getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
912 stars 109 forks source link

fix: adds `dynamodb:ConditionCheckItem` permission to dynamodb construct #340

Closed cmcnicholas closed 1 year ago

cmcnicholas commented 1 year ago

Closes #339

Without this IAM permission, transacted writes in dynamodb using the ConditionCheck feature are disallowed.

See:

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ConditionCheck.html

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis-iam.html

Example usage:

After this change you would be able to make use of ConditionCheck in transacted writes e.g.

client.send(
  new TransactWriteCommand({
    TransactItems: [
      // checks an item condition is successful
      {
        ConditionCheck: {
          TableName: environment.tableName,
          Key: {
            PK: 'somepk',
            SK: 'somesk',
          },
          ConditionExpression: 'attribute_exists(PK)',
        },
      },
      // and writes a record in 1 transaction ensuring consistency
      {
        Put: {
          TableName: environment.tableName,
          Item: someItem,
        },
      }
    ]
  }));
mnapoli commented 1 year ago

Thanks!