What is @aws-sdk/credential-provider-web-identity?
The @aws-sdk/credential-provider-web-identity npm package is designed to provide AWS credentials to your application by leveraging web identity tokens. This is particularly useful for applications that authenticate users through federated identity providers such as Amazon Cognito, Facebook, Google, or any OpenID Connect (OIDC) compatible identity provider. It simplifies the process of assuming an AWS IAM role by using the web identity token, allowing your application to access AWS services securely.
Creating credentials from web identity tokens
This feature allows you to create AWS credentials by providing a web identity token, the ARN of the role to assume, and a session name. It's particularly useful for serverless applications that rely on federated authentication.
const { fromWebToken } = require('@aws-sdk/credential-provider-web-identity');
const credentials = fromWebToken({
roleArn: 'arn:aws:iam::123456789012:role/WebIdentityRole',
roleSessionName: 'web-identity-session',
webIdentityToken: process.env.WEB_IDENTITY_TOKEN
});