Skill Level Intermediate
- [Instructor] If you have a DynamoDB table, and you want to run some Lambda functionality whenever something is inserted, updated or deleted in the table, we can do that with triggers. So under the More tab, I'll select Triggers, Create Trigger, New Function. This will allow us to define the function and most of the values have been defined for us. So I'll give it a name, basic Lambda permissions, and leave all the trigger settings as they are an the same with the default code and now I'll click Create Function. If you get an error like this, it's okay, we just need to add some permissions to our IAM role, so let's go to IAM. Here we're going to select Roles, and then the role that was created for us and Attach policies. We're going to want to attach a DynamoDB policy specifically the LambdaDynamoDBExecution policy. Now we can go back and recreate our trigger. We should refresh just to make sure it picks everything up and now under Create Trigger, we can select Existing Lambda Function and attach our test function. We'll create that here. Now when we change anything in the database, we should be able to check the logs for the changes. So I'm going to change this value in the latitude and longitude and I'm going to include something like 999 on the end. And I'll save that and now we can go check the logs. So from the Services, I'll select CloudWatch, and here I'll select Logs in the log group for our test function and then the file and we can see the changes that were made. If I expand this, we can scroll down and we can see the new value. Congratulations!