gpt4 book ai didi

amazon-web-services - 有没有办法从子网列表中选择在 CloudFormation 中启动 EC2 实例?

转载 作者:行者123 更新时间:2023-12-03 07:36:14 26 4
gpt4 key购买 nike

我正在尝试创建一个 CF 模板来启动三个不同的环境,但我希望能够选择在哪个子网中启动 EC2 实例,而无需在模板中对特定子网进行硬编码。然而,在下面的示例中,我收到一个错误,指出 SubnetId 必须是字符串。我想不出任何其他方法来实现这一目标。有什么想法吗?

Parameters:
EnvironmentType:
Type: String
Default: Dev
AllowedValues:
- Dev
- Test
- Production
Description: Select Environment Type (Dev, Test, Production)
SubnetIdList:
Type: String
AllowedValues:
- Public1
- Public2
- Private
Description: Select a subnet



Mappings:
InstanceSize:
Dev:
"EC2" : "t3.micro"
Test:
"EC2" : "t3.small"
Production:
"EC2" : "t3.medium"
Sub:
Public1:
"Subnet" : "subnet-05daa558dc3f65529" #public 1
Public2:
"Subnet" : "subnet-0f57bb83e0fc545f4" #public 2
Private:
"Subnet" : "subnet-0eb76c49954acc803" #Private




Resources:
EC2:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0080e4c5bc078760e
InstanceType: !FindInMap [InstanceSize, !Ref EnvironmentType, EC2]
KeyName: Ashkelon
SubnetId: [Sub, !Ref SubnetIdList, Subnet]

最佳答案

我认为您的 Ec2 子网参数定义中缺少 !FindInMap。见下文

Resources:
EC2:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0080e4c5bc078760e
InstanceType: !FindInMap [InstanceSize, !Ref EnvironmentType, EC2]
KeyName: Ashkelon
SubnetId: !FindInMap [Sub, !Ref SubnetIdList, Subnet]

关于amazon-web-services - 有没有办法从子网列表中选择在 CloudFormation 中启动 EC2 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56586513/

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