Last active
March 17, 2020 09:18
-
-
Save doi-t/ff37ff18f565230d96fc3e0cb2fbdfc5 to your computer and use it in GitHub Desktop.
Login to an opsworks instance from local with AWS session manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install the plugin first | |
# https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html | |
TARGET_HOSTNAME="<your target hostname>"; \ | |
OPSWORKS_STACK_ID="<your target OpsWorks Stack ID>"; \ | |
REGION="us-east-1"; \ | |
EC2_INSTANCE_ID=$(aws opsworks describe-instances --stack-id ${OPSWORKS_STACK_ID} --region ${REGION} \ | |
| jq --arg TARGET_HOSTNAME "$TARGET_HOSTNAME" \ | |
'.[][] | select(.Hostname | contains($TARGET_HOSTNAME)) | .Ec2InstanceId' --raw-output); \ | |
echo "Connecting to ${EC2_INSTANCE_ID}"; \ | |
aws ssm start-session --target ${EC2_INSTANCE_ID} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment