Last active
March 3, 2022 14:25
-
-
Save rms1000watt/d414683f99561d360a8099cd4068e61f to your computer and use it in GitHub Desktop.
NodeJS in EKS/K8s to assumeRoleWithWebIdentity
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
const AWS = require('aws-sdk'); | |
const fs = require('fs'); | |
const sts = new AWS.STS(); | |
sts.getCallerIdentity({}, console.log); | |
const webIdentityToken = fs.readFileSync(process.env.AWS_WEB_IDENTITY_TOKEN_FILE, "utf8"); | |
const role = sts.assumeRoleWithWebIdentity({ | |
RoleArn: process.env.AWS_ROLE_ARN, | |
RoleSessionName: "todo-put-something-dynamic-maybe", | |
WebIdentityToken: webIdentityToken | |
}, console.log); | |
console.log(role.data.Credentials.AccessKeyId); | |
console.log(role.data.Credentials.SecretAccessKey); | |
console.log(role.data.Credentials.SessionToken); | |
const stsNew = new AWS.STS({credentials: new AWS.Credentials( | |
role.data.Credentials.AccessKeyId, | |
role.data.Credentials.SecretAccessKey, | |
role.data.Credentials.SessionToken | |
)}); | |
stsNew.getCallerIdentity({}, console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment