Socket
Socket
Sign inDemoInstall

@aws-sdk/client-sts

Package Overview
Dependencies
136
Maintainers
5
Versions
364
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aws-sdk/client-sts

AWS SDK for JavaScript Sts Client for Node.js, Browser and React Native


Version published
Weekly downloads
20M
increased by4.66%
Maintainers
5
Install size
3.98 MB
Created
Weekly downloads
 

Package description

What is @aws-sdk/client-sts?

The @aws-sdk/client-sts package is a modular AWS SDK for JavaScript clients for AWS Security Token Service (STS). It allows developers to interact with the STS service, enabling them to request temporary, limited-privilege credentials for AWS Identity and Access Management (IAM) users or for users that you authenticate (federated users).

What are @aws-sdk/client-sts's main functionalities?

AssumeRole

AssumeRole allows you to request temporary security credentials for a role. This is useful for scenarios where you need to grant access to your AWS resources to users or systems without AWS accounts.

const { STSClient, AssumeRoleCommand } = require('@aws-sdk/client-sts');
const client = new STSClient({ region: 'us-west-2' });
const command = new AssumeRoleCommand({
  RoleArn: 'arn:aws:iam::123456789012:role/demo',
  RoleSessionName: 'session1'
});
client.send(command).then((response) => {
  console.log(response.Credentials);
});

GetSessionToken

GetSessionToken is used to retrieve a session token for use with AWS services. This is typically used when you have an IAM user and you want to create a temporary session with enhanced security, such as MFA.

const { STSClient, GetSessionTokenCommand } = require('@aws-sdk/client-sts');
const client = new STSClient({ region: 'us-west-2' });
const command = new GetSessionTokenCommand({
  DurationSeconds: 3600
});
client.send(command).then((response) => {
  console.log(response.Credentials);
});

AssumeRoleWithWebIdentity

AssumeRoleWithWebIdentity allows you to request temporary security credentials for users who have been authenticated in a mobile or web application with a web identity provider, such as Amazon Cognito, Login with Amazon, Facebook, Google, or any OpenID Connect-compatible identity provider.

const { STSClient, AssumeRoleWithWebIdentityCommand } = require('@aws-sdk/client-sts');
const client = new STSClient({ region: 'us-west-2' });
const command = new AssumeRoleWithWebIdentityCommand({
  RoleArn: 'arn:aws:iam::123456789012:role/demo',
  RoleSessionName: 'web-identity-session',
  WebIdentityToken: 'token'
});
client.send(command).then((response) => {
  console.log(response.Credentials);
});

Other packages similar to @aws-sdk/client-sts

Changelog

Source

3.454.0 (2023-11-17)

Bug Fixes

  • codegen: deserialize unions with list members (#5498) (69afef9)

Features

  • client-app-mesh: Change the default value of these fields from 0 to null: MaxConnections, MaxPendingRequests, MaxRequests, HealthCheckThreshold, PortNumber, and HealthCheckPolicy -> port. Users are not expected to perceive the change, except that badRequestException is thrown when required fields missing configured. (90a90eb)
  • client-athena: Adding SerivicePreProcessing time metric (6d0d449)
  • client-cloudformation: This release adds a new flag ImportExistingResources to CreateChangeSet. Specify this parameter on a CREATE- or UPDATE-type change set to import existing resources with custom names instead of recreating them. (9dd25ec)
  • client-codepipeline: CodePipeline now supports overriding source revisions to achieve manual re-deploy of a past revision (9239afa)
  • client-codestar-connections: This release adds support for the CloudFormation Git sync feature. Git sync enables updating a CloudFormation stack from a template stored in a Git repository. (ae3037b)
  • client-connect: This release adds WISDOM_QUICK_RESPONSES as new IntegrationType of Connect IntegrationAssociation resource and bug fixes. (b1c19ad)
  • client-ec2: This release adds new features for Amazon VPC IP Address Manager (IPAM) Allowing a choice between Free and Advanced Tiers, viewing public IP address insights across regions and in Amazon Cloudwatch, use IPAM to plan your subnet IPs within a VPC and bring your own autonomous system number to IPAM. (7a42bf1)
  • client-ecr: Documentation and operational updates for Amazon ECR, adding support for pull through cache rules for upstream registries that require authentication. (00d6cad)
  • client-emr: Launch support for IAM Identity Center Trusted Identity Propagation and workspace storage encryption using AWS KMS in EMR Studio (6cc6bdc)
  • client-eventbridge: Introduces a new rule state ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS for matching with Get, List and Describe AWS API call events from CloudTrail. (e581203)
  • client-internetmonitor: Adds new querying capabilities for running data queries on a monitor (33af400)
  • client-ivschat: type & defaulting refinement to various range properties (ceef825)
  • client-ivs: type & defaulting refinement to various range properties (fe08f6f)
  • client-location: Remove default value and allow nullable for request parameters having minimum value larger than zero. (1886fed)
  • client-medialive: MediaLive has now added support for per-output static image overlay. (02cc208)
  • client-mgn: Removed invalid and unnecessary default values. (e7efd42)
  • client-osis: Add support for enabling a persistent buffer when creating or updating an OpenSearch Ingestion pipeline. Add tags to Pipeline and PipelineSummary response models. (26fab56)
  • client-pipes: TargetParameters now properly supports BatchJobParameters.ArrayProperties.Size and BatchJobParameters.RetryStrategy.Attempts being optional, and EcsTaskParameters.Overrides.EphemeralStorage.SizeInGiB now properly required when setting EphemeralStorage (03b574e)
  • client-rds: This release adds support for option groups and replica enhancements to Amazon RDS Custom. (fb8ad1a)
  • client-redshift-serverless: Updated SDK for Amazon Redshift Serverless, which provides the ability to configure a connection with IAM Identity Center to manage user and group access to databases. (d293ea1)
  • client-redshift: Updated SDK for Amazon Redshift, which you can use to configure a connection with IAM Identity Center to manage access to databases. With these, you can create a connection through a managed application. You can also change a managed application, delete it, or get information about an existing one. (b806277)
  • client-s3: Removes all default 0 values for numbers and false values for booleans (61b32fe)
  • client-sso-admin: Improves support for configuring RefreshToken and TokenExchange grants on applications. (f53e68f)
  • client-sso-oidc: Adding support for sso-oauth:CreateTokenWithIAM. (313f046)
  • client-trustedadvisor: AWS Trusted Advisor introduces new APIs to enable you to programmatically access Trusted Advisor best practice checks, recommendations, and prioritized recommendations. Trusted Advisor APIs enable you to integrate Trusted Advisor with your operational tools to automate your workloads. (a1849c2)
  • client-verifiedpermissions: Adding BatchIsAuthorized API which supports multiple authorization requests against a PolicyStore (ec2e0d5)
  • client-wisdom: This release adds QuickResponse as a new Wisdom resource and Wisdom APIs for import, create, read, search, update and delete QuickResponse resources. (acf3ac4)
  • clients: update client endpoints as of 2023-11-17 (4d74018)

Readme

Source

@aws-sdk/client-sts

Description

AWS SDK for JavaScript STS Client for Node.js, Browser and React Native.

Security Token Service

Security Token Service (STS) enables you to request temporary, limited-privilege credentials for users. This guide provides descriptions of the STS API. For more information about using this service, see Temporary Security Credentials.

Installing

To install the this package, simply type add or install @aws-sdk/client-sts using your favorite package manager:

  • npm install @aws-sdk/client-sts
  • yarn add @aws-sdk/client-sts
  • pnpm add @aws-sdk/client-sts

Getting Started

Import

The AWS SDK is modulized by clients and commands. To send a request, you only need to import the STSClient and the commands you need, for example GetCallerIdentityCommand:

// ES5 example
const { STSClient, GetCallerIdentityCommand } = require("@aws-sdk/client-sts");
// ES6+ example
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";

Usage

To send a request, you:

  • Initiate client with configuration (e.g. credentials, region).
  • Initiate command with input parameters.
  • Call send operation on client with command object as input.
  • If you are using a custom http handler, you may call destroy() to close open connections.
// a client can be shared by different commands.
const client = new STSClient({ region: "REGION" });

const params = {
  /** input parameters */
};
const command = new GetCallerIdentityCommand(params);
Async/await

We recommend using await operator to wait for the promise returned by send operation as follows:

// async/await.
try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  // error handling.
} finally {
  // finally.
}

Async-await is clean, concise, intuitive, easy to debug and has better error handling as compared to using Promise chains or callbacks.

Promises

You can also use Promise chaining to execute send operation.

client.send(command).then(
  (data) => {
    // process data.
  },
  (error) => {
    // error handling.
  }
);

Promises can also be called using .catch() and .finally() as follows:

client
  .send(command)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  })
  .finally(() => {
    // finally.
  });
Callbacks

We do not recommend using callbacks because of callback hell, but they are supported by the send operation.

// callbacks.
client.send(command, (err, data) => {
  // process err and data.
});
v2 compatible style

The client can also send requests using v2 compatible style. However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post on modular packages in AWS SDK for JavaScript

import * as AWS from "@aws-sdk/client-sts";
const client = new AWS.STS({ region: "REGION" });

// async/await.
try {
  const data = await client.getCallerIdentity(params);
  // process data.
} catch (error) {
  // error handling.
}

// Promises.
client
  .getCallerIdentity(params)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  });

// callbacks.
client.getCallerIdentity(params, (err, data) => {
  // process err and data.
});

Troubleshooting

When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).

try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  const { requestId, cfId, extendedRequestId } = error.$metadata;
  console.log({ requestId, cfId, extendedRequestId });
  /**
   * The keys within exceptions are also parsed.
   * You can access them by specifying exception names:
   * if (error.name === 'SomeServiceException') {
   *     const value = error.specialKeyInException;
   * }
   */
}

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.

To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.

Contributing

This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-sts package is updated. To contribute to client you can check our generate clients scripts.

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.

Client Commands (Operations List)

AssumeRole

Command API Reference / Input / Output

AssumeRoleWithSAML

Command API Reference / Input / Output

AssumeRoleWithWebIdentity

Command API Reference / Input / Output

DecodeAuthorizationMessage

Command API Reference / Input / Output

GetAccessKeyInfo

Command API Reference / Input / Output

GetCallerIdentity

Command API Reference / Input / Output

GetFederationToken

Command API Reference / Input / Output

GetSessionToken

Command API Reference / Input / Output

FAQs

Last updated on 17 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc