Code Monkey home page Code Monkey logo

ec2-testing's Introduction

Simple Golang Web App in Docker for AWS EC2/ECS/Elastic Beanstalk testing

Go Build Status Docker

If you run this container in AWS Environment, the Web application will show you page with some meta-information about the current environment and environment variables inside the docker container.

alt text

How to run pre-built docker container on AWS

git clone https://github.com/vensder/ec2-testing.git
cd ec2-testing

Export your AWS Access keys:

export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY='YYzYYzzYYYYzYYYYYYYzYYYYzzzYzYzYYzYzzzzY'

Run helper script to configure S3 backend to store the Terraform state file:

cd terraform
./s3-terraform-state-helper.sh

Run Terraform plan and apply:

terraform plan
terraform apply

Copy the IP address from the terraform output and open it in the browser, for example:

Outputs:

instance_ip_addr = 35.172.233.117

Open http://35.172.233.117

How to run pre-built docker container locally

docker run -d -p 80:8080 --rm --name ec2-test vensder/ec2-testing

How to build image and run docker container locally

git clone https://github.com/vensder/ec2-testing.git
cd ec2-testing
docker build . -t ec2-testing
docker run -d -p 80:8080 --rm --name ec2-test ec2-testing

Open http://localhost/Hi%20there! or any other random path after slash in your web browser.

View logs:

docker logs ec2-testing

Stop container:

docker stop ec2-testing

How to run pre-built docker container in Elastic Beanstalk environment

You can use this container for testing of AWS Elastic Beanstalk Blue/Green deployment (see Dockerrun.aws.json) - just set environment variable "color" to appropriate color for each environment. You can create an Elastic Beanstalk applications and environments, using Elastic Beanstalk command-line interface:

eb init -p docker ec2-testing
eb create ec2-testing-blue  --instance_type t3.nano --region us-east-1 --envvars color=blue
eb create ec2-testing-green --instance_type t3.nano --region us-east-1 --envvars color=green
eb swap ec2-testing-blue --destination_name ec2-testing-green

alt text

Terminate environment:

eb terminate ec2-testing-blue
eb terminate ec2-testing-green

Run it in K8s locally

cd ./k8s
kubectl apply -f ec2-test.yml
kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
ec2-test-599869688d-b72s4   1/1     Running   0          5m24s
ec2-test-599869688d-nngrw   1/1     Running   0          5m24s
ec2-test-599869688d-txttm   1/1     Running   0          5m24s
ec2-test-599869688d-xhsgq   1/1     Running   0          5m24s

Add ec2-test.local to /etc/hosts:

grep 'ec2-test.local' /etc/hosts
127.0.0.1 ec2-test.local

Open in a browser http://ec2-test.local/

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.