问题描述
对于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
解决方法
您的缩进不适用于WebAppLaunchConfig
和WebAppGroup
。建议尝试CloudFormation Linter中的VSCode来创作模板时内联查看这些错误:
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
,
除了缩进问题(请参阅其他答案)之外,您的模板还缺少WebAppTargetGroup
资源的定义。
因此,除非仅显示模板的一部分,否则即使更正了缩进,模板也不会部署。您需要定义WebAppTargetGroup
或将其从AutoScaling组中删除。