gpt4 book ai didi

amazon-web-services - 在 yaml 中执行调整根卷大小,但在 ec2 中不调整大小

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

我正在尝试向 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/

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