aws sts assume-role
is very useful for cross-account access. Imaging using dev account for build and testing and assume to prod account for deployment.
To assume a role, your AWS account must be trusted by the role. The trust relationship is defined in the role’s trust policy when the role is created. That trust policy states which accounts are allowed to delegate access to this account’s role.
By default, the temporary security credentials created by AssumeRole last for one hour. However, you can use the optional DurationSeconds parameter to specify the duration of your session. You can provide a value from 900 seconds (15 minutes) up to the maximum session duration setting for the role. This setting can have a value from 1 hour to 12 hours.
To assume a role:
1 | aws sts assume-role --role-arn arn:aws:iam::123456789012:role/xaccounts3access --role-session-name s3-access-example |
The output of the command contains an access key, secret key, and session token that you can use to authenticate to AWS:
1 | { |
Used in build bash scripts:
1 | assume_role() { |
https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role.html