gpt4 book ai didi

amazon-web-services - AWS 上的 CloudFormation 模板错误

转载 作者:行者123 更新时间:2023-12-03 07:13:55 27 4
gpt4 key购买 nike

在解决我的 AWS 模板上的这些错误时遇到问题。

这是我的错误:

WobblelandSecurityGroup CREATE_FAILED 属性 GroupName 的值必须为字符串类型

PrivateSubnet CREATE_FAILED 资源 PrivateSubnet 的属性验证失败,消息为:#/AvailabilityZone:预期类型:字符串,找到:JSONArray

InternetGateway CREATE_FAILED 资源 InternetGateway 的属性验证失败,并显示消息:#:不允许使用无关 key [KeyName]

这是我的模板:

AWSTemplateFormatVersion: 2010-09-09
Description: "Wumbo Jumbo"
Parameters:
AvailabilityZone:
Type: "AWS::EC2::AvailabilityZone::Name"
EnvironmentName:
Description: "An environment name that is prefixed to resource names"
Type: String
KeyName:
Default: mongodb
Type: "AWS::EC2::KeyPair::KeyName"
PrivateSubnetCIDR:
Default: 10.0.2.0/24
Description: "Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone"
Type: String
PublicSubnetCIDR:
Default: 10.0.0.0/24
Description: "Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone"
Type: String
VpcCIDR:
Default: 10.0.0.0/16
Description: "Please enter the IP range (CIDR notation) for this VPC"
Type: String
Resources:
WobblelandEc2Instance:
Properties:
ImageId: ami-04505e74c0741db8d
InstanceType: t2.micro
KeyName: KeyName
SecurityGroupIds:
- WobblelandSecurityGroup
UserData:
Fn::Sub: |
#!/bin/bash
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Type: "AWS::EC2::Instance"
WobblelandSecurityGroup:
Properties:
GroupDescription: "Allow HTTP/HTTPS and SSH inbound and outbound traffic"
GroupName:
- "-"
-
- Wobbleland-security-group
- dev
SecurityGroupIngress:
-
CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
-
CidrIp: 0.0.0.0/0
FromPort: 443
IpProtocol: tcp
ToPort: 443
-
CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
Type: "AWS::EC2::SecurityGroup"
DefaultPrivateRoute:
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: NatGateway
RouteTableId: PrivateRouteTable
Type: "AWS::EC2::Route"
DefaultPublicRoute:
DependsOn: InternetGatewayAttachment
Properties:
DestinationCidrBlock: 0.0.0.0/0
InternetGatewayId: !GetAtt InternetGateway.InternetGatewayId
RouteTableId: PublicRouteTable
Type: "AWS::EC2::Route"
InternetGateway:
Properties:
KeyName: !Ref 'KeyName'
Tags:
-
Key: Name
Value: EnvironmentName
-
Key: Env
Value: EnvironmentName
Type: "AWS::EC2::InternetGateway"
InternetGatewayAttachment:
Properties:
InternetGatewayId: !GetAtt InternetGateway.InternetGatewayId
VpcId: VPC
Type: "AWS::EC2::VPCGatewayAttachment"
NatGateway:
Properties:
AllocationId: NatGatewayEIP.AllocationId
SubnetId: PublicSubnet
Type: "AWS::EC2::NatGateway"
NatGatewayEIP:
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Type: "AWS::EC2::EIP"
PrivateRouteTable:
Properties:
Tags:
-
Key: Name
Value: "${EnvironmentName} Private Routes (AZ1)"
-
Key: Env
Value: EnvironmentName
VpcId: VPC
Type: "AWS::EC2::RouteTable"
PrivateSubnet:
Properties:
AvailabilityZone:
- 0
CidrBlock: PrivateSubnetCIDR
MapPublicIpOnLaunch: false
Tags:
-
Key: Name
Value: "${EnvironmentName} Private Subnet (AZ1)"
-
Key: Env
Value: EnvironmentName
VpcId: VPC
Type: "AWS::EC2::Subnet"
PublicRouteTable:
Properties:
Tags:
-
Key: Name
Value: "${EnvironmentName} Public Routes"
-
Key: Env
Value: EnvironmentName
VpcId: VPC
Type: "AWS::EC2::RouteTable"
PublicSubnet:
Properties:
AvailabilityZone:
- 0
CidrBlock: PublicSubnetCIDR
MapPublicIpOnLaunch: true
Tags:
-
Key: Name
Value: "${EnvironmentName} Public Subnet (AZ1)"
-
Key: Env
Value: EnvironmentName
VpcId: VPC
Type: "AWS::EC2::Subnet"
VPC:
Properties:
CidrBlock: VpcCIDR
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
-
Key: Name
Value: EnvironmentName
-
Key: Env
Value: EnvironmentName
Type: "AWS::EC2::VPC"

最佳答案

您遇到了三个不同的错误。


对于第一个:

WobblelandSecurityGroup CREATE_FAILED Value of property GroupName must be of type String

这是因为 GroupName 属性的类型不正确;我想你想要:

  GroupName: !Join
- "-"
- - Wobbleland-security-group
- dev

对于第二个:

PrivateSubnet CREATE_FAILED Properties validation failed for resource PrivateSubnet with message: #/AvailabilityZone: expected type: String, found: JSONArray

这是因为 AvailabilityZone 属性的类型不正确;我想你想要:

AvailabilityZone: !Select [ 0, !GetAZs ]

第三个:

InternetGateway CREATE_FAILED Properties validation failed for resource InternetGateway with message: #: extraneous key [KeyName] is not permitted

这是因为 KeyName 不是该资源的有效属性。您可以从文档中找到更多关于哪些 key 资源支持的信息;在这种情况下,this page .

关于amazon-web-services - AWS 上的 CloudFormation 模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71786158/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com