我正在尝试向 yaml
添加一个部分,以允许从默认 30
调整 ec2
的根卷。如果我使用 ec2 控制台启动实例,我可以将大小从 30 调整到 200,下面的代码确实创建了一个 ec2,但不使用调整后的根卷。谢谢:)
yaml
Parameters:
BlockDeviceMappings:
Type: Number
Description: Root Volume Size
Default: 40
RootDeviceName:
Type: String
Description: Volume Device Name
Default: "/dev/xvda"
Resources:
VolumeAttachment:
Type: AWS::EC2::VolumeAttachment
Properties:
Device: !Ref RootDeviceName
InstanceId: !Ref EC2
VolumeId: !Ref RootVolume
最佳答案
如果我描述要在 CloudFormation 中启动的新 EC2 实例,我会使用 LaunchTemplate。在 LaunchTemplateData 中,您可以在其中指定 BlockDeviceMappings 并将其链接到 EC2 资源中。
我在下面添加了一个示例模板,为简洁起见,我省略了一些信息。
Resources:
ec2Server:
Type: AWS::EC2::Instance
Properties:
LaunchTemplate:
LaunchTemplateId: !Ref ec2LaunchTemplate
Version: !GetAtt ec2LaunchTemplate.LatestVersionNumber
ec2LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: 'server-launch-template'
LaunchTemplateData:
IamInstanceProfile:
Arn: ...
ImageId: ...
InstanceType: ...
KeyName: ...
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 64
VolumeType: gp2
DeleteOnTermination: true
关于amazon-web-services - 在 yaml 中执行调整根卷大小,但在 ec2 中不调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68864291/