Step 2: Create a Lambda Function
In this step, you will create a very simple AWS Lambda function to read stream records and echo their contents to Amazon CloudWatch Logs. You will associate this Lambda function with the stream on the DynamoDB table that you created in Step 1, so that changes to data in that table will trigger the Lambda function.
Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/.
In the navigation pane, choose Tables.
In the list of tables, choose
Choose the Triggers tab.
Choose Create trigger, and then choose New function. The AWS Lambda console appears.
In the Configure event sources section of the Lambda console, in the DynamoDB table field, choose
In the Configure function section of the Lambda console, do the following:
In the Name field, type
StreamsLambdaFunction. (This is the name of the function that we will use for this walkthrough.)
Leave the Runtime field at its default setting:
Do not modify any fields in the Lambda function code section. You will use the pre-provided Node.js code.
In the Lambda function handler and role section, do the following:
Leave the Handler field at its default setting:
In the Role field, select
DynamoDB event stream role. A new window appears, asking for confirmation that you want to create a new IAM role,
lambda_dynamo_streams, that will be used when invoking your Lambda function. Choose Allow to create the role and dismiss the window.
Back in the Lambda console, leave all of the other settings on the page at their default values, and choose Next.
On the Review page, go to Enable event source and choose Enable now.
Leave all of the other settings on this page their default values, and then choose Create function.