Configure your lambda function to copy changed records from the Orders DynamoDB streams to the OrdersHistory table by doing the following.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Scan",
"dynamodb:UpdateItem"
],
"Resource": "arn:aws:dynamodb:{aws-region}:{aws-account-id}:table/*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:DescribeStream",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:ListStreams"
],
"Resource": "arn:aws:dynamodb:{aws-region}:{aws-account-id}:table/Orders/stream/*"
},
{
"Effect": "Allow",
"Action": "dynamodb:PutItem",
"Resource": "arn:aws:dynamodb:{aws-region}:{aws-account-id}:table/OrdersHistory"
},
{
"Effect": "Allow",
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:{aws-region}:{aws-account-id}:orders-ddbs-dlq"
}
]
}
The updated IAM policy gives the create-order-history-ddbs lambda function the permissions required to read events from the Orders DynamoDB stream, write new items to the OrdersHistory DynamoDB table and send messages to the orders-ddbs-dlq SQS queue.
Replace {aws-region} and {aws-account-id} in the policy statement above with the correct value for your AWS region and your AWS account ID.
1
arn:aws:lambda:{aws-region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:58
Replace {aws-region} with ID for the AWS region that you are currently working on.
arn:aws:sqs:{aws-region}:{aws-account-id}:orders-ddbs-dlq