How do I assume a role

0

I am using the CLI to try and I want to retrieve a value from secrets manager. My IAM user doesn't have access to retrieve secrets but it does have access to assume a role (deploy_role) that does have access. I'm unsure of how to set up the credentials profile to auth into that IAM user as well as assume the role. My credentials file looks like this:

[default] aws_access_key_id=[my iam user's access key] aws_secret_access_key=[my iam user's secret access key] region=us-east-1

Is there a way to set up credentials to auth as that IAM user as well as assume the role (deploy_role)? Or, do I need to somehow do it after it is authed with a separate command. I would like to not have a second command because when I get into the .Net SDK, I don't want to check in code that lists the specific role info.

Thank you! Cindy

1개 답변
0

Something like this:

aws sts assume-role \
   --role-arn <ROLE_ARN> \
   --role-session-name <ROLE_NAME> \
   --duration-seconds 3600 \
   --output text \
   --query Credentials.[SessionToken,SecretAccessKey,AccessKeyId,Expiration]"

export AWS_SESSION_TOKEN=$(echo $credentials | cut -f1 -d' ')
export AWS_SECRET_ACCESS_KEY=$(echo $credentials | cut -f2 -d' ')
export AWS_ACCESS_KEY_ID=$(echo $credentials | cut -f3 -d' ')
export AWS_SESSION_EXPIRATION=$(echo $credentials | cut -f4 -d' ')

If you are on an EC2 instance you can assign a role to the instance. See: IAM roles for Amazon EC2

profile pictureAWS
전문가
kentrad
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠