Last active
August 29, 2015 14:26
-
-
Save r7kamura/3d60c3efed22801868ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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 () { | |
return resource; | |
}); | |
}).then(function (resource) { | |
return client.putMethodResponse({ | |
httpMethod: endpoint.httpMethod, | |
resourceId: resource.source.id, | |
restapiId: restapi.source.id, | |
statusCode: 200 | |
}).then(function (response) { | |
console.log(response); | |
return resource; | |
}); | |
}).then(function (resource) { | |
return client.putIntegrationResponse({ | |
httpMethod: endpoint.httpMethod, | |
resourceId: resource.source.id, | |
restapiId: restapi.source.id, | |
statusCode: 200 | |
}).then(function () { | |
return resource; | |
}); | |
}); | |
}) | |
).then(function () { | |
return restapi; | |
}); | |
}).then(function (restapi) { | |
client.createDeployment({ | |
restapiId: restapi.source.id, | |
stageName: 'production' | |
}).then(function (resource) { | |
console.log(resource); | |
}); | |
}).catch(function (error) { | |
console.log(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment