Coder Social home page Coder Social logo

bestseller_demo's Introduction

Architecture

Alt text

According to the requirements, basically I need to have an EC2 instance working in the private network and connected with S3 bucket. AWS provides VPC endpoints to connect ec2 instance behind private network with S3 buckets. The other way is to route network traffice through NAT Gateway on public subnet. In this solution VPC endpoints used. And besides that I had to serve index.html with bootstrapped Nginx. So I decided to put index.html into the S3 bucket and get it from there during the deployment.

Also I decided to create my own ami to use based on ubuntu-18.04 and initial bootstap configurations has been done in packer build part.

As an output of packer build command you have ami-XXXXXXXX to use it as an variable of ami.

Conclusion: To connect EC2 instance to the S3 bucket VPC endpoints has been used. nginx bootstrap has been done in with packer

Preconditions

Install Packer

Install AWSCLI

Configure AWS credentials

Packer and Terraform need to the AWS credentials so You need to export the keys below or you can use the aws CLI tool to configure credentials

aws configure 
$ export AWS_ACCESS_KEY_ID="anaccesskey"
$ export AWS_SECRET_ACCESS_KEY="asecretkey"
$ export AWS_DEFAULT_REGION="us-west-2"
$ terraform plan

Packer

For aws EC2 instance, we need to build our own ami with packer to install awscli and nginx on top of the ubuntu image

Go to "packer" directory and run below commands

packer validate \
-var 'region=us-west-2' \
-var 'instance_type=t2.micro' \
-var 'tag=bestseller' \
-var 'environment=prod' \
aws-ubuntu.pkr.hcl
packer build \
-var 'region=us-west-2' \
-var 'instance_type=t2.micro' \
-var 'tag=bestseller' \
-var 'environment=prod' \
aws-ubuntu.pkr.hcl

Then get ami-id and use it as an input parameter of terraform.

Alt text

Terraform

To initialize infrastructure run below command;

terraform plan \
-var="instance_ami=ami-0e25a85626e298436" \
-var="region=us-west-2" \
-var="tag=bestseller" \
-var="instance_type=t2.micro" \
-var="environment=prod" \
-out=plan

Alt text

terraform apply "plan"

Alt text

To destroy :

terraform plan -destroy \
-var="instance_ami=ami-0e25a85626e298436" \
-var="region=us-west-2" \
-var="tag=bestseller" \
-var="instance_type=t2.micro" \
-var="environment=prod" \
-out=plan

bestseller_demo's People

Contributors

mustafaerbay avatar

Watchers

 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.