This project demonstrates how to set up and use various AWS services locally using LocalStack. It includes a Flask web application for file uploads, along with infrastructure setup scripts for S3, DynamoDB, SNS, and Lambda.
localstack-example/
├── app/
│ ├── __init__.py
│ ├── app.py
│ ├── config.py
│ └── templates/
│ └── index.html
├── ec2-flask/
│ ├── run.sh
│ └── user_script.sh
├── infrastructure/
│ ├── setup_dynamodb.py
│ ├── setup_lambda.py
│ ├── setup_s3.py
│ └── setup_sns.py
├── lambda/
│ ├── lambda_function.py
│ ├── lambda_handler.py
│ └── requirements.txt
└── commands
-
Start LocalStack:
docker run --rm -it -p 127.0.0.1:4566:4566 -p 127.0.0.1:4510-4559:4510-4559 -v /var/run/docker.sock:/var/run/docker.sock localstack/localstack -
Set up AWS services:
python infrastructure/setup_s3.py python infrastructure/setup_sns.py python infrastructure/setup_dynamodb.py python infrastructure/setup_lambda.py -
Run the Flask application:
python app/app.py
- Handles file uploads
- Interacts with S3, DynamoDB, and Lambda
- Provides a simple web interface for file uploads
setup_s3.py: Creates an S3 bucketsetup_sns.py: Sets up an SNS topicsetup_dynamodb.py: Creates a DynamoDB tablesetup_lambda.py: Deploys a Lambda function
- Processes uploaded files
- Updates DynamoDB with file status
- Sends SNS notifications
- Scripts for setting up a Flask application on EC2 (for demonstration purposes)
- Access the web interface at
http://localhost:80 - Upload a file using the provided form
- The file will be processed by the Lambda function
- Check the file status using the
/status/<username>/<filename>endpoint
Adjust the configuration in app/config.py to match your LocalStack setup:
- S3_BUCKET
- DYNAMO_TABLE
- SNS_TOPIC_ARN
- LAMBDA_FUNCTION_NAME
- This project is designed for local development and testing with LocalStack
- Ensure all necessary Python dependencies are installed
- Modify IAM roles and permissions as needed for your specific use case (example in commands file for lambda)