-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_postman_from_aws.js
More file actions
38 lines (34 loc) · 1.1 KB
/
export_postman_from_aws.js
File metadata and controls
38 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const args = require('yargs').argv;
const url = require('url');
const fs = require('fs');
const util = require('util');
const AWS = require('aws-sdk');
/**
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html#getExport-property
*/
var parsed_url = url.parse(args.INVOKE_URL);
var restApiId = parsed_url.hostname.split(".")[0]
var stageName = parsed_url.pathname.replace(/\//g, '')
var params = {
exportType: 'swagger', /* required */
restApiId: restApiId, /* required */
stageName: stageName, /* required */
accepts: 'application/json',
parameters: {
'extensions': 'postman',
}
};
var apigateway = new AWS.APIGateway();
apigateway.getExport(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
console.log("Successful response from APIGateway"); // successful response
fs.writeFileSync("outputs/postman.json", util.inspect(JSON.parse(data.body), { depth: null }), 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
console.log("The Postman file was saved!");
}
});