I'm trying to call AWS Free Tier API from a Lambda function, but I'm getting this error:
Inaccessible host: `freetier.us-east-1.amazonaws.com' at port `undefined'. This service may not be available in the `us-east-1' region.
Free tier API documentation:
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/FreeTier.html
My code:
const AWS = require('aws-sdk');
module.exports = {
getFreeTierUsage: async (awsCredential) => {
var freetier = new AWS.FreeTier({
accessKeyId: awsCredential.accessKeyId,
secretAccessKey: awsCredential.secretAccessKey
});
var params = {};
let result = await freetier.getFreeTierUsage(params).promise();
return result;
}
}
What's wrong?
It looks like AWS is changing the URL format for their APIs.
Traditionally it would look something like:
https://freetier.us-east-1.amazonaws.com
However, the Class: AWS.FreeTier — AWS SDK for JavaScript documentation is showing it as:
https://freetier.us-east-1.api.aws
Need to include the endpoint parameter like this:
var freetier = new AWS.FreeTier({
endpoint: 'https://freetier.us-east-1.api.aws',
accessKeyId: awsCredential.accessKeyId,
secretAccessKey: awsCredential.secretAccessKey
});