Skip to content

Instantly share code, notes, and snippets.

@r7kamura
Created August 2, 2015 16:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7kamura/8103a08a5a064ed1d551 to your computer and use it in GitHub Desktop.
Save r7kamura/8103a08a5a064ed1d551 to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk');
var Client = require('amazon-api-gateway-client').Client;
var RequestLogger = require('stackable-fetcher').RequestLogger;
var ResponseLogger = require('stackable-fetcher').ResponseLogger;
var client = new Client({
accessKeyId: AWS.config.credentials.accessKeyId,
region: 'us-east-1',
secretAccessKey: AWS.config.credentials.secretAccessKey,
}).use(RequestLogger).use(ResponseLogger);
// これ叩くと全部消せてお得
// client.listRestapis().then(function (restapis) {
// restapis.forEach(function (restapi) {
// client.deleteRestapi({ restapiId: restapi.source.id });
// });
// });
client.createRestapi({
name: 'test'
}).then(function (restapi) {
return client.deleteModel({
modelName: 'Empty',
restapiId: restapi.source.id
}).then(function () {
return restapi;
});
}).then(function (restapi) {
return client.deleteModel({
modelName: 'Error',
restapiId: restapi.source.id
}).then(function () {
return restapi;
});
}).then(function (restapi) {
return client.createResources({
paths: ['/articles', '/recipes'],
restapiId: restapi.source.id
}).then(function () {
return restapi;
});
}).then(function (restapi) {
return Promise.all(
[
{
httpMethod: 'GET',
path: '/articles'
},
{
httpMethod: 'GET',
path: '/recipes'
}
].map(function (endpoint) {
return client.findResourceByPath({
path: endpoint.path,
restapiId: restapi.source.id
}).then(function (resource) {
return client.putMethod({
httpMethod: endpoint.httpMethod,
resourceId: resource.source.id,
restapiId: restapi.source.id
}).then(function () {
return resource;
});
}).then(function (resource) {
return client.putIntegration({
httpMethod: endpoint.httpMethod,
integrationHttpMethod: 'GET',
resourceId: resource.source.id,
restapiId: restapi.source.id,
type: 'HTTP',
uri: 'https://api.github.com/users/r7kamura'
}).then(function (response) {
console.log(response);
});
});
})
);
}).catch(function (error) {
console.log(error);
});
@r7kamura
Copy link
Author

r7kamura commented Aug 2, 2015

実行するとこうなる

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment