5

I use serverless framework to deploy cloudFormation. I want to trigger lambda to deleteObject on my S3 bucket after I update my DynamoDB Table with certain attribute, eg. my table has account, user, icon, I only want when I update icon, it trigger Lambda to delete my iconObject on S3 bucket.

As I read the documentation on AWS, it seems the eventName of dynamoDB stream Event only have three status, REMOVE, MODIFY, INSERT.

AWS Documentation » Amazon DynamoDB » API Reference » Data Types » Amazon DynamoDB Streams » Record Record

Could I do as below? But how do I know it update icon instead other attribute like account or user?

if (this._record.eventName === 'MODIFY' && this._record.NewImage!== this._record.OldImage ){
        return this._remove(this._record.dynamodb);
    }
1

1 Answer 1

11

You are on the right track. If the DynamoDB StreamViewType is set to NEW_AND_OLD_IMAGES then when record.eventName === 'MODIFY', record.dynamodb.NewImage will contain the updated version of the item and record.dynamodb.OldImage will contain what the item was before the update. You could then inspect the 2 objects and look for changes in the fields you are interested in.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah!!!!!! Thanks @bwinant! Had a hard time figuring out what's NewImage and OldImage.
Hi, can you have a look here please? stackoverflow.com/questions/70020731/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.