Abstract


  • Basically a virtual machine

Accessing EC2


  • Obtain the tags and id of all EC2
aws ec2 describe-instances \
| jq '.Reservations[].Instances[] | {Tags: .Tags, InstanceId: .InstanceId, State: .State}'
  • Start a particular EC2 instance
aws ec2 start-instances --instance-ids <YOUR_INTANCE_ID>
  • SSH into Private EC2 on Local Machine

EC2 SSM Configuration

Make sure you are using an Amazon Linux Image, or you have setup system manager on EC2

aws ssm start-session --target <INTANCE_ID>

Debugging inside EC2


Cheatsheet
# Obtain User Data in EC2
sudo cat /var/lib/cloud/instance/user-data.txt
 
# Obtain the outputs of system outputs, including outputs of user data
cat /var/log/syslog

Obtain EC2 Metadata

get_mdsv2 () {
	echo $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" 2>/dev/null` \
&& curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/${1} 2>/dev/null)
}