Skip to content

Instantly share code, notes, and snippets.

@iann0036
Created June 9, 2020 23:37
Show Gist options
  • Save iann0036/d8883ed3b22967c9f8a22c2fcace9349 to your computer and use it in GitHub Desktop.
Save iann0036/d8883ed3b22967c9f8a22c2fcace9349 to your computer and use it in GitHub Desktop.
#!/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