【问题标题】:An error occurred (ValidationError) when calling the UpdateStack operation: Invalid template property or properties [WebAppGroup, WebAppLaunchConfig]调用 UpdateStack 操作时发生错误 (ValidationError):无效的模板属性或属性 [WebAppGroup, WebAppLaunchConfig]
【发布时间】:2020-12-01 17:09:24
【问题描述】:

我有以下 WebAppLaunchConfig 和 WebAppGroup 配置,不知道为什么会出现该错误。

escription: >
    High availability web app
Parameters:

    EnvironmentName:
        Description: An environment name that will be prefixed to resource names
        Type: String
Resources:
  LBSecGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow http to our load balancer
      VpcId:
        Fn::ImportValue:
          !Sub "${EnvironmentName}-VPCID"
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: 0.0.0.0/0
      SecurityGroupEgress:
      - IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: 0.0.0.0/0

  WebServerSecGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow http to our hosts and SSH from local only
      VpcId:
        Fn::ImportValue:
          !Sub "${EnvironmentName}-VPCID"
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: 22
        ToPort: 22
        CidrIp: 0.0.0.0/0
      SecurityGroupEgress:
      - IpProtocol: tcp
        FromPort: 0
        ToPort: 65535
        CidrIp: 0.0.0.0/0

WebAppLaunchConfig:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash
          # Install docker
          apt-get update
          apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
          curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
          add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
          apt-get update
          apt-get install -y docker-ce
          mkdir docker-test
          cd docker-test
          wget  https://udagram-dev-u.s3.ap-south-1.amazonaws.com/index.html.zip 
          apt-get install unzip
          unzip index.html.zip
          echo "FROM ubuntu:latest" >> Dockerfile
          echo "RUN apt-get update" >> Dockerfile
          echo "RUN apt-get install -y nodejs" >> Dockerfile
          echo "RUN apt-get install -y npm" >> Dockerfile
          echo "RUN npm install -g http-server" >> Dockerfile
          echo "WORKDIR /usr/apps/test-docker/" >> Dockerfile
          echo "COPY index.html /usr/apps/test-docker/" >> Dockerfile
          echo 'CMD ["http-server", "-s"]' >> Dockerfile
          docker build -t "test:test-docker" .
          usermod -aG docker ubuntu
          docker run -d -p 8080:8080 "test:test-docker"
      ImageId: ami-005bdb005fb00e791
      SecurityGroups:
      - Ref: WebServerSecGroup
      InstanceType: t3.medium
      BlockDeviceMappings:
      - DeviceName: "/dev/sdk"
        Ebs:
          VolumeSize: '10'

WebAppGroup:
      Type: AWS::AutoScaling::AutoScalingGroup
      Properties:
        VPCZoneIdentifier:
        - Fn::ImportValue: 
            !Sub "${EnvironmentName}-PRIV-NETS"
        LaunchConfigurationName:
          Ref: WebAppLaunchConfig
        MinSize: '4'
        MaxSize: '6'
        TargetGroupARNs:
        - Ref: WebAppTargetGroup    

【问题讨论】:

  • 你能像 YAML 文件一样编辑它吗?

标签: amazon-cloudformation aws-cli


【解决方案1】:

除了缩进问题(参见其他答案),您的模板缺少WebAppTargetGroup 资源的定义

因此,除非您只显示模板的一部分,否则即使在更正缩进之后它也不会部署。您需要定义 WebAppTargetGroup 或将其从 AutoScaling 组中删除。

【讨论】:

    【解决方案2】:

    WebAppLaunchConfigWebAppGroup 的缩进不正确。建议在创作模板时尝试 VSCode 中的 CloudFormation Linter 以查看这些错误:

    E1001 Top level template section escription is not valid
    E1001 Top level template section WebAppLaunchConfig is not valid
    E1001 Top level template section WebAppGroup is not valid
    E1012 Ref WebAppTargetGroup not found as a resource or parameter
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      相关资源
      最近更新 更多