Last active
January 10, 2017 23:29
-
-
Save kndt84/ab8538ed85cecb1f0e43f34ba2ff5878 to your computer and use it in GitHub Desktop.
Node.js から API Gateway を簡単に使えるパッケージ作りました ref: http://qiita.com/kndt84/items/25445998a7c372864cde
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
npm install aws-api-gateway-client |
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 apigClientFactory = require('aws-api-gateway-client') |
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
config = {invokeUrl:'https://xxxxx.execute-api.us-east-1.amazonaws.com'} | |
var apigClient = apigClientFactory.newClient(config); |
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 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 | |
}); |
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 apigClient = apigClientFactory.newClient({ | |
apiKey: 'API_KEY' | |
}); |
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 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 | |
}; |
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
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