A simple AWS Lambda function that exports DynamoDB table data to CSV and provides a download link via SNS.
Generated with AWS Q Developer.
- SQS Trigger: Function is triggered by messages in an SQS queue
- DynamoDB Scan: Scans the entire TodoItems-Dev table (configurable)
- CSV Generation: Creates CSV with all item attributes and headers
- S3 Upload: Stores the CSV file in an S3 bucket
- Pre-signed URL: Generates a 5-minute download link
- SNS Notification: Sends the download link via SNS topic
# Build and deploy
sam build
sam deploy --guided
# You'll be prompted for:
# - DynamoDBTableName (default: TodoItems-Dev)
# - S3BucketName (your existing bucket)
# - SQSQueueArn (your existing queue ARN)
# - SNSTopicArn (your existing topic ARN)
DYNAMODB_TABLE_NAME
: DynamoDB table name to scanS3_BUCKET_NAME
: S3 bucket for CSV storageSNS_TOPIC_ARN
: SNS topic ARN for notifications
If you are deploying manually, you'll need to grant the relevant permissions to the Lambda's Execution role.
- S3 Full
- SNS Full
- DynamoDB Read Only
- SQS Full
ALSO - Bump up the function timeout to 30 seconds from 3 seconds - 3 seconds is NOT long enough
Send a message to your SQS queue to trigger the function. The message content doesn't matter - any message will trigger the export process.
The function creates a timestamped CSV file (e.g., todo_export_20231201_143022.csv
) and sends a download link via SNS that expires in 5 minutes.