Help us understand the problem. What is going on with this article?

AWS CLI EC2 instance roleを使っているときに、assume role する方法

More than 1 year has passed since last update.

AWS CLI EC2 instance roleを使っているときに、assume role する方法

問題

AWS CLIは https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-roles.html で簡単にassume role で引き受けたroleが使用できるが、元の権限が EC2 instance role を使っているとこのページの通りだと The source_profile "default" must specify either static credentials or an assume role configuration と言われてしまい動作しない

./aws/config
[profile test]
role_arn = arn:aws:iam::xxxxxxxx:role/TestRole
source_profile = default

[default]
output = json
region = ap-northeast-1
-> % aws --profile test  ec2 describe-instances

The source_profile "default" must specify either static credentials or an assume role configuration

解決方法

https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#using-aws-iam-roles にある

credential_source = Ec2InstanceMetadata を指定すれば、できるようになる

./aws/config
[profile test]
role_arn = arn:aws:iam::xxxxxxxx:role/TestRole
credential_source = Ec2InstanceMetadata
region = ap-northeast-1

[default]
output = json
region = ap-northeast-1
-> % aws --profile test  ec2 describe-instances | head -8
{
    "Reservations": [
        {
            "Instances": [
                {
                    "Monitoring": {
                        "State": "disabled"
                    },
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした