Associate existing IAM role with EC2 instance in CloudFormation

后端 未结 3 1408
忘了有多久
忘了有多久 2020-12-14 09:21

How can I use an existing IAM role for an EC2 instance, as opposed to creating a new one in my CloudFormation template?

For example, I have created a role in AWS Con

3条回答
  •  执念已碎
    2020-12-14 09:48

    You need an instance profile, a role, and the instance info (or launch configuration) itself.

    Your instance profile would look like this:

    "Resources" : {
      "InstanceProfile" : {
        "Type" : "AWS::IAM::InstanceProfile",
        "Properties" : {
          "Path" : "/",
          "Roles" : ["MyExistingRole"]
        }
      },
    
      "Instance" : {
        "Type" : "AWS::EC2::Instance",
        "Properties" : {
          "IamInstanceProfile" : {"Ref" : "InstanceProfile"}
          ...
        }
      }
    

    In particular - note that the reference in the Instance profile is to an existing RoleName

    Also - I've written about bootstrapping instances which uses instance profiles and roles to ensure we're not persisting security.

    The key thing is rather than using the {"Ref" : RoleName} etc, to use the actual name of the role.

提交回复
热议问题