gpt4 book ai didi

amazon-web-services - 如何在 cloudformation 模板中指定 subnetID(从现有子网或我创建的子网)?

转载 作者:行者123 更新时间:2023-12-03 07:33:43 25 4
gpt4 key购买 nike

如何在 YAML cloudformation 模板中指定子网 ID(从现有子网或我创建的子网)?

我不断收到堆栈错误,它需要是字符串或以下内容。

2022-04-18 19:56:17 UTC+1000 DBInstance CREATE_FAILED 参数 groupName 不能与参数子网一起使用(服务:AmazonEC2;状态代码:400;错误代码:InvalidParameterCombination;请求 ID:45b4589e-0195- 4f13-9cde-d2200c0031bf;代理:空)

--- 
Parameters:
AvailabilityZone:
Type: String
Default: us-east-1a

EnvironmentInstanceType:
Description: "Specify the Environment type of the stack."
Type: String
Default: Web
AllowedValues:
- Web
- DB

KeyName:
Description: Saved Key Pair file for SSH Access
Type: AWS::EC2::KeyPair::KeyName

VpcId:
Description: Select your VPC
Type: AWS::EC2::VPC::Id

ImageId:
Description: GoldenAMI ImageId
Type: String
Default: ami-06170cf892b466b5a

PrivSubnetCIDR:
Description: Private Subnet CidrBlock
Type: String
Default: 10.0.1.0/24

PublicSecurityGroup:
Description: WebSecurityGroup
Type: String
Default: sg-081d3059c58edb3b6

PublicSubnet:
Description: Web/PublicSecurityGroup
Type : String
Default: subnet-0b3ea12c33b327f0a





Mappings:
EnvironmentToInstanceType:
Web:
InstanceType: t2.micro
DB:
InstanceType: t2.micro




Resources:

DBSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VpcId
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: !Ref PrivSubnetCIDR
MapPublicIpOnLaunch: false

DBInstance:
Type: AWS::EC2::Instance
Properties:
KeyName:
Ref: KeyName
InstanceType:
!FindInMap [
EnvironmentToInstanceType,
!Ref EnvironmentInstanceType,
InstanceType,
]
ImageId: !Ref ImageId
AvailabilityZone: !Ref AvailabilityZone
SubnetId:
Ref: DBSubnet
SecurityGroups: [!Ref DBSecurityGroup]


DBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Open MySQL (port 3306)"
VpcId:
Ref: VpcId


DBOutboundRule1:
Type: AWS::EC2::SecurityGroupEgress
Properties:
GroupId: !Ref DBSecurityGroup
IpProtocol: tcp
FromPort: 22
ToPort: 22
SourceSecurityGroupId: !Ref PublicSecurityGroup

DBInboundRule1:
Type: AWS::EC2::SecurityGroupEgress
Properties:
GroupId: !Ref DBSecurityGroup
IpProtocol: tcp
FromPort: 3306
ToPort: 3306
SourceSecurityGroupId: !Ref PublicSecurityGroup




DBRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VpcId

DBSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref DBRouteTable
SubnetId: !Ref DBSubnet


WebInstance:
Type: AWS::EC2::Instance
Properties:
KeyName:
Ref: KeyName
InstanceType:
!FindInMap [
EnvironmentToInstanceType,
!Ref EnvironmentInstanceType,
InstanceType,
]
ImageId: !Ref ImageId
# AvailabilityZone: !Ref AvailabilityZone
SubnetId: !Ref PublicSubnet
SecurityGroupIds:
- Ref: PublicSecurityGroup

最佳答案

该错误与子网无关,而是与您的安全组有关。而不是:

SecurityGroups: [!Ref DBSecurityGroup]

应该是:

SecurityGroupIds: [!GetAtt DBSecurityGroup.GroupId]

关于amazon-web-services - 如何在 cloudformation 模板中指定 subnetID(从现有子网或我创建的子网)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71910349/

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