Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services CreateStack操作:模板格式错误:模板的资源块中存在未解析的资源依赖项[VpcId]_Amazon Web Services_Yaml_Amazon Cloudformation - Fatal编程技术网

Amazon web services CreateStack操作:模板格式错误:模板的资源块中存在未解析的资源依赖项[VpcId]

Amazon web services CreateStack操作:模板格式错误:模板的资源块中存在未解析的资源依赖项[VpcId],amazon-web-services,yaml,amazon-cloudformation,Amazon Web Services,Yaml,Amazon Cloudformation,我正在使用多个CF模板,并打算跨模板导出和导入值。我导出/导入的大多数值都很好,但是由于某种原因,VpcId没有被导入时遇到了这个问题 带导出的第一个模板 Parameters: StackPrefix: Type: String Default: "app-name" Outputs: VpcId: Value: !Ref VPC Export: Name: !Join [ ":", [ !Ref StackPrefix, VPC ] ]

我正在使用多个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--配置文件应用程序云信息创建堆栈--堆栈名称app elb--模板体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

经过一个不眠之夜,经过一位同事身边,我想回答我自己的问题,我非常感谢他的帮助

@赛斯:谢谢你的意见,你说得对

我在第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

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

!Sub '${AWS::StackName}:VPC'
您不需要在第一个堆栈中添加前缀参数,只需使用名称,然后在第53行的第二个堆栈中尝试类似的操作,并使用第一个堆栈的名称添加参数ParentVPCStack

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

对我来说,这很有效。

你确定模板中没有其他地方导致此问题吗?为了进行测试,请从VpcID中删除导入,并对VPC ID进行硬编码。您是否也可以确认VpcID实际上是从第一个堆栈正确导出的?我不确定您是否指向cuprit。你有
吗!参考:VpcId
在什么地方?此外,为了调试第一个堆栈,您应该能够在CloudFormation控制台的Outputs选项卡中看到导出名称