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.
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
docker run -d -p 80:8080 --rm --name ec2-test vensder/ec2-testing
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
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
Terminate environment:
eb terminate ec2-testing-blue
eb terminate ec2-testing-green
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/