Simple ETL
This guide shows you how to build a file processing pipeline using AWS S3, Lambda, and DynamoDB locally with LocalStack. This lab demonstrates how S3 uploads trigger a Lambda to log metadata into a DynamoDB table.
Prerequisites
Section titled “Prerequisites”- Docker installed and running.
- Dev Containers extension installed (optional).
- AWS Toolkit for VS Code (optional, included in Dev Container).
How to execute
Section titled “How to execute”-
Setup Environment:
Open VS Code in the project folder and execute this command in the Command Palette:
Terminal window > Dev Containers: Reopen in Container- Start LocalStack:
Terminal window docker compose up -d localstack - Configure AWS CLI:
Terminal window aws configure set aws_access_key_id test --profile localstackaws configure set aws_secret_access_key test --profile localstackaws configure set region us-east-1 --profile localstackaws configure set output json --profile localstackaws configure set endpoint_url http://localhost:4566 --profile localstackaws configure set cli_pager "" --profile localstack - Install Python dependencies:
Terminal window pip install uvuv sync - Package the Lambda function:
Terminal window python deploy/utils/package_lambda.py - Deploy:
Terminal window python deploy/boto3_deploy.py
- Start LocalStack:
-
Run the Example:
Terminal window python main.pyTerminal window curl -X PUT -T src/lambda.py http://localhost:4566/file-uploads-bucket/manual-upload.py- Select the
localstackprofile in the AWS Toolkit. - Right-click on the
file-uploads-bucketand select Upload Files….
- Select the
Deployment methods
Section titled “Deployment methods”There are other deployment methods that you can use in this Lab.
terraform -chdir=deploy initterraform -chdir=deploy apply -auto-approve- Create a temporary bucket for deployment:
Terminal window aws s3 mb s3://lambda-deploy-bucket --profile localstack - Upload the Lambda package:
Terminal window aws s3 cp tmp/lambda.zip s3://lambda-deploy-bucket/lambda.zip --profile localstack - Deploy the stack:
Terminal window aws cloudformation deploy --profile localstack \--stack-name aws-dynamo-db-stack \--template-file deploy/cloud_formation_deploy.yaml \--capabilities CAPABILITY_NAMED_IAM
python deploy/boto3_deploy.py- Create DynamoDB Table:
Terminal window aws dynamodb create-table --profile localstack \--table-name file-logs \--attribute-definitions AttributeName=file_id,AttributeType=S \--key-schema AttributeName=file_id,KeyType=HASH \--billing-mode PAY_PER_REQUEST - Create IAM Role:
Terminal window aws iam create-role --profile localstack \--role-name lambda-s3-processor-role \--assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}' - Create Lambda Function:
Terminal window aws lambda create-function --profile localstack \--function-name s3-file-processor \--runtime python3.12 \--role arn:aws:iam::000000000000:role/lambda-s3-processor-role \--handler lambda.lambda_handler \--zip-file fileb://tmp/lambda.zip \--environment Variables={DYNAMODB_TABLE=file-logs} - Create S3 Bucket:
Terminal window aws s3 mb s3://file-uploads-bucket --profile localstack - Add S3 Permission and Configure Notification:
Terminal window aws lambda add-permission --profile localstack \--function-name s3-file-processor \--statement-id s3-trigger \--action lambda:InvokeFunction \--principal s3.amazonaws.com \--source-arn arn:aws:s3:::file-uploads-bucketaws s3api put-bucket-notification-configuration --profile localstack \--bucket file-uploads-bucket \--notification-configuration '{"LambdaFunctionConfigurations":[{"LambdaFunctionArn":"arn:aws:lambda:us-east-1:000000000000:function:s3-file-processor","Events":["s3:ObjectCreated:*"]}]}'
Validate results
Section titled “Validate results”- Check S3 Bucket:
Terminal window aws s3 ls s3://file-uploads-bucket --profile localstack - Scan DynamoDB Table:
Terminal window aws dynamodb scan --table-name file-logs --profile localstack - View Lambda Logs:
Terminal window aws logs tail /aws/lambda/s3-file-processor --profile localstack
- S3: Expand the S3 section to see the uploaded files.
- CloudWatch: Expand the Logs section to see the Lambda execution output.
- Download: NoSQL Workbench for DynamoDB.
- Setup Connection: Click Operation builder > Add connection > DynamoDB local. Set Connection Name to
LocalStack, Hostname tolocalhost, Port to4566. - Connect to browse and edit the
file-logstable.
Clean Up
Section titled “Clean Up”docker compose down -vTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| Connection Refused | Ensure LocalStack is running and wait for the Ready. message in logs. |
| Lambda Not Triggering | Verify logs: aws logs tail /aws/lambda/s3-file-processor --profile localstack |