Skip to content

Instantly share code, notes, and snippets.

@geodis
Last active August 20, 2024 08:39
Show Gist options
  • Save geodis/708de75282156d5edc1704bddabfdfc9 to your computer and use it in GitHub Desktop.
Save geodis/708de75282156d5edc1704bddabfdfc9 to your computer and use it in GitHub Desktop.
access_to_container
prod=""
export AWS_PROFILE="claranet-root"
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