Im trying to get a list of all the API usage plans on my account, running the cli command returns my desired result, however I cant get the JS SDK version to work in Lambda. What's going wrong? I see in he sdk its paginated but it doesn't return data after I include that kind of info either.
CLI:
aws apigateway get-usage-plans
Output:
{
"items": [
{
"id": "3hhulv",
"name": "testplan",
"apiStages": [
{
"apiId": "dp6ounv3jd",
"stage": "default"
}
],
"throttle": {
"burstLimit": 10,
"rateLimit": 10.0
},
"quota": {
"limit": 10000,
"offset": 0,
"period": "MONTH"
}
}
]
}
In node:
const AWS = require('aws-sdk');
exports.handler = async (event) => {
var apigateway = new AWS.APIGateway();
var params = {};
var usageplans = apigateway.getUsagePlans(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
const response = {
statusCode: 200,
things : usageplans.data
};
return response;
};
output:
{
"statusCode": 200
}
I resolved the issue by removing the callback function and adding a .promise() onto it.