@middy/sts
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.3 • Public • Published

    Middy sts middleware

    Middy logo

    STS middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

    npm version npm install size GitHub Actions CI status badge
    Standard Code Style Known Vulnerabilities Language grade: JavaScript Core Infrastructure Initiative (CII) Best Practices
    Chat on Gitter Ask questions on StackOverflow

    You can read the documentation at: https://middy.js.org/docs/middlewares/sts

    Fetches STS credentials to be used when connecting to other AWS services.

    Install

    To install this middleware you can use NPM:

    npm install --save @middy/sts

    Options

    • AwsClient (object) (default AWS.STS): AWS.STS class constructor (e.g. that has been instrumented with AWS XRay). Must be from aws-sdk v2.
    • awsClientOptions (object) (default undefined): Options to pass to AWS.STS class constructor.
    • awsClientCapture (function) (default undefined): Enable XRay by passing captureAWSClient from aws-xray-sdk in.
    • fetchData (object) (required): Mapping of internal key name to API request parameters.
    • disablePrefetch (boolean) (default false): On cold start requests will trigger early if they can. Setting awsClientAssumeRole disables prefetch.
    • cacheKey (string) (default sts): Cache key for the fetched data responses. Must be unique across all middleware.
    • cacheExpiry (number) (default -1): How long fetch data responses should be cached for. -1: cache forever, 0: never cache, n: cache for n ms.
    • setToContext (boolean) (default false): Store credentials to request.context.

    NOTES:

    • Lambda is required to have IAM permission for sts:AssumeRole
    • setToContext are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.

    Sample usage

    import middy from '@middy/core'
    import sts from '@middy/sts'
    
    const handler = middy((event, context) => {
      const response = {
        statusCode: 200,
        headers: {},
        body: JSON.stringify({ message: 'hello world' })
      };
    
      return response
    })
    
    handler
      .use(sts({
        fetchData: {
          assumeRole: {
            RoleArn: '...',
            RoleSessionName:'' // optional
          }
        }
      }))

    Middy documentation and examples

    For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.

    Contributing

    Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

    License

    Licensed under MIT License. Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the Middy team.

    FOSSA Status

    Install

    npm i @middy/sts

    Homepage

    middy.js.org

    DownloadsWeekly Downloads

    647

    Version

    3.0.3

    License

    MIT

    Unpacked Size

    11.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • lmammino
    • middyjs
    • willfarrell