This Rust project defines an AWS Lambda function designed to log commands received through events into an Amazon DynamoDB table and, optionally, fetch and display the contents of this table. The Lambda function is built using lambda_runtime for the Rust runtime and rusoto_dynamodb for interacting with DynamoDB.
- Log Commands: Logs each command received through a Lambda event to a DynamoDB table and AWS cloudwatch. AWS X-Ray is also enabled.
- Print Database Contents: On receiving a specific command (
print_db), the Lambda function scans the specified DynamoDB table and returns its contents as part of the response message.
- Rust and Cargo
- AWS CLI configured with appropriate access rights
- An existing Amazon DynamoDB table
Ensure you have a DynamoDB table created with the name my-table and a primary key named request_id.
Build your Lambda function package by compiling the Rust project:
cargo build --release --target x86_64-unknown-linux-muslThen, create a deployment package by zipping the compiled binary:
zip -j rust_lambda.zip ./target/x86_64-unknown-linux-musl/release/bootstrapCreate an AWS Lambda function specifying the runtime as provided and upload the rust_lambda.zip as the function code. Ensure the Lambda function's execution role has permissions to access DynamoDB (at least dynamodb:PutItem and dynamodb:Scan on your table).
Invoke the Lambda function by sending an event with a command field. The command can be any string, but if print_db is sent, the function will scan the DynamoDB table and return its contents.
{
"command": "example_command"
}To print the contents of the DynamoDB table, use:
{
"command": "print_db"
}Ensure you have Rust and Cargo installed. Clone the repository and navigate into the project directory. Then use cargo lambda to deploy and invoke.