Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2022 04:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# lets find the ec2 key value pairs
keypair=$(aws ec2 describe-key-pairs --query "KeyPairs[0].KeyName")
echo "Selected key pair is $keypair"
# lets find the security group
sg_id=$(aws ec2 describe-security-groups --group-names "openall" --query "SecurityGroups[0].GroupId")
echo "Selected security group is ${sg_id}"
# lets find the ami id
ami_id=$(aws ec2 describe-images --filters "Name=owner-id,Values=099720109477" "Name=description, Values='Canonical, Ubuntu, 20.04 LTS, amd64 focal image build on 2022-04-19'" --query "Images[0].ImageId" --output text)
echo "Selected ami id id ${ami_id}"
aws ec2 run-instances --image-id $ami_id --instance-type $instance_size --key-name $keypair --security-group-ids $sg_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment