【问题标题】:CloudFormation !Ref not working as expectedCloudFormation !Ref 未按预期工作
【发布时间】:2020-12-17 09:32:48
【问题描述】:

我有下面的模板,它描述了一个新的 OpsWorks 堆栈。它依赖于帐户中已经存在的两个角色,但我需要使用 !Ref 作为帐户 ID,因为此模板可以在任何地方生成堆栈。

  Stack4:
    Type: AWS::OpsWorks::Stack
    Condition: CreateStack4
    Properties:
      Name: !Ref StackName4
      DefaultOs: 'Amazon Linux 2'
      VpcId: !Ref VpcId
      DefaultSubnetId: !Ref SubnetId
      UseOpsworksSecurityGroups: True
      CustomCookbooksSource:
        Type: 's3'
        Url: https://oidigital-chef-recipes.s3.amazonaws.com/prd/aws-chef-recipes-master.zip
      ConfigurationManager:
        Name: Chef
        Version: "12"
      DefaultInstanceProfileArn: !Join 
        - ''
        - - 'arn:aws:iam::'
          - !Ref 'AWS::AccountId'
          - ':role/DefaultOiServerRole'
      ServiceRoleArn: !Join
        - ''
        - - 'arn:aws:iam::'
          - !Ref 'AWS::AccountId'
          - ':role/aws-opsworks-service-role'

由于某种原因,DefaultInstanceProfileArn 中的 !Join 声明未按预期工作。尝试创建堆栈时,会抛出以下错误。

Default Instance Profile Arn: must be an instance profile ARN belonging to AWS account

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    这实际上是一个instance profile 而不是一个角色,您指定了一个角色 Arn,因此它拒绝了这个。

    控制台隐藏此资源已创建,但当您实际将角色附加到实例时,它会在后台创建。如果您已通过控制台附加,则会有一个与已为您创建的角色名称同名的实例配置文件。

    实例配置文件格式类似于arn:aws:iam::123456789012:instance-profile/Webserver,因此请确保您的模板引用此内容。

    如果您还没有实例配置文件,您可以在 CloudFormationvia the CLI 中创建一个。

    【讨论】:

    • 你成功了。我刚刚在 ARN 中将 role 更改为 instance-profile 并且它工作正常,无需进行其他更改。
    【解决方案2】:

    您正在尝试引用实例配置文件 arn,其格式应为

    arn:aws:iam::1234567890:instance-profile/MyProfile-ASDNSDLKJ - 注意instance-profile

    您提供的是一个角色 arn。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 2021-06-04
      • 2022-01-24
      • 2015-05-11
      • 2020-05-15
      • 2014-10-31
      • 2018-02-12
      • 2014-01-20
      相关资源
      最近更新 更多