Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rms1000watt/d414683f99561d360a8099cd4068e61f to your computer and use it in GitHub Desktop.
Save rms1000watt/d414683f99561d360a8099cd4068e61f to your computer and use it in GitHub Desktop.
NodeJS in EKS/K8s to assumeRoleWithWebIdentity
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