带aws-sdk的requestSpotInstances UnexpectedParameter的TagSpecifications [英] TagSpecifications with requestSpotInstances UnexpectedParameter with aws-sdk

查看:123
本文介绍了带aws-sdk的requestSpotInstances UnexpectedParameter的TagSpecifications的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将标签添加到我的AWS Spot请求.但是它给我返回了 {UnexpectedParameter:在params.LaunchSpecification 中找到了意外的键'TagSpecifications'.我遵循了本文档,我已经尝试将此代码移出LaunchSpecification,但错误仍然存​​在.

I'm trying to add a tag to my AWS Spot Request. But it has returned me { UnexpectedParameter: Unexpected key 'TagSpecifications' found in params.LaunchSpecification. I have followed this documentation, and I have already tried to move this code out of LaunchSpecification, but the error persists.

  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中.我的选择已经用完了.

Something makes me think that the problem is in the documentation or in the aws-sdk for Javascript itself. My options are exhausted.

推荐答案

错误消息正确.根据文档 RequestSpotLaunchSpecification 对象没有名为 TagSpecifications 的属性.

The error message is correct. According to the documentation, the RequestSpotLaunchSpecification object doesn't have an attribute called TagSpecifications.

但是,您可以在创建竞价型实例请求后对其进行标记.

However, you can tag your Spot Instance request after you create it.

ec2.requestSpotInstances(params)返回一个 SpotInstanceRequest 对象的数组,每个对象都包含一个 spotInstanceRequestId (例如, sir-012345678 ).对这些竞价型实例使用 CreateTags API 要求添加标签的ID.

ec2.requestSpotInstances(params) returns an array of SpotInstanceRequest objects, each containing a spotInstanceRequestId (e.g. sir-012345678). Use the CreateTags API with these Spot Instance request ids to add the tags.

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

这篇关于带aws-sdk的requestSpotInstances UnexpectedParameter的TagSpecifications的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆