首页 > 解决方案 > CloudFormation !Ref 未按预期工作

问题描述

我有下面的模板,它描述了一个新的 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-servicesamazon-cloudformation

解决方案


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

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

您提供的是一个角色 arn。


推荐阅读