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

标签 amazon-web-services aws-cloudformation

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

相关文章:

api - aws api网关和lambda : multiple endpoint/functions vs single endpoint

amazon-web-services - 如何使用 Lambda 在无服务器应用程序中读取 POST 参数?

java - 如何记录堆栈跟踪 aws elastic beanstalk 以快速解决客户错误

amazon-web-services - 如何获取/设置AWS ECS容器实例角色

amazon-web-services - 使用 CloudFormation 更改集对正在运行的集群启用 AWS Redshift 加密

Django——我已经准备好了一个小应用程序,我应该使用私有(private) VPS 还是 Google App Engine?

amazon-web-services - 创建 firehose cloudformation 模板时出错

amazon-web-services - 如何将特定工件版本部署到 AWS ECS,而不在 Cloudformation 模板中对其 ID 进行硬编码

amazon-web-services - 如何在AWS中通过CloudFormation配置 "Instance Protection"?

python-3.x - Lambda 支持的自定义资源