Assume a role and export credentials

Assume an IAM role and put the temporary credentials into the shell environment in one step

eval $(aws sts assume-role --role-arn <id> --role-session-name ops --query 'Credentials.[`AWS_ACCESS_KEY_ID=`+AccessKeyId,`AWS_SECRET_ACCESS_KEY=`+SecretAccessKey,`AWS_SESSION_TOKEN=`+SessionToken]' --output text | sed 's/^/export /')

tool
aws14 commands
tags
awssecuritysecrets

More aws commands

  • aws ec2 describe-instances --filters Name=tag:Env,Values=prod Name=instance-state-name,Values=running --query 'Reservations[].Instances[].{id:InstanceId,ip:PrivateIpAddress,az:Placement.AvailabilityZone}' --output table

    List running prod instances with ID, private IP and AZ using a JMESPath query

  • aws s3 sync ./ s3://<name>/ --delete --exclude '*.tmp' --exclude '.git/*' --size-only

    Mirror a directory to a bucket. --delete removes objects that are gone locally. Note: --size-only compares only size, not timestamps

  • aws s3 presign s3://<name>/path/file.tgz --expires-in 3600

    Create a download link that works for 1 hour, without making the object public

  • aws eks update-kubeconfig --name <cluster> --region <id> --alias <cluster> --kubeconfig ~/.kube/config

    Add or refresh an EKS context with a short alias instead of the long ARN

  • aws ecr get-login-password --region <id> | docker login --username AWS --password-stdin <id>.dkr.ecr.<id>.amazonaws.com

    Log Docker in to ECR through stdin, so the token does not end up in shell history

all 14 aws commands