instance-details
lets you easily create infrastructure on AWS and deploy an application that displays the information of all running EC2 instances.
- Creating an application to return a list of all running EC2 instances in a region in an AWS account along with their corresponding IPs and Tags when called on the /ec2 path
- Building and pushing container image of the application to the registry
- IaC(Infrastructure as Code) to automate the deployment of infrastructure on AWS
Technology | Description | ||
---|---|---|---|
✦ | Python | programming language | |
pip | package-management system | ||
flask | micro web framework | ||
gunicorn | web server gateway interface HTTP server | ||
boto3 | python SDK for AWS | ||
✦ | Docker | containerization platform | |
✦ | AWS | public cloud platform | |
instance | virtual server | ||
launch template | launch parameters for instance | ||
ASG | Auto Scaling group: logical grouping of instances | ||
target group | request routing to registered targets | ||
ALB | Application Load Balancer: configuring and routing incoming end-user traffic to apps | ||
route 53 | Domain Name System service | ||
security Group | virtual firewall | ||
✦ | Terraform | infrastructure as code software tool |
- Install AWS CLI
- Create AWS credentials
- Configure the above AWS credentials locally by inserting respective values
aws configure
Application creation and containerization steps can be found
here
.
Resources are segregated as per the services and their components. More details in respective directories.
- Modularized structure
- Terraform backend state maintained in S3 bucket with versioning enabled
- Isolation between the terraform tfstate files for the AWS resources for reducing the impact
- Terraform tfvars used for passing variable values
- Consistent structure and naming convention
- Best for teams to store the Terraform state file remotely
- Teams have access to the latest copy of infrastructure always
- Supports state locking and consistency checking
- Three things are required:
- Terraform S3 backend resource
- S3 bucket to store the state file
- DynamoDB table for state locking and consistency checking
terraform { backend "s3" { bucket = "example-s3" key = "path/to/my/key" // e.g "prod/route_53.tfstate" region = "us-east-1" encrypt = "true" dynamodb_table = "example-table" } }
├── README.md // Description of the module and its purpose
├── backend.tf // To create terraform backend state configuration
├── data.tf // It contains the declarations for data sources
├── main.tf // The primary entrypoint for terraform resources
├── outputs.tf // It contains the declarations for outputs
├── terraform.tfvars // The file to pass the terraform variables values
├── variables.tf // It contains the declarations for variables
├── versions.tf // To specify terraform versions and providers
-
Head over to the path of the resource to be deployed
-
Run
terraform init
terraform plan
terraform apply
Command Description terraform init initializes a working directory containing Terraform configuration files terraform plan creates an execution plan, which lets us preview the changes that Terraform plans to make to our infrastructure terraform apply executes the actions proposed in the Terraform plan Note: Above commands should be run from the resource directories. The modules directory consists of root modules and will not change anything unless it is necessary.
├── dynamodb_table
│ ├── main.tf
│ ├── outputs.tf
│ ├── README.md
│ ├── terraform.tfvars
│ ├── variables.tf
│ └── versions.tf
├── ec2
│ ├── backend.tf
│ ├── main.tf
│ ├── outputs.tf
│ ├── README.md
│ ├── terraform.tfvars
│ ├── variables.tf
│ └── versions.tf
├── modules
│ ├── dynamodb_table
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── ec2
│ │ ├── data.tf
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── user_data.sh
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── route_53
│ │ ├── data.tf
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── s3
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ └── vpc
│ ├── data.tf
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
├── README.md
├── route_53
│ ├── backend.tf
│ ├── main.tf
│ ├── outputs.tf
│ ├── README.md
│ ├── terraform.tfvars
│ ├── variables.tf
│ └── versions.tf
├── s3
│ ├── main.tf
│ ├── outputs.tf
│ ├── README.md
│ ├── terraform.tfvars
│ ├── variables.tf
│ └── versions.tf
└── vpc
├── backend.tf
├── main.tf
├── outputs.tf
├── README.md
├── terraform.tfvars
├── variables.tf
└── versions.tf