This project is designed to generate thumbnails and upload the data information into DynamoDB from images uploaded to an AWS S3 bucket using AWS Lambda and Terraform.
Before getting started, make sure you have the following:
- Docker installed
- Visual Studio Code installed
- Recommended VS Code extensions installed (check the "Extensions: show recommended extensions" command)
To deploy the infrastructure using Terraform, follow these steps:
-
Generate HCP Terraform account token: You can do this by navigating to Settings > Tokens.
-
Create an HCP Terraform Organization and update the
TF_CLOUD_ORGANIZATION
variable in.devcontainer/.env
with your HCP Terraform Organization name. -
Start the devcontainer: Open the devcontainer via VSCode, GitHub Codespaces, or other supported environments and select the Terraform container.
-
(Optional) Update the Lambda function: Modify the
src/lambda.py
file, then run the following scripts:./scripts/aws/lambda/00-install-package.sh ./scripts/aws/lambda/01-compress-package.sh
-
Deploy the infrastructure: Run the script to deploy:
./scripts/terraform/00-terraform.sh
-
(Optional) Testing Lambda locally
After finishing, you can clean up AWS resources via the Terraform CLI or HCP Terraform Workspace page.
terraform plan -destroy -out=destroy.tfplan
terraform apply destroy.tfplan
The project follows a specific folder structure to organize the code and resources. Here is an overview of the folder structure: Read here
Feel free to explore each folder to understand the purpose and contents of each.
The following diagram illustrates the high-level workflow of the project.
To test Lambda functions locally, we utilize AWS SAM (Serverless Application Model). Detailed steps for setting up and running tests can be found in the documentation: SAM
For common issues that you may encounter while working with this project, refer to this document troubleshooting.md.
Information about contributing to this project can be found in the CONTRIBUTING.md file.
In this project, you learned:
- How to use Terraform (IaC) and manage it in the cloud with HCP Terraform.
- Explored various AWS services to implement a workflow where uploaded images in S3 trigger a Lambda function to generate thumbnails and update metadata in DynamoDB.
- Set up a development environment using devcontainers for fast and easy project setup.
- Utilized AWS SAM for seamless local testing of Lambda functions.
- Managed repository and CI/CD pipelines using GitHub.
- Created architectural diagrams using diagram-as-code tools.
- Provided detailed documentation of Terraform modules in
docs/terraform.md
. - Ensured code quality through pre-commit hooks with tools like Ruff, Gitlint, Gitleaks, Trivy, and more.
For more details, please refer to the Changelog.
This project is released under the Mozilla Public License by @Nguyen Tri Man (@cloud-bees)
© 2024 Nguyen Tri Man. All rights reserved.