Monday, December 31, 2018

Using AWS ECR with Docker

1) Setup Docker on Mac Pro

Download Docker from DockerHub and install
https://docs.docker.com/docker-for-mac/install/
Skip the login
A Whale icon appears on the top right corner on the Mac

From the terminal, execute docker ps or docker --version command to confirm installation.

2) Download a sample docker image
I used rabbitmq from DockerHub
https://hub.docker.com/_/rabbitmq/

From the terminal, execute docker pull rabbitmq

3) Create AWS ECR repository
Login to AWS > ECR
Create a new repository myrabbitmq
Once created, View Push Commands for instructions.

4) Upload a new image into ECR
From the terminal, execute these commands
docker image ls (List the Docker images)
$(aws ecr get-login --no-include-email --region us-east-1)
Login successful message will be displayed

docker tag excalibur:latest {your-aws-id}.dkr.ecr.us-east-1.amazonaws.com/myrabbitmq:latest
docker image ls (List the Docker images)
docker push {your-aws-id}.dkr.ecr.us-east-1.amazonaws.com/myrabbitmq:latest

Refresh ECR repository to view the uploaded image



Wednesday, October 31, 2018

AWS CLI query to list instance types and name with sort by instace type


aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=mytag,Values=myvalue" --query "Reservations[*].Instances[*].{name: Tags[?Key=='Name'] | [0].Value, InstanceType: InstanceType}" --output text --color off | sort -n -k 2



Thursday, October 25, 2018

AWS CLI query for EC2 instances summary (multiple filters)


aws ec2 describe-instances --output text --filters "Name=instance-state-name,Values=running" "Name=tag:mytagname,Values=mytagvalue"  --query 'Reservations[*].Instances[*].[InstanceType]' | sort | uniq -c
  18 c4.2xlarge
  10 c4.xlarge
   7 m4.10xlarge
   6 m4.16xlarge
   8 m4.2xlarge
   3 m4.4xlarge
  22 m4.large
  21 m4.xlarge
  26 r4.2xlarge
   3 r4.large
  10 r4.xlarge
   6 r5.2xlarge
  10 r5.4xlarge
   3 t2.medium