Git Product home page Git Product logo

colinbut / microservice-aws-ec2-setup Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 23 KB

Infrastructure provisioning of AWS EC2 instances using Terraform, Cloudformation, AWS Console, aws cli

Python 40.67% Shell 16.04% HCL 43.29%
hcl python python-3 python3 shell shell-script shell-scripts shell-scripting aws ec2 ec2-instance terraform cloudformation aws-cloudformation aws-cli awscli devops

microservice-aws-ec2-setup's Introduction

Microservice AWS EC2 Setup

This project provides the steps/methods required for setup an EC2 instance for running the microservice as defined in the microservice-aws-demo project.

The microservice can be a containerized or a non-containerized microservice. See microservice-java & microservice-nodejs projects for more details on this.

There are many ways to setup EC2 instances in AWS:

  1. via AWS mamagement console creating from scratch
  2. using Infrastructure as Code tool (Terraform/Cloudformation)
  3. AWS CLI
  4. utilizing a pre-build custom made AMI for any of above methods

Assumptions

  1. Assumes a AWS account created and AWS credentials configured (access_keys & secret_keys etc)

  2. This project will create EC2 instances in the default VPC.

  3. To put in a custom non-default VPC require to create the custom non-default VPC. See my Terraform project - aws-public-private-vpc for more reference on to create this.

Option 1 - AWS Management Console

Follow the official AWW guide from AWS documentation - https://docs.aws.amazon.com/efs/latest/ug/gs-step-one-create-ec2-resources.html

Option 2 - Terraform/Cloudformation

It is good to manage infrastructure changes and define them in 'code'. This option details how to do this via modern infrastructure as code tools such as Terraform and AWS Cloudformation

Terraform

Create S3 bucket to store terraform state. Need to ensure bucket is unique and also ideally within same region you want to provision your infrastructure resources onto.

aws s3 mb s3://[name of bucket] --region [region]

Initialize Terraform Backend

terraform init

Validating the terraform configuration files syntax is correct:

terraform validate

When make changes it is always a good idea to run terraform plan to check the changes are what you intend to make... even though terraform apply does prompt you confirm (if run without the --auto-approve option)

terraform plan

To apply your infrastructure changes (creation/modifications)

terraform apply

Cloudformation

Go to the Cloudformation directory and execute following command from the AWS CLI:

aws cloudformation create-stack --stack-name microservice-ec2-instance --template-body file://ec2_instances.yml --parameters ParameterKey=KeyName,ParameterValue=MyLondonKP

the --stack-name you can provide anything.

Option 3 - AWS CLI

Can also create the required EC2 instances via the AWS CLI

There's a pre-made create_ec2_instances script (available in both Bash & Python) that wraps around the AWS CLI command call. To use:

create_ec2_instances.sh

or using Python:

python create_ec2_instances.py

The scripts basically just does the following aws cli command underneath the hood:

aws ec2 run-instances --image-id [ami-id] --count 1 --instance-type t2.micro --key-name [KeyPair Name] --user-data [provisioning script]

Option 4 - from pre-build custom made AMI

See the microservice-ami project for more details on the corresponding AMIs for the required development platform.

Possible to uses Packer to build the AMI.

To build & deploy to your AWS account:

e.g.

packer build [microservice-*.json]

The AMI can now be referenced in any of the above 3 methods of creating the EC2 instance.

microservice-aws-ec2-setup's People

Contributors

colinbut avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.