Skip to content

This repository contains Terraform code and instructions for deploying a sample Python application on an AWS EC2 instance.

Notifications You must be signed in to change notification settings

vinod-kha/terraform-ec2-python-deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Application Deployment on AWS EC2 using Terraform

This repository contains Terraform code and instructions for deploying a sample Python application on an AWS EC2 instance.

Table of Contents

Overview

The Terraform code in this repository automates the creation of an AWS EC2 instance and deploys a sample Python application on it. This README provides guidance on setting up and deploying the application.

Prerequisites

Before you begin, ensure you have the following prerequisites installed and configured:

  • Terraform CLI
  • AWS CLI with appropriate access credentials
  • AWS account

Project Structure

The project structure is as follows:

terraform-ec2-python/
├── main.tf
├── variables.tf
├── terraform.tfvars
├── provisioners.md
├── app.py
└── README.md

  • main.tf: Terraform configuration for creating EC2 instance, security group, VPC, subnet, route table, Internet Gatway and key-pair.
  • variables.tf: Input variables used in Terraform configuration.
  • terraform.tfvars: Specifies values for input variables.
  • app/: Sample Python application directory.
  • README.md: Instructions and documentation (you're reading it now).
  • provisioners.md: Types of provisioners

Terraform Configuration

Modify the variables.tf and terraform.tfvars files to customize your EC2 instance configuration. Key variables include:

  • region: AWS region where the EC2 instance will be created.
  • instance_type: Type of EC2 instance to launch (e.g., t2.micro).
  • key_name: Name of the SSH key pair used to access the instance.
  • ami: ID of the Amazon Machine Image (AMI) to use for the EC2 instance.
  • security_group_name: Name of the security group allowing inbound traffic on port 80 (HTTP).

Application Deployment

  1. Clone this repository to your local machine:

    git clone https://github.com/your/repository.git
  2. Navigate to the cloned repository:

    cd terraform-provisioners/
  3. Initialize Terraform:

    terraform init
  4. Review and modify the Terraform configuration files (main.tf, variables.tf, terraform.tfvars) as needed.

  5. Apply the Terraform configuration to create the EC2 instance:

    terraform apply
  6. Once the EC2 instance is created, the sample Python application will be automatically deployed on the instance.

Accessing the Application

To access the deployed Python application:

  1. Note the public IP address or DNS name of the EC2 instance from the Terraform output.

  2. Open a web browser and enter the following URL:

    http://<EC2_Public_IP_or_DNS>
    

    Replace <EC2_Public_IP_or_DNS> with the actual public IP address or DNS name of your EC2 instance.

  3. You should see the sample Python application running and displaying a welcome message.

Cleaning Up

To clean up and destroy the resources created by Terraform:

  1. Navigate to the project directory.

  2. Run the following command to destroy the resources:

    terraform destroy

    Confirm the action when prompted.

About

This repository contains Terraform code and instructions for deploying a sample Python application on an AWS EC2 instance.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published