微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cloudformation 无法解析参数 - VolumeAttachment

如何解决Cloudformation 无法解析参数 - VolumeAttachment

我正在尝试实施一个 Cloudformation 模板,该模板会将现有 EBS 卷挂载到现有 EC2 实例。 这是我使用的代码

AWstemplateFormatVersion: "2010-09-09"
Description: MountEBStoDev
Parameters:
  EBSVolumeID:
    Description: The volume we want to attach to the instances
    Type: "List<AWS::EC2::Volume::Id>"
  InstanceIdToMount:
    Description: The instance to attach the volume to
    Type: "List<AWS::EC2::Instance::Id>"

Resources:
 MountPoint:
  Type: "AWS::EC2::VolumeAttachment"
  Properties:
    Device: /dev/sdh
    InstanceId: !Ref InstanceIdToMount
    VolumeId: !Ref EBSVolumeID

运行堆栈时,用户可以选择所需的 EBS 和 EC2 实例,我可以看到选择后参数正确指定,但 Cloudformation 无法附加 EBS 并出现错误

属性InstanceId的值必须是String类型”

我怀疑参数类型中的 List 是罪魁祸首,但我发现没有其他方法可以让用户从可用实例/EBS 中进行选择(除了静态列表)。

任何帮助都会非常有用。

解决方法

看起来 AWS::EC2::Instance::IdAWS::EC2::Volume::Idsupported parameter types,因此您只需更改代码即可使用它们。像这样:

AWSTemplateFormatVersion: "2010-09-09"
Description: MountEBStoDev
Parameters:
  EBSVolumeID:
    Description: The volume we want to attach to the instances
    Type: "AWS::EC2::Volume::Id"
  InstanceIdToMount:
    Description: The instance to attach the volume to
    Type: "AWS::EC2::Instance::Id"

Resources:
 MountPoint:
  Type: "AWS::EC2::VolumeAttachment"
  Properties:
    Device: /dev/sdh
    InstanceId: !Ref InstanceIdToMount
    VolumeId: !Ref EBSVolumeID
,

如果您的用户选择只有一个实例和卷(如果没有自定义资源或宏,则无法循环选择多个选项),则应该是:

Resources:
 MountPoint:
  Type: "AWS::EC2::VolumeAttachment"
  Properties:
    Device: /dev/sdh
    InstanceId: !Select [0,!Ref InstanceIdToMount]
    VolumeId: !Select [0,!Ref EBSVolumeID]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。