Last active
November 14, 2024 12:18
-
-
Save geodis/708de75282156d5edc1704bddabfdfc9 to your computer and use it in GitHub Desktop.
access_to_container
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
prod="" | |
export AWS_PROFILE="profile" | |
DEST_ACCOUNT_ID=${prod} | |
aws sts assume-role \ | |
--role-arn "arn:aws:iam::${DEST_ACCOUNT_ID}:role/admin" \ | |
--role-session-name awscli-session | |
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \ | |
$(aws sts assume-role \ | |
--role-arn arn:aws:iam::${DEST_ACCOUNT_ID}:role/admin \ | |
--role-session-name user \ | |
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \ | |
--output text)) | |
## Registry login | |
# aws_account_id=${shared} | |
# regionID="eu-west-1" | |
# aws ecr get-login-password --region ${regionID} | docker login --username AWS --password-stdin ${aws_account_id}.dkr.ecr.${regionID}.amazonaws.com | |
We must set now container name and task arn of the container we want to access | |
``` | |
CONTAINER_NAME=<obtain from previous step> | |
TASK_ARN=<obtain from previous step> | |
CONTAINER_NAME=pre-redis | |
TASK_ARN=arn:aws:ecs:eu-west-1:1232:task/Cluster/xxxxxxxxx | |
``` | |
Access to container | |
``` | |
aws ecs execute-command \ | |
--region eu-west-1 \ | |
--cluster ${CLUSTER_NAME} \ | |
--task ${TASK_ARN} \ | |
--container ${CONTAINER_NAME} \ | |
--command "/bin/bash" \ | |
--interactive | |
``` | |
For logging out the container we can use *ctrl+D* or *exit* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment