Skip to content

Instantly share code, notes, and snippets.

@stephenlauck
Created June 26, 2023 00:19
Show Gist options
  • Save stephenlauck/a623d067010853ea56554348c27b88f2 to your computer and use it in GitHub Desktop.
Save stephenlauck/a623d067010853ea56554348c27b88f2 to your computer and use it in GitHub Desktop.
curl https://test.spellcaster.sh/spells/aws-ssh-$(uname | tr '[:upper:]' '[:lower:]') | bash && export AWS_VM=spell-vm-01; aws ec2 wait instance-running --instance-ids $(aws ec2 describe-instances --filter Name=tag:Name,Values="${AWS_VM}" 'Name=instance-state-name,Values=[running, stopped, pending]' --query 'Reservations[*].Instances[*].InstanceId' --out text) && sleep 10 && ssh -o ConnectTimeout=20 -i ${AWS_VM}.pem ubuntu@$(aws ec2 describe-instances --filter Name=tag:Name,Values="${AWS_VM}" 'Name=instance-state-name,Values=[running, stopped, pending]' --query 'Reservations[*].Instances[*].PublicIpAddress' --out text)
@stephenlauck
Copy link
Author

stephenlauck commented Jun 26, 2023

zsh <(curl https://test.spellcaster.sh/spells/aws-ssh-$(uname | tr '[:upper:]' '[:lower:]')) && export AWS_VM=spell-vm-01; aws ec2 wait instance-running --instance-ids $(aws ec2 describe-instances --filter Name=tag:Name,Values="${AWS_VM}" 'Name=instance-state-name,Values=[running, stopped, pending]' --query 'Reservations[*].Instances[*].InstanceId' --out text) && sleep 10 && ssh -o ConnectTimeout=20 -i ${AWS_VM}.pem ubuntu@$(aws ec2 describe-instances --filter Name=tag:Name,Values="${AWS_VM}" 'Name=instance-state-name,Values=[running, stopped, pending]' --query 'Reservations[*].Instances[*].PublicIpAddress' --out text)

@stephenlauck
Copy link
Author

export AWS_VM=spell-vm-01; aws ec2 terminate-instances --instance-ids $(aws ec2 describe-instances --filter "Name=tag:Name,Values=${AWS_VM}" --query 'Reservations[*].Instances[*].InstanceId' 'Name=instance-state-name,Values=[running, stopped, pending]' --output text) && aws ec2 delete-key-pair --key-name ${AWS_VM} && rm ${AWS_VM}.pem; aws ec2 wait instance-terminated --instance-ids $(aws ec2 describe-instances --filter Name=tag:Name,Values="${AWS_VM}" 'Name=instance-state-name,Values=[running, stopped, pending]' --query 'Reservations[*].Instances[*].InstanceId' --out text) && aws ec2 delete-security-group --group-name spell-aws-sg && aws secretsmanager delete-secret --secret-id ${AWS_VM} --force-delete-without-recovery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment