gpt4 book ai didi

amazon-web-services - 没有默认vpc的ec2 cloudformation模板

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

EC2 模板是基本模板,但由于默认 vpc 不再存在而失败。结果会出错,通常会在参数默认值下进行设置。

不幸的是,创建默认 VPC 不是一个选项......

如何修改它以使用特定的 VPC?

只有在弄清楚错误的真正含义之后,我才知道我必须分配 VPC 并且无法告诉它使用“默认”

Parameters:
VPC:
Description: Testing using VPC created
Type: String
Default: vpc-8787789
Subnet:
Type: String
Default: subnet-7657657578



...
...
...
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref 'InstanceType'
VpcId: !Ref VPC
SecurityGroups:
- !Ref 'InstanceSecurityGroup'
KeyName: !Ref 'KeyName'
ImageId: !FindInMap
- AWSRegionArch2AMI
- !Ref 'AWS::Region'
- HVM64
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'SSHLocation'

我想我想了解的是如何修改此代码以使用特定的 vpcid。

最佳答案

该错误很可能来自 InstanceSecurityGroup,因为它没有指定 VpcId 的值。因此,它默认为不存在的默认 VPC。要解决此问题,请添加:VpcId: VPC

  InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'SSHLocation'
VpcId: !Ref VPC

关于amazon-web-services - 没有默认vpc的ec2 cloudformation模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55544530/

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