json - 在cloudformation中创建ELB时出现错误

标签 json amazon-web-services yaml aws-cloudformation devops

AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      IpAddressType: ipv4
      AvailabilityZones:
        - ap-southeast-1
      Name: mytestingELB
      Scheme: internet-facing
      Type: application
      SecurityGroups:
        - !Ref sg-**********
      Subnets:
        - !Ref subnet-******
        - !Ref subnet-*******
      Metadata:
        'AWS::CloudFormation::Designer':
          id: 3f17841f-7296-4aeb-a464-94dbbf6542fd
      'AWS::ElasticLoadBalancingV2::TargetGroup':
        Properties:
          HealthCheckIntervalSeconds: '30'
          HealthCheckPath: /
          HealthCheckProtocol: HTTP
          HealthCheckTimeoutSeconds: '5'
          HealthyThresholdCount: '5'
          Matcher:
            HttpCode: '200'
          Name: testingtargetgroup
          Port: '80'
          Protocol: HTTP
          TargetType: instance
          UnhealthyThresholdCount: '2'
          VpcId: !Ref vpc-******

收到错误模板无效:模板格式错误:未解析的资源依赖项 [子网-、sg-、子网- , vpc-*] 在模板的资源 block

请帮我添加

最佳答案

如果vpc-*****subnet-******sg-********* * 是您现有 VPC、子网和安全组的实际 ID,那么您不需要 !Ref 来引用它们。

只需提供它们,无需 !Ref,例如

SecurityGroups:
  - sg-**********
Subnets:
  - subnet-******
  - subnet-*******

VpcId: vpc-******

新模板版本:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      IpAddressType: ipv4
      Name: mytestingELB
      Scheme: internet-facing
      Type: application
      SecurityGroups:
        - !Ref sg-**********
      Subnets:
        - !Ref subnet-******
        - !Ref subnet-*******

  MyTargetGroup
      'AWS::ElasticLoadBalancingV2::TargetGroup':
        Properties:
          HealthCheckIntervalSeconds: '30'
          HealthCheckPath: /
          HealthCheckProtocol: HTTP
          HealthCheckTimeoutSeconds: '5'
          HealthyThresholdCount: '5'
          Matcher:
            HttpCode: '200'
          Name: testingtargetgroup
          Port: '80'
          Protocol: HTTP
          TargetType: instance
          UnhealthyThresholdCount: '2'
          VpcId: !Ref vpc-******
添加了

MyTargetGroup 并删除了 AvailabilityZonesMetadata

关于json - 在cloudformation中创建ELB时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62650879/

相关文章:

javascript - 从 javascript 数组中获取 Json 对象

java - Spring MVC : strange @ResponseBody behavior

java - 判断一个对象是数组还是字符串

yaml - Python : Read information from . yaml

git - 来自 bash 的 YAML 解析器

android - JSON Android ListView

amazon-web-services - AWS CloudFormation 的全局环境变量

amazon-web-services - 使用 boto3 列出 AWS 实例类型

amazon-web-services - Cloudformation 错误 - 标识符为 'AWS::ApiGateway::Model' 的类型为 'Empty' 的资源已存在

go - 在 Go 中解析动态 YAML 的惯用方式是什么?