This project is a simple web application that allows users to convert images between different formats. It utilizes AWS Lambda for serverless image conversion and Amazon S3 for storing input and output images. The application provides a user-friendly web interface for uploading images and downloading converted images.
- Convert images between various formats, including JPG, PNG, BMP, and TIFF.
- User-friendly web interface for uploading images and downloading converted images.
- Seamless integration with AWS Lambda and Amazon S3 for serverless image conversion.
Before setting up this project, ensure you have the following prerequisites:
- AWS Account: You will need an AWS account to provision the necessary services.
- Terraform: Install Terraform on your local machine. You can download it from the Terraform website.
- AWS CLI: Install and configure the AWS Command Line Interface (CLI) to manage your AWS resources. You can download it from the AWS CLI website.
- AWS IAM User with Programmatic Access: Create an IAM user with programmatic access and the necessary permissions to provision resources using Terraform.
- Basic Knowledge of AWS Services: Familiarity with AWS services such as S3, Lambda, IAM, and Cognito will be helpful.
Input and Output Buckets:
- Create two S3 buckets: one for storing input images and another for storing converted images.
- Configure permissions to allow uploads to the input bucket and downloads from the output bucket.
- Set up event notifications to trigger the Lambda function for image conversion upon file upload.
Serverless Image Conversion Function:
- Implement a Lambda function for converting images between different formats.
- Configure the function to trigger automatically in response to S3 upload events.
- Set up IAM execution roles with necessary permissions for accessing S3 buckets and CloudWatch logs.
Permissions and Roles:
- Define IAM roles with granular permissions for Lambda execution, S3 access, and CloudWatch logging.
- Ensure least privilege by granting only the necessary permissions required for each service.
User Authentication and Authorization:
- Configure a Cognito User Pool to manage user identities and authentication.
- Integrate Cognito with the web application for user access control.
Logging and Monitoring:
- Set up CloudWatch logs to capture logs generated by the Lambda function during image conversion.
- Configure custom metrics and alarms to monitor Lambda function performance and resource utilization.
This project uses Terraform to provision all the necessary AWS services.
I chose Terraform for the following reasons:
- Infrastructure as Code (IaC): Terraform allows us to define our infrastructure using code. This approach provides several benefits including version control, collaboration, and documentation of infrastructure changes.
- Consistency and Reproducibility: By using Terraform scripts, we ensure that the infrastructure can be consistently reproduced in different environments. This eliminates the risk of manual configuration errors.
- Scalability: Terraform supports modular configurations, making it easy to scale the infrastructure as the project grows. It allows us to reuse configurations and manage resources efficiently.
- Provider Support: Terraform has extensive support for a wide range of cloud providers, including AWS. This makes it easier to manage and integrate various AWS services required for our project.
- Automation: Terraform automates the provisioning and management of infrastructure, reducing the time and effort required for manual setup. This automation is crucial for maintaining an agile and responsive development process.
The Terraform configuration for this project is organized into several files and folders, each serving a specific purpose. Below is an overview of the Terraform files and their structure:
terraform/
├── main.tf
├── providers.tf
├── variables.tf
├── terraform.tfvars
├── Lambda Files/
├── app/
└── Modules/
├── S3/
│ ├── S3.tf
│ ├── variables.tf
│ └── outputs.tf
├── Lambda/
│ ├── main.tf
│ └── variables.tf
└── IAM Role/
├── main.tf
├── variables.tf
└── outputs.tf-
main.tf: This file contains the main Terraform configuration, including the definition of AWS resources such as S3 buckets, Lambda functions, IAM roles, and other infrastructure components. It may also include references to modules defined in theModules/directory. -
providers.tf: This file specifies the provider configurations, including the AWS provider details such as access keys, secret keys, and region. It ensures that Terraform knows which cloud provider to interact with and how to authenticate. -
variables.tf: This file defines input variables used in the Terraform configuration. It allows customization of parameters such as bucket names, Lambda function settings, IAM role policies, and other configurable options. -
terraform.tfvars: This file contains values for the input variables defined invariables.tf. It serves as a convenient way to specify values without modifying the Terraform configuration files directly. It is typically used to set sensitive information like AWS access keys and secret keys. -
Lambda Files/: This directory contains the code files for the AWS Lambda functions used in the project. -
app/: This directory contains the files for the web application, including HTML, CSS, JavaScript, and other static assets. These files define the user interface and functionality of the application. -
Modules/: This directory contains reusable Terraform modules, each responsible for provisioning a specific set of resources. In this project, there are three modules folders:S3,Lambda, andIAM Role. Each module folder contains its ownmain.tf,variables.tf, andoutputs.tffiles defining the module's resources, input variables, and outputs.
When modifying the Terraform configuration files, follow these best practices:
- Use Variables: Whenever possible, use variables to parameterize your configurations. This allows for easy customization and reuse of Terraform code.
- Document Changes: Clearly document any changes made to the Terraform files, including the rationale behind the modifications and their impact on the infrastructure.
- Test Changes: Before applying changes to your production environment, test them in a separate environment to ensure they behave as expected and do not cause any unintended side effects.
