-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.sh
More file actions
12 lines (11 loc) · 880 Bytes
/
Copy pathscript.sh
File metadata and controls
12 lines (11 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/bash
mkdir -p ~/.ssh && chmod 700 $_
key_name="CloudFormationKeyPair"
aws ec2 create-key-pair --key-name ${key_name} --query 'KeyMaterial' --output text > ~/.ssh/${key_name}.pem
chmod 600 ~/.ssh/${key_name}.pem
aws cloudformation create-stack --stack-name test-stack --template-body file://test-stack.yaml
aws cloudformation wait stack-create-complete --stack-name test-stack
instance_id=$(aws cloudformation describe-stack-resources --stack-name test-stack | jq -r '.StackResources[] | select(.StackName == "test-stack" and .ResourceType == "AWS::EC2::Instance") | .PhysicalResourceId')
dns_name=$(aws ec2 describe-instances | jq -r --arg instance_id ${instance_id} '.Reservations[] | .Instances[] | select(.InstanceId == $instance_id) | .PublicDnsName')
ssh-keyscan -H ${dns_name} >> ~/.ssh/known_hosts
ssh -i ~/.ssh/CloudFormationKeyPair.pem ubuntu@${dns_name}