api-gateway-put-resource
v1.0.0
Published
creates AWS API Gateway's resource if it doesn't exist
Downloads
1
Readme
api-gateway-put-resource
creates (or deletes) AWS API Gateway's resource if it doesn't exist.
Usage
example.js:
var AWS = require('aws-sdk');
var credentials = new AWS.SharedIniFileCredentials({
profile: 'org-stuff'
});
AWS.config.credentials = credentials;
var putResource = require('api-gateway-put-resource');
putResource(
new AWS.APIGateway({
region: 'ap-northeast-1'
}),
{
restApiId: 'xxxxx', // Your restApiId
deleteOthers: true, // Set true if you want to delete all resources that is not in path
path: [
'/api-gateway',
'/hi/api'
],
},
function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
}
);
$ node ./example.js { "items": [ { "id": "x", "path": "/", "resourceMethods": { "GET": {} } }, { "id": "y", "parentId": "x", "pathPart": "hi", "path": "/hi" }, { "id": "z", "parentId": "x", "pathPart": "api-gateway", "path": "/api-gateway" } ], "deletedItems": [], "operations": [ { "op": "apiGateway.createResource", "params": { "restApiId": "xxx", "parentId": "x", "pathPart": "hi" }, "message": "apiGateway: create resource /hi" }, { "op": "apiGateway.createResource", "params": { "restApiId": "xxx", "parentId": "x", "pathPart": "api-gateway" }, "message": "apiGateway: create resource /api-gateway" } ] }
## API
```javascript
var putResource = require('api-gateway-put-resource')
putFunction(apiGateway, params, cb)
This function creates (or deletes) AWS API Gateway's resource if it doesn't exist.
- Arguments
- apiGateway - required -
instance of AWS.APIGateway
- params - required -
map
- path - required -
Array<String> | String
- deleteOthers: - defaults to false -
Boolean
- dryRun: - defaults to false -
Boolean
- path - required -
- cb -
function(err, data) {}
- called with following arguments on the end of operation- Arguments (cb)
- err -
Error
- the error object from aws-sdk. Set tonull
if the operation is successful. - data -
map
- the data from aws-sdk. Set tonull
if the operation error occur.- items -
Array<map>
- the resources that are targets of the operation- id -
String
- parentId -
String
- pathPart -
String
- path -
String
- resourceMethods -
map
- id -
- deletedItems -
Array<map>
- the deleted resources- id -
String
- parentId -
String
- pathPart -
String
- path -
String
- id -
- operations -
Array<map>
- op -
String
- like a"apiGateway.createResource"
- params -
map
- like a{restApiId: 'xxx', path: '/foo'}
- message -
String
- like a"apiGateway: create resource /foo"
- op -
- items -
- err -
- Arguments (cb)
- apiGateway - required -