I am running the same EC2 API call repeatedly, as I wait for an instance to be started.
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 first call always succeeds, but subsequent calls fail with:
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.
What can I do to make the repeated calls work?
I think it might help if you specify an API version in the options of creating an agent. Like so:
var ec2 = aws.createEC2Client(yourAccessKeyId, yourSecretAccessKey, {
version: "2012-04-01"
}
);
I tried your code, but was not able to reproduce the same error. I get 'InvalidAction' when I do not specify the API version. This is the code I used:
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);
Out of curiosity, do you get the same error with invoking DescribeInstances?