【问题标题】:Cloudformation fails to parse parameters - VolumeAttachmentCloudformation 无法解析参数 - VolumeAttachment
【发布时间】:2021-09-12 10:04:23
【问题描述】:

我正在尝试实现一个 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 的值必须是字符串类型"

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

任何帮助将不胜感激。

【问题讨论】:

  • 你如何运行堆栈?

标签: amazon-web-services amazon-ec2 amazon-cloudformation amazon-ebs


【解决方案1】:

看起来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

【讨论】:

  • 谢谢,这可行,但我仍然收到设备名称错误“未找到设备 /dev/sdh 上的卷 ID vol-xxxxxxxxxx 和实例 ID i-xxxxxxxxxxxxx 之间的卷附件” .有什么想法吗?
【解决方案2】:

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

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

【讨论】:

  • 看起来这解决了问题。我现在遇到设备名称问题,出现错误“未找到设备 /dev/sdh 处的卷 ID 和实例 ID 之间的卷附件”将尝试更改设备名称
  • 我认为 @YaMo IanMckay 的回答更好,所以请检查并在可能的情况下接受。对于新问题,请提出新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-15
  • 2021-01-07
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多