Skip to content

Instantly share code, notes, and snippets.

@kndt84
Last active January 10, 2017 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kndt84/ab8538ed85cecb1f0e43f34ba2ff5878 to your computer and use it in GitHub Desktop.
Save kndt84/ab8538ed85cecb1f0e43f34ba2ff5878 to your computer and use it in GitHub Desktop.
Node.js から API Gateway を簡単に使えるパッケージ作りました ref: http://qiita.com/kndt84/items/25445998a7c372864cde
npm install aws-api-gateway-client
var apigClientFactory = require('aws-api-gateway-client')
config = {invokeUrl:'https://xxxxx.execute-api.us-east-1.amazonaws.com'}
var apigClient = apigClientFactory.newClient(config);
var apigClient = apigClientFactory.newClient({
accessKey: 'ACCESS_KEY',
secretKey: 'SECRET_KEY',
sessionToken: 'SESSION_TOKEN', //OPTIONAL: If you are using temporary credentials you must include the session token
region: 'eu-west-1' // OPTIONAL: The region where the API is deployed, by default this parameter is set to us-east-1
});
var apigClient = apigClientFactory.newClient({
apiKey: 'API_KEY'
});
var params = {
//This is where any header, path, or querystring request params go. The key is the parameter named as defined in the API
userId: '1234',
};
// Template syntax follows url-template https://www.npmjs.com/package/url-template
var pathTemplate = '/users/{userID}/profile'
var method = 'GET';
var additionalParams = {
//If there are any unmodeled query parameters or headers that need to be sent with the request you can add them here
headers: {
param0: '',
param1: ''
},
queryParams: {
param0: '',
param1: ''
}
};
var body = {
//This is where you define the body of the request
};
apigClient.invokeApi(params, pathTemplate, method, additionalParams, body)
.then(function(result){
//This is where you would put a success callback
}).catch( function(result){
//This is where you would put an error callback
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment