LoginSignup
1
1

More than 5 years have passed since last update.

早速、既存のEC2にIAMロールを付けてみた

Posted at

うっかり IAM ロールを付け忘れて EC2 を起動してしまったので後から付与してみた。
実行例がなかったので覚え書き。

  1. 事前準備

GUIでロールを作っておきます。下記コマンドの例では「role_waka」という名前のロールを使っています。
image

 
 
2. ロールを付けるコマンド


aws --profile waka --region ap-northeast-1 ec2 associate-iam-instance-profile --instance-id i-XXXXXXXXXXXXXXXXX --iam-instance-profile Name=role_waka

[オプションの説明]
 --instance-id :インスタンスID
 --iam-instance-profile :Name=IAMロール名
 
 
3. 確認コマンド


aws --profile waka --region ap-northeast-1 ec2 describe-iam-instance-profile-associations

[表示例]

{
    "IamInstanceProfileAssociations": [
        {
            "InstanceId": "i-XXXXXXXXXXXXXXXXX",
            "State": "associated",
            "AssociationId": "iip-assoc-XXXXXXXXXXXXXXXXX",
            "IamInstanceProfile": {
                "Id": "XXXXXXXXXXXXXXXXXXXXX",
                "Arn": "arn:aws:iam::XXXXXXXXXXXX:instance-profile/role_waka"
            }
        }
    ]
}

 
[Amazon Web Services ブログ] 既存のAmazon EC2インスタンスにIAM Roleがアタッチできるようになりました

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1