amazon-web-services - CloudFormation !Ref 未按预期工作

标签 amazon-web-services aws-cloudformation

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

最佳答案

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

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

实例配置文件格式如下所示 arn:aws:iam::123456789012:instance-profile/Webserver,因此请确保您的模板引用此格式。

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

关于amazon-web-services - CloudFormation !Ref 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63633953/

相关文章:

amazon-web-services - 访问拒绝上传到 s3

amazon-web-services - Cloudwatch 触发 Aws lambda

amazon-web-services - 如何防止通过Auto Scaling终止EC2实例?

amazon-web-services - AWS CloudFormation - Ubuntu Nginx 元数据

amazon-web-services - 从 DynamoDB 表中删除内容的最佳方法(使用 Jenkins + CloudFormation)

amazon-web-services - 使用 CloudFormation 模板验证 AWS 资源

python - 使用 Amazon Linux 的 Python 2.6.9 上的 mysql.connector 错误

node.js - Elastic Beanstalk 单实例 SSL .ebextensions 配置文件不起作用

amazon-web-services - 如何通过cloudformation附加vpc链接以获取api网关中的方法

amazon-web-services - “指定的存储桶不存在”错误 - S3 存储桶的策略禁止从特定 IP 上传