Capturing the write (Put, Delete, Update) operation of a DynamoDB stream that will be processed by a Lambda function. The Lambda Function reads the records from the stream and invokes the function synchronously with an event that contains stream records.
{
"log_code": "DynamoDBStreamRecord",
"log_msg": "Events from the DynamoDB Table",
"log_level": "INFO",
"log_keys": {
"record": {
"awsRegion": "us-east-1",
"dynamodb": {
"ApproximateCreationDateTime": 1689103530,
"Keys": {
"referenceId": {
"S": "sample-reference-id-12345"
}
},
"NewImage": {
"change": {
"N": "249.5"
},
"customer_id": {
"S": "customer-12345"
},
"quantity": {
"N": "25"
},
"referenceId": {
"S": "sample-reference-id-12345"
},
"total": {
"N": "1250.5"
}
},
"SequenceNumber": "100000000006899888825",
"SizeBytes": 126,
"StreamViewType": "NEW_IMAGE"
},
"eventID": "12ab34c567de89f10fedc11b1a07e92b",
"eventName": "INSERT",
"eventSource": "aws:dynamodb",
"eventVersion": "1.1",
"eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789101:table/orders/stream/2023-05-19T02:24:40.803"
}
},
"log_timestamp": "2023-05-19 02:30:49"
}
{
"log_code": "DynamoDBStreamRecord",
"log_msg": "Events from the DynamoDB Table",
"log_level": "INFO",
"log_keys": {
"record": {
"awsRegion": "us-east-1",
"dynamodb": {
"ApproximateCreationDateTime": 1689103530,
"Keys": {
"referenceId": {
"S": "sample-reference-id-12345"
}
},
"NewImage": {
"cash": {
"N": "1500"
},
"change": {
"N": "249.5"
},
"customer_id": {
"S": "customer-12345"
},
"quantity": {
"N": "25"
},
"referenceId": {
"S": "sample-reference-id-12345"
},
"total": {
"N": "1250.5"
}
},
"SequenceNumber": "200000000006399151338",
"SizeBytes": 132,
"StreamViewType": "NEW_IMAGE"
},
"eventID": "12ab34c567de89f10fedc11b1a07e92b",
"eventName": "MODIFY",
"eventSource": "aws:dynamodb",
"eventVersion": "1.1",
"eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789101:table/orders/stream/2023-05-19T02:24:40.803"
}
},
"log_timestamp": "2023-05-19 02:31:40"
}
{
"log_code": "DynamoDBStreamRecord",
"log_msg": "Events from the DynamoDB Table",
"log_level": "INFO",
"log_keys": {
"record": {
"awsRegion": "us-east-1",
"dynamodb": {
"ApproximateCreationDateTime": 1689103530,
"Keys": {
"referenceId": {
"S": "sample-reference-id-12345"
}
},
"SequenceNumber": "300000000006899888825",
"SizeBytes": 36,
"StreamViewType": "NEW_IMAGE"
},
"eventID": "12ab34c567de89f10fedc11b1a07e92b",
"eventName": "REMOVE",
"eventSource": "aws:dynamodb",
"eventVersion": "1.1",
"eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789101:table/orders/stream/2023-05-19T02:24:40.803"
}
},
"log_timestamp": "2023-05-19 02:32:10"
}
- Core components of Amazon DynamoDB
- Using AWS Lambda with Amazon DynamoDB
- Change data capture for DynamoDB Streams
- Best practices for designing and using partition keys effectively
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
-
Install all the dependencies, bootstrap your project, and synthesized CloudFormation template.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/dynamodb/dynamodb-stream-lambda$ make init # With "profile" parameter dev@dev:~:aws-cdk-samples/dynamodb/dynamodb-stream-lambda$ make init profile=[profile_name]
-
Deploy the project.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/dynamodb/dynamodb-stream-lambda$ make deploy # With "profile" parameter dev@dev:~:aws-cdk-samples/dynamodb/dynamodb-stream-lambda$ make deploy profile=[profile_name]