Skip to content

Instantly share code, notes, and snippets.

@shaikkhajaibrahim
Created May 21, 2022 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaikkhajaibrahim/e65ae46818701b3c993b469d3f556eec to your computer and use it in GitHub Desktop.
Save shaikkhajaibrahim/e65ae46818701b3c993b469d3f556eec to your computer and use it in GitHub Desktop.
#!/bin/bash
# lets find the ec2 key value pairs
keypair=$(aws ec2 describe-key-pairs --query "KeyPairs[0].KeyName")
keypair=${keypair:1:-1}
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")
sg_id=${sg_id:1:-1}
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}"
instance_size="t2.micro"
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