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 doi-t/ff37ff18f565230d96fc3e0cb2fbdfc5 to your computer and use it in GitHub Desktop.
Save doi-t/ff37ff18f565230d96fc3e0cb2fbdfc5 to your computer and use it in GitHub Desktop.
Login to an opsworks instance from local with AWS session manager
# 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