I am beginning to learn Cloud Formation Templates and I am running into issues when I validate the template in AWS Cloud Formation -> Create new stack. I am writing the templates using the CloudFormation plugin in Pycharm. These are a couple of the error messages that I get when validating in CloudFormation:
1/10/2022, 5:41:06 PM - Template contains errors.: Template format error: YAML not well-formed. (line 27, column 16)
1/10/2022, 5:40:06 PM - Template contains errors.: Template format error: YAML not well-formed. (line 24, column 12)
Below is my simple code:
AWSTemplateFormatVersion: "2010-09-09"
# Description:
Resources:
#Create the VPC
MyCustomVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: '10.3.0.0/16'
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- key: Name
value: !Sub '${AWS::StackName}-application-vpc-acg'
# Create the Subnets
PublicSubnetA:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: '10.3.0.0/24'
MapPublicIpOnLaunch: false
AvailabilityZone: !Select [ 0, !GetAZs]
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-public-subnet-A'
VpcId: !Ref MyCustomVPC
PublicSubnetB:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: '10.3.1.0/24'
MapPublicIpOnLaunch: false
AvailabilityZone: !Select [1, !GetAz]
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-public-subnet-B'
VpcId: !Ref MyCustomVPC
#Create Internet Gateway
MyInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- key: Name
Value: !Sub '${AWS::StackName}-Internet-Gateway
#Attach Internet Gateway to VPC
MyIGWAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref MyInternetGateway
VpcId: !Ref MyCustomVPC
Any help to point me in the right direction is greatly appreciated. Thank you!
CodePudding user response:
There are many issues, such as spelling mistakes, missing parentheses, wrong functions. The correct version is:
AWSTemplateFormatVersion: "2010-09-09"
# Description:
Resources:
#Create the VPC
MyCustomVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: '10.3.0.0/16'
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-application-vpc-acg'
# Create the Subnets
PublicSubnetA:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: '10.3.0.0/24'
MapPublicIpOnLaunch: false
AvailabilityZone: !Select [ 0, !GetAZs ""]
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-public-subnet-A'
VpcId: !Ref MyCustomVPC
PublicSubnetB:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: '10.3.1.0/24'
MapPublicIpOnLaunch: false
AvailabilityZone: !Select [1, !GetAZs ""]
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-public-subnet-B'
VpcId: !Ref MyCustomVPC
#Create Internet Gateway
MyInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-Internet-Gateway'
#Attach Internet Gateway to VPC
MyIGWAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref MyInternetGateway
VpcId: !Ref MyCustomVPC
