This AWS Lambda function will attach to the DynamoDB Stream of the logfile
table to replicate item puts and deletes to the logfile_replica
table. The Lambda function code has been provided for you in the file ddbreplica_lambda.py
. You may review the contents of the script if you would like with vim
or less
.
Zip the contents of the script. We will upload this to AWS Lambda when we create the function.
zip ddbreplica_lambda.zip ddbreplica_lambda.py lab_config.py
Get the Amazon Resource Name (ARN) of the precreated IAM role so that you can associate it with the Lambda function. Run the following command to retrieve the ARN of the role that was created during the lab creation.
cat ~/workshop/ddb-replication-role-arn.txt
The output looks like the following.
arn:aws:iam::<ACCOUNTID>:role/XXXXX-DDBReplicationRole-XXXXXXXXXXX
Now, run the following command to create the Lambda function.
aws lambda create-function \
--function-name ddbreplica_lambda --zip-file fileb://ddbreplica_lambda.zip \
--handler ddbreplica_lambda.lambda_handler --timeout 60 --runtime python3.7 \
--description "Sample lambda function for dynamodb streams" \
--role $(cat ~/workshop/ddb-replication-role-arn.txt)