Useful Commands

SSH to an EC2 instnace

ssh -i ~/repos/aws/keypair/awsAccess.pem ec2-user@52.65.42.180

Copy a file to remote server

scp -i ~/repos/aws/keypair/awsAccess.pem ~/repos/aws/keypair/awsAccess.pem ec2-user@13.236.232.70:/tmp/

Get docker login

Get docker login bash command

aws ecr get-login --no-include-email

Create stack using aws-cli

aws cloudformation create-stack --stack-name simpleSite --template-body file://s3_simple_website.json --parameters ParameterKey=Stackname,ParameterValue=stage1,ParameterKey=AppName,ParameterValue=something

aws cloudformation delete-stack --stack-name simpleSite

Redirect all TCP traffic to another ip address.

sudo yum install socat
socat TCP-LISTEN:8080,fork TCP:10.0.100.121:80

Install redis-cli to aws-ami

sudo yum install -y gcc wget http://download.redis.io/redis-stable.tar.gz && tar xvzf redis-stable.tar.gz && cd redis-stable && make sudo cp src/redis-cli /usr/bin/

Connect to remote redis

redis-cli -h 10.144.62.3 -p 30000

Test

redis-cli ping should get PONG back

redis-cli 127.0.0.1:6379> set red-count 0 OK 127.0.0.1:6379> get red-count “0”

AWS ECS delete hosted zone - service discovery

aws servicediscovery list-services --region ap-southeast-2
aws servicediscovery delete-service --id srv-pass65zl4auilb4e  --region ap-southeast-2
aws servicediscovery list-namespaces --region ap-southeast-2
aws servicediscovery delete-namespace --id ns-nsslrl7nl2u6safn --region ap-southeast-2

Create, attach and use a new EBS

-- View available disks
sudo lsblk --output NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,LABEL

# create fs if its new
sudo mkfs -t ext4 /dev/xvdf

sudo mkdir /etc/conf

sudo mount /dev/xvdf  /etc/conf

df -h