Created
June 9, 2020 23:37
-
-
Save iann0036/d8883ed3b22967c9f8a22c2fcace9349 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
#!/usr/bin/env node | |
const request = require('request'); | |
const aws4 = require('aws4'); | |
const AWS = require('aws-sdk'); | |
let chain = new AWS.CredentialProviderChain(); | |
chain.resolve((err, awscreds) => { | |
let awsreq = aws4.sign({ | |
service: 'sts', | |
region: 'us-east-1', | |
method: 'POST', | |
path: '/?Action=GetSessionToken&Version=2011-06-15', | |
headers: { | |
'Content-Type': 'application/x-amz-json-1.1' | |
//'X-Amz-Target': 'STS.GetSessionToken' | |
}, | |
body: JSON.stringify({}) | |
}, { | |
secretAccessKey: awscreds.secretAccessKey, | |
accessKeyId: awscreds.accessKeyId | |
}); | |
request.post({ | |
url: 'https://' + awsreq.hostname + awsreq.path, | |
headers: awsreq.headers, | |
body: awsreq.body | |
}, function(err, httpResponse, body) { | |
if (err) { | |
console.log(err); | |
} | |
console.log(httpResponse.toJSON()); | |
console.log(body); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment