Skip to content

Commit

Permalink
Use EC2 Instance Connect to access the server
Browse files Browse the repository at this point in the history
  • Loading branch information
mathcolo committed Feb 9, 2024
1 parent f50ae46 commit a810fb2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
11 changes: 0 additions & 11 deletions devops/cloudformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,5 @@
]
}
}
},
"Outputs": {
"InstanceHostname": {
"Description": "RRE's public hostname",
"Value": {
"Fn::GetAtt": [
"RREInstance",
"PublicDnsName"
]
}
}
}
}
5 changes: 3 additions & 2 deletions devops/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ aws cloudformation deploy --stack-name $STACK_NAME \
RREDomain=$DOMAIN \
RRECertArn=$CERT_ARN

INSTANCE_HOSTNAME=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='InstanceHostname'].OutputValue" --output text)
INSTANCE_PHYSICAL_ID=$(aws cloudformation list-stack-resources --stack-name $STACK_NAME --query "StackResourceSummaries[?LogicalResourceId=='RREInstance'].PhysicalResourceId" --output text)

# Run the playbook! :-)
export ANSIBLE_HOST_KEY_CHECKING=False # If it's a new host, ssh known_hosts not having the key fingerprint will cause an error. Silence it
ansible-playbook -v -i $INSTANCE_HOSTNAME, -u ubuntu --private-key ~/.ssh/transitmatters-rre.pem playbook.yml
SSH_PROXY_ARGS="-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id $INSTANCE_PHYSICAL_ID'"
ansible-playbook -v --ssh-extra-args $SSH_PROXY_ARGS -i $INSTANCE_PHYSICAL_ID, -u ubuntu --private-key ~/.ssh/transitmatters-rre.pem playbook.yml

# Grab the cloudfront ID and invalidate its cache
CLOUDFRONT_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items!=null] | [?contains(Aliases.Items, '$HOSTNAME')].Id | [0]" --output text)
Expand Down

0 comments on commit a810fb2

Please sign in to comment.