Storage Writer
This guide shows you how to build an AWS Lambda function that uploads files to S3 locally using LocalStack. This lab demonstrates multiple deployment methods — Terraform, CloudFormation, and Boto3.
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 - Setup environment (installs mise, Python, AWS CLI, Terraform, and syncs dependencies):
Terminal window scripts/setup-mve.sh - Install AWS Toolkit: Install the AWS Toolkit extension and connect using the
localstackprofile configured by the setup script. - Deploy Resources:
Terminal window scripts/boto3/deploy.sh
- Start LocalStack:
-
Run the Example:
Terminal window python main.py- Select the
localstackprofile in the AWS Toolkit. - Right-click on the
upload-to-s3function and select Invoke Lambda….
- Select the
Deployment methods
Section titled “Deployment methods”There are other deployment methods you can use in this lab.
scripts/terraform/deploy.shscripts/cloudformation/deploy.shscripts/boto3/deploy.shValidate results
Section titled “Validate results”- Check S3 Bucket:
Terminal window aws s3 ls s3://test-bucket/ --profile localstack - View Lambda Logs:
Terminal window aws logs tail /aws/lambda/upload-to-s3 --profile localstack
- S3: Expand the S3 section to see the uploaded files.
- CloudWatch: Expand the Logs section to see the Lambda execution output.
Clean Up
Section titled “Clean Up”To remove only the deployed resources, run the destroy script for the method you used:
scripts/terraform/destroy.shscripts/cloudformation/destroy.shscripts/boto3/destroy.shTo remove all containers and volumes as well:
docker compose down -vTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| Lambda Timeout | Ensure LocalStack has enough memory and CPU resources. |
| Connection Refused | Ensure LocalStack is running and wait for the Ready. message in logs. |