Skip to content

Instantly share code, notes, and snippets.

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 immanuelpotter/3b36c3199ff5a86efef79d3411c021da to your computer and use it in GitHub Desktop.
Save immanuelpotter/3b36c3199ff5a86efef79d3411c021da to your computer and use it in GitHub Desktop.
quickly launch an amazon linux 1 instance that doesn't need to be in terraform on ec2 for messing around
#!/bin/bash
KEY_NAME=blah
SG_ID=blah
SUBNET_ID=blah
AWS_PROFILE=blah
AWS_REGION=eu-west-2
aws_cmd(){
aws --profile $AWS_PROFILE --region $AWS_REGION "$@"
}
get_image_id(){
aws_cmd ec2 describe-images \
--filters \
Name=name,Values='*-image-name-we-made' \
Name=architecture,Values=x86_64 \
Name=root-device-type,Values=ebs \
--query 'sort_by(Images, &Name)[-1].ImageId' \
--output text
}
main(){
aws_cmd ec2 run-instances \
--image-id "$(get_image_id)" \
--instance-type m5.large \
--count 1 \
--key-name $KEY_NAME \
--security-group-ids $SG_ID \
--subnet-id $SUBNET_ID \
--block-device-mappings 'DeviceName=/dev/sda1,Ebs={VolumeSize=40}'
}
main
#!/bin/bash
KEY_NAME=<set this>
aws ec2 run-instances --image-id
"$(aws ec2 describe-images \
--filters \
Name=name,Values='Amazon Linux*' \
Name=architecture,Values=x86_64 \
Name=root-device-type,Values=ebs \
--query 'sort_by(Images, &Name)[-1].ImageId' \
--output text)" \
--instance-type t2.micro --count 1 --key-name $KEY_NAME --security-groups default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment