AWS Cloudformation:YAML:密钥:预期名称 <block end>,但发现“?”值:“PublicSubnet2”

问题描述 投票:0回答:1

问题

YAML 格式错误,无法确定此 YAML 格式在线工具中缺少哪些内容需要纠正:https://www.anyjson.in/yaml-formatter 检查我的 YAML 脚本。

YAML 修复格式的努力

我尝试过值:公共子网2;值:公共子网2;值:“公共子网2”。在线 YAML 格式化程序中都出现相同的格式错误

YAML 错误

下面的 YAML 脚本中给出了以下 YAML 语法错误。我已经改了好几次了,还是无法解决格式yaml错误。

我尝试过值:公共子网2;值:公共子网2;值:“公共子网2”。现在不知道下一步要纠正第 82/83 行的 YAML 格式,根据下面的错误(下一个)

Line 83: while parsing a block collection in "<unicode string>", line 82, column 9: - Key: Name ^ (line: 82) expected <block end>, but found '?' in "<unicode string>", line 83, column 9: Value: 'PublicSubnet2' ^ (line: 83)

YAML 脚本

线路82/83

       - Key: Name
        Value: 'PublicSubnet2'

在此块中可以找到键/值 YAML 脚本的完整范围:

  Subnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: Ref VPC
      CidrBlock: 10.0.30.0/24
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
        Value: 'PublicSubnet2'

YAML 链接

完整的 YAML 格式尝试位于此链接:


YAML Formatter - Format and Beautify YAML Documents Online
Line 83: while parsing a block collection
  in "<unicode string>", line 82, column 9:
            - Key: Name
            ^ (line: 82)
expected <block end>, but found '?'
  in "<unicode string>", line 83, column 9:
            Value: 'PublicSubnet2'
            ^ (line: 83)
Enter YAML input below:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
...
245.
246.
247.
248.
249.
250.
251.

line numbers map to below YAML script:


Parameters:

  DBName:
    Default: mydb
    Description: My database
    Type: String
    MinLength: '1'
    MaxLength: '64'
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'

  DBUsername:
    Type: String
    Description: Master username for the RDS instance
    Default: admin

  DBPassword:
    Type: String
    NoEcho: true
    Description: Master password for the RDS instance
    Default: password

  DBInstanceClass:
    Default: db.m5.large
    Description: DB instance class
    Type: String

  DBAllocStore:
    Default: '50'
    Description: The size of the database (GiB)
    Type: Number
    MinValue: '20'
    MaxValue: '65536'

  DBInstance:
    Default: DBInstance
    Description: My database instance
    Type: String
    MinLength: '1'
    MaxLength: '63'
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
      - Key: Name
        Value: VPC

  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: 'aws--s3--bucket'

  IGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
      - Key: Name
        Value: VPC Internet Gateway

  Subnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: 10.0.20.0/24
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: 'PrivateSubnet1'

  Subnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: Ref VPC
      CidrBlock: 10.0.30.0/24
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
        Value: 'PublicSubnet2'


  resource aws_lb_test:
    name: test-lb-tf
    internal: false
    load_balancer_type: application
    security_groups:
    - aws_security_group.lb_sg.id
    subnets:
    - for subnet in aws_subnet.public: subnet.id

  enable_deletion_protection: true

  access_logs:
    bucket: aws_s3_bucket.lb_logs.id
    prefix: aws_lb_test
    enabled: true

  tags:
    Environment: production


  SSHSecGrp:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: Ref VPC
      GroupDescription: Security group egress
      SecurityGroupEgress:
        - CidrIp: 127.0.0.111/32
          IpProtocol: "-1"
 
  EC2SecGrp:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: Ref VPC
      GroupDescription: EC2 Security Group
      GroupName: aws-security-grp
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 80
        ToPort: 80
      SourceSecurityGroupId:
      - IpProtocol: tcp
        FromPort: 22
        ToPort: 22
        CidrIp: 127.0.0.112/32

  EC2Net1:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      SecurityGroupIds:
        - Ref EC2SecGrp
      SubnetId: !Ref Subnet1
      KeyName: EC2Net1
      UserData: 
        Fn::Base64: !Sub |
          #!/bin/bash
          yum update -y
          yum install -y httpd
          systemctl start httpd
          systemctl enable httpd
          #echo "<h1>Hello from Region us-east-2b</h1>" > /var/www/html/index.html

  EC2Net2:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      SecurityGroupIds:
        - !Ref EC2SecGrp
      SubnetId: Ref Subnet2
      KeyName: EC2Net1\2
      UserData: 
        Fn::Base64: !Sub |
          #!/bin/bash
          yum update -y
          yum install -y httpd
          systemctl start httpd
          systemctl enable httpd
          #echo "<h1>Hello from Region us-east-2b</h1>" > /var/www/html/index.html

  S3BuckPol:
    Type: 'AWS::S3::BucketPolicy'
    Properties:
      Bucket: Ref S3Bucket
      SecurityGroupIds:
        - Ref EC2SecGrp
      KeyName: S3BucketPol
      PolicyDocument:
        Statement:
          - Effect: Allow
            Action: 's3:*'
            Resource: !Sub 'arn:aws:s3:::${S3Bucket}/*'
            Principal:
              AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:user/@matthew'


  EC2TgtGrp:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 30
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 15
      HealthyThresholdCount: 5
      Matcher:
        HttpCode: '200'
      Name: EC2TargetGroup
      Port: 80
      Protocol: HTTP
      TargetGroupAttributes:
      - Key: deregistration_delay.timeout_seconds
        Value: '20'
      Targets:
      - Id: Ref EC2Net2
        Port: 80
      UnhealthyThresholdCount: 3

  EC2TgtGrp:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 30
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 15
      HealthyThresholdCount: 5
      Matcher:
        HttpCode: '200'
      Name: EC2TargetGroup
      Port: 80
      Protocol: HTTP
      TargetGroupAttributes:
      - Key: deregistration_delay.timeout_seconds
        Value: '20'
      Targets:
      - Id: Ref EC2Net1
        Port: 80
      UnhealthyThresholdCount: 3

  LoadBalance:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: aws-elb-load-balance
      Scheme: internet-facing
      Subnets:
      - Ref Subnet1

  AppLBListner:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - Type: forward
          TargetGroupArn: Ref VPC
      LoadBalancerArn: Ref LoadBalance
      Port: 80
      Protocol: HTTP

  MyRDS:
    Type: 'AWS::RDS::DBInstance'
    Properties:
      DBInstanceIdentifier: Ref DBInstance
      DBName: Ref DBName
      DBInstanceClass: Ref DBInstanceClass
      AllocatedStorage: Ref DBAllocStore
      Engine: MySQL
      MasterUsername: Ref DBUsername
      MasterUserPassword: Ref DBPassword
      SecurityGroupIds:
        - Ref EC2SecGrp
      KeyName: MyRDS
amazon-web-services yaml aws-cloudformation subnet
1个回答
0
投票

您的

Value
缩进错误,并且
Ref
拼写错误。应该是:

  Subnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: 10.0.30.0/24
      MapPublicIpOnLaunch: true
      Tags:
        - Key: Name
          Value: 'PublicSubnet2'

您不必检查模板的其余部分是否存在类似问题。

© www.soinside.com 2019 - 2024. All rights reserved.