Created
August 17, 2015 18:29
-
-
Save venkatperi/8164fafa71b0c316231c to your computer and use it in GitHub Desktop.
REST acess AWS ApiGatetwy in nodejs. Uses "private" AWS v4 signer.
This file contains hidden or 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
AWS = require "aws-sdk" | |
https = require "https" | |
creds = | |
accessKeyId: "<<ACCESS KEY ID>>" | |
secretAccessKey: "<<SECRET ACCESS KEY>>" | |
opts = | |
method: "GET" | |
pathname: -> '/restapis' | |
path: "/restapis" | |
search: -> "" | |
region: "us-east-1" | |
headers : | |
host : "apigateway.us-east-1.amazonaws.com" | |
"presigned-expires": false | |
signer = new AWS.Signers.V4(opts, "apigateway") | |
signer.addAuthorization creds, new Date() | |
console.log JSON.stringify(opts, null, 2) | |
opts.host = "apigateway.us-east-1.amazonaws.com" | |
req = https.request opts, (res) -> | |
console.log 'statusCode: ', res.statusCode | |
console.log 'headers: ', res.headers | |
res.on 'data', (d) -> | |
process.stdout.write d | |
req.end() | |
req.on 'error', (e) -> console.error e | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment