2

在等待启动实例时,我重复运行相同的 EC2 API 调用。

var check_started = function() {
  console.log('Calling');
  ec2.call("DescribeInstanceStatus", {InstanceId:['pretend_instance_id']}, function(err, status_result){
    if (err) {
      console.log('error')
      console.log(err)
      console.log(status_result)
    } else {
      console.log('success')
    }
  }); 
}

var instance_started_checker = setInterval( check_started, 5 * 1000)

第一次调用总是成功,但后续调用失败:

The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

我该怎么做才能使重复调用起作用?

4

1 回答 1

2

我认为如果您在创建代理的选项中指定 API 版本可能会有所帮助。像这样:

var ec2 = aws.createEC2Client(yourAccessKeyId, yourSecretAccessKey, {
        version: "2012-04-01"
    }
);

我尝试了您的代码,但无法重现相同的错误。当我没有指定 API 版本时,我得到“InvalidAction”。这是我使用的代码:

var aws = require("aws-lib");
var ec2 = aws.createEC2Client("xXx", "yYy", {
    secure: "https",
    host: "ec2.eu-west-1.amazonaws.com",
    version: "2012-04-01"
}
);
var check_started = function() {
console.log('Calling');
ec2.call("DescribeInstanceStatus", {InstanceId:["i-abcdefg"]}, function(err, status_result) {
    if (err) {
      console.log('error')
      console.log(err)
      console.log(status_result)
    } else {
      console.log('success')
      console.log(status_result.instanceStatusSet)
      clearInterval(instance_started_checker);
    }
});
}
var instance_started_checker = setInterval( check_started, 5 * 1000);

出于好奇,您在调用 DescribeInstances 时是否遇到同样的错误?

于 2012-05-08T16:29:44.610 回答