【问题标题】:CreateStack operation: Template format error: Unresolved resource dependencies [VpcId] in the Resources block of the templateCreateStack 操作:模板格式错误:模板的 Resources 块中未解析的资源依赖项 [VpcId]
【发布时间】:2019-10-21 18:02:49
【问题描述】:

我正在使用多个 CF 模板,并打算跨模板导出和导入值。我很好地导出/导入了大多数值,但是在由于某种原因没有导入 VpcId 时遇到了这个问题。

第一个导出模板

Parameters:
  StackPrefix:
    Type: String
    Default: "app-name"

Outputs:
  VpcId:
    Value: !Ref VPC
    Export:
      Name: !Join [ ":", [ !Ref StackPrefix, VPC ] ]

第二个导入模板

Parameters:
  StackPrefix:
    Type: String
    Default: "app-name"

Resources:
  SecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: !Sub ${AWS::StackName}-alb
      SecurityGroupIngress:
        - CidrIp: "0.0.0.0/0"
          IpProtocol: "TCP"
          FromPort: 80
          ToPort: 80
      VpcId:
        Fn::ImportValue: !Sub "${StackPrefix}:VPC"

使用aws cli 部署模板会导致“模板验证错误”

aws --profile shiny-app cloudformation create-stack --stack-name app-elb --template-body file://02-load-balancer.yaml

An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved resource dependencies [VpcId] in the Resources block of the template

感谢任何帮助

【问题讨论】:

  • 您确定模板中没有其他内容会导致此问题吗?只是为了测试,从 VpcID 中删除导入并对 VPC ID 进行硬编码。您是否还可以确认 VpcID 实际上是从第一个堆栈中正确导出的?
  • 我不确定你指的是杯子。你在某处有!Ref: VpcId 吗?此外,为了调试您的第一个堆栈,您应该能够在 CloudFormation 控制台的“输出”选项卡中看到“导出名称”

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


【解决方案1】:

如果您的第一个堆栈的输出正确,请在 AWS 控制台中检查,否则请尝试:

!Sub '${AWS::StackName}:VPC'

您不需要在第一个堆栈中添加前缀参数,只需使用名称,然后在第 53 行的第二个堆栈中尝试类似的操作,并使用第一个堆栈的名称添加参数 ParentVPCStack。

 VpcId: {'Fn::ImportValue': !Sub '${ParentVPCStack}:VPC'}

对我来说这是可行的。

【讨论】:

    【解决方案2】:

    经过一个不眠之夜,跑过一位同事,我想回答我自己的问题

    @Seth E 感谢您的意见,您说对了。

    我在第 53-54 行有这个

     53       VpcId:
     54         Fn::ImportValue: !Sub "${StackPrefix}:VPC"
    

    ...在第 117 行出现了

    117       VpcId: !Ref VpcId
    
    

    我认为 CloudFormation 在很大程度上有助于识别模板中的哪一行有违规代码,但是对于这个错误,CloudFormation 对我来说不够清楚。在 CF 中调试(输出值不是那么直接),我认为这是我需要习惯于调试 CF 模板的东西。

    An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved resource dependencies [VpcId] in the Resources block of the template
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2020-03-30
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 2020-03-25
      • 2020-05-15
      相关资源
      最近更新 更多