我開始學習 Cloud Formation 模板,當我在 AWS Cloud Formation -> Create new stack 中驗證模板時遇到了問題。我正在使用 Pycharm 中的 CloudFormation 插件撰寫模板。這些是我在 CloudFormation 中驗證時收到的一些錯誤訊息:
2022 年 1 月 10 日,下午 5:41:06 - 模板包含錯誤。:模板格式錯誤:YAML 格式不正確。(第 27 行,第 16 列)
2022 年 1 月 10 日,下午 5:40:06 - 模板包含錯誤。:模板格式錯誤:YAML 格式不正確。(第 24 行,第 12 列)
下面是我的簡單代碼:
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
非常感謝任何幫助我指出正確方向的幫助。謝謝!
uj5u.com熱心網友回復:
有很多問題,例如拼寫錯誤,缺少括號,功能錯誤。正確的版本是:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/408897.html
標籤:
