Created
May 8, 2019 21:33
-
-
Save robertsosinski/54ac1ea346fd47c824bc596e95bfd17b to your computer and use it in GitHub Desktop.
AWS SDK CLI STS Usage
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
let fs = require("fs"); | |
let path = require("path"); | |
let AWS = require("aws-sdk"); | |
let cliPath = path.resolve(process.env.HOME, ".aws", "cli"); | |
/* | |
NOTES: Make sure you alias the SHA1 fingerprinted cache token to the profile name | |
E.G. ln -s ~/.aws/cli/cache/09a19nczc3zvza58zrftetyfso7yw9d48u6ugsel.json profile | |
Then run your program with the specified profile alias as an envrionemnt variable | |
E.G. AWS_SDK_CLI_STS_PROFILE=profile node app.js | |
*/ | |
module.exports = function() { | |
var sts; | |
try { | |
var cliString = fs.readFileSync(path.resolve(cliPath, process.env.AWS_SDK_CLI_STS_PROFILE), "utf8"); | |
var cliObject = JSON.parse(cliString); | |
sts = new AWS.STS().credentialsFrom(cliObject); | |
} | |
catch (e) { | |
// use defaults... | |
} | |
return sts; | |
}; |
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
var AWS = require("aws-sdk"); | |
var cliSTS = require("./aws-sdk-cli-sts"); | |
AWS.config.credentials = cliSTS(); | |
var s3 = new AWS.S3(); | |
s3.listBuckets({}, function(err, data) { | |
if (err) console.log(err); | |
if (data) console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment