Skip to content

Instantly share code, notes, and snippets.

@iann0036
Created Jun 9, 2020
Embed
What would you like to do?
#!/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