Skip to content

Repository files navigation

Image Conversion Service on AWS using Terraform

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.

Features

  • 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.

Architecture

Architecture

Prerequisites

Before setting up this project, ensure you have the following prerequisites:

  1. AWS Account: You will need an AWS account to provision the necessary services.
  2. Terraform: Install Terraform on your local machine. You can download it from the Terraform website.
  3. 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.
  4. AWS IAM User with Programmatic Access: Create an IAM user with programmatic access and the necessary permissions to provision resources using Terraform.
  5. Basic Knowledge of AWS Services: Familiarity with AWS services such as S3, Lambda, IAM, and Cognito will be helpful.

Configurations of AWS Services

Amazon S3

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.

AWS Lambda

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.

IAM (Identity and Access Management)

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.

Amazon Cognito

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.

Amazon CloudWatch

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.

Infrastructure Provisioning with Terraform

This project uses Terraform to provision all the necessary AWS services.

Why Terraform?

I chose Terraform for the following reasons:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Terraform Configuration Files

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:

Directory 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 the Modules/ 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 in variables.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, and IAM Role. Each module folder contains its own main.tf, variables.tf, and outputs.tf files defining the module's resources, input variables, and outputs.

Modifying Terraform Files

When modifying the Terraform configuration files, follow these best practices:

  1. Use Variables: Whenever possible, use variables to parameterize your configurations. This allows for easy customization and reuse of Terraform code.
  2. Document Changes: Clearly document any changes made to the Terraform files, including the rationale behind the modifications and their impact on the infrastructure.
  3. 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.

Contributors

About

A serverless web application for converting images between various formats using AWS Lambda and Amazon S3. The project leverages Terraform for automated provisioning of AWS resources, ensuring scalability and consistency.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages