【问题标题】:Cloudformation to automatically pick up the default instance profileCloudformation 自动获取默认实例配置文件
【发布时间】:2016-05-25 06:43:19
【问题描述】:

我使用 CloudFormation 模板将实例部署到环境中。我希望模板为实例选择默认 EC2 实例配置文件,类似于“arn:aws:iam::12345678910:role/EC2InstanceProfile-InstanceRole-14F2A0ATJNUO1”

我想为我拥有的每个 AWS 账户使用相同的模板。但是,问题在于每个帐户中的实例配置文件名称都不同。随机生成的后缀附加到名称(在此示例中为 14F2A0ATJNUO1)。如何解决此问题以使模板可在每个帐户中重复使用。如果可能,请提供代码。

    "EC2InstanceProfile" : {
      "Description" : "The default instance profile",
      "Type": "String",
      "ConstraintDescription" : "must be the name of an existing defualt EC2 instance profile."
    },

"IamInstanceProfile": { "Ref": "EC2InstanceProfile" }

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-cloudformation


    【解决方案1】:

    使用以下 cloudformation 从角色名称获取您的实例配置文件。

    "InstanceProfile" : {
      "Type" : "AWS::IAM::InstanceProfile",
      "Properties" : {
        "Path" : "/",
        "Roles" : ["your-role-name"]
      }
    }
    "IamInstanceProfile": {"Fn::GetAtt" : ["InstanceProfile", "Arn"] },
    

    【讨论】:

    • 嗨,这不能回答我的问题。实例配置文件已创建。所以模板需要选择实例配置文件。我可以硬编码名称“arn:aws:iam::12345678910:role/EC2InstanceProfile-InstanceRole-14F2A0ATJNUO1”,但该模板在其他账户中不起作用,因为实例角色具有随机后缀。
    • 好的。我们可以创建新的 InstanceProfile,因为它可能不会影响任何功能。或者您可以使用 InstanceProfile 输入作为 cloudformation 的参数来重用模板。
    • 您必须通过 Ref 获取 IamInstanceProfile 值。
    猜你喜欢
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 2018-08-06
    • 1970-01-01
    • 2017-11-15
    相关资源
    最近更新 更多