【问题标题】:TagSpecifications with requestSpotInstances UnexpectedParameter with aws-sdkTagSpecifications with requestSpotInstances UnexpectedParameter with aws-sdk
【发布时间】:2020-05-15 01:05:27
【问题描述】:

我正在尝试向我的 AWS Spot 请求添加标签。但它返回了我{ UnexpectedParameter: Unexpected key 'TagSpecifications' found in params.LaunchSpecification。 我关注了this documentation,并且已经尝试将此代码移出LaunchSpecification,但错误仍然存​​在。

  const params = {
    InstanceCount: 1,
    LaunchSpecification: {
      ImageId: config.aws.instanceAMI,
      KeyName: 'backoffice',
      InstanceType: config.aws.instanceType,
      SecurityGroupIds: [config.aws.instanceSecurityGroupId],
      TagSpecifications: [{
        ResourceType: 'instance',
        Tags: [{
          Key: 'Type',
          Value: 'Mongo-Dump',
        }],
      }],
      BlockDeviceMappings: [{
        DeviceName: '/dev/xvda',
        Ebs: {
          DeleteOnTermination: true,
          SnapshotId: 'snap-06e838ce2a80337a4',
          VolumeSize: 50,
          VolumeType: 'gp2',
          Encrypted: false,
        },
      }],
      IamInstanceProfile: {
        Name: config.aws.instanceProfileIAMName,
      },
      Placement: {
        AvailabilityZone: `${config.aws.region}a`,
      },
    },
    SpotPrice: config.aws.instancePrice,
    Type: 'one-time',
  };

  return ec2.requestSpotInstances(params).promise();

有些事情让我认为问题出在文档或 Javascript 本身的 aws-sdk 中。我的选择已经用尽了。

【问题讨论】:

    标签: node.js amazon-web-services aws-sdk


    【解决方案1】:

    错误信息是正确的。根据documentationRequestSpotLaunchSpecification 对象没有名为TagSpecifications 的属性。

    但是,您可以在创建 Spot 实例请求后对其进行标记。

    ec2.requestSpotInstances(params) 返回一个由SpotInstanceRequest 对象组成的数组,每个对象都包含一个spotInstanceRequestId(例如sir-012345678)。使用带有这些 Spot 实例请求 ID 的 CreateTags API 添加标签。

    const createTagParams = {
      Resources: [ 'sir-12345678' ], 
      Tags: [
        {
          Key: 'Type', 
          Value: 'Mongo-Dump'
        }
      ]
    };
    ec2.createTags(createTagParams, function(err, data) {
      // ...
    });
    

    【讨论】:

    • 它有效,但我希望它可以在 requestSpotInstances 上完成。 aws-sdk javascript 中有一个错误,对吧?
    • 这不是 JavaScript SDK 中的错误。不幸的是,Amazon EC2 RequestSpotInstances API 本身不接受标签作为参数。但是感谢您的反馈,我会确保将其返回给服务团队。
    • @DennisTraub 我认为非常令人困惑的是TagSpecifications 列为docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/…中的参数,在Calling the requestSpotInstances operation下面的示例代码中。
    • 同样,当我们查看docs.aws.amazon.com/cli/latest/reference/ec2/… 时,我们会看到--tag-specifications 是一个有效的命令行标志。我们应该在这里查看 CLI 的实现,看看它是否以及如何将标签规范包含在它为请求现场实例而发送的同一个 http 请求中。
    • @Dr.Jan-PhilipGehrcke 我在文档中也发现了这一点。我认为这会将标签应用于 SpotInstanceRequest itself - 当我期望/寻求的是一种在创建后标记实例的方法时。
    猜你喜欢
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-27
    相关资源
    最近更新 更多