🌜
🌞
@middy/sts

@middy/sts

v2.5.7

STS (Security Token Service) credentials middleware for the middy framework

npm install @middy/sts

README

Middy sts middleware

Middy logo

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

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) (optional): Options to pass to AWS.STS class constructor.
  • awsClientCapture (function) (optional): 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-2021 Luciano Mammino, will Farrell, and the Middy team.

FOSSA Status

Release Notes

2.5.7
By will Farrell • Published on January 25, 2022

Fix publishing transpiling error in 2.5.6. Thanks to @maximepichou and @rreubenreyes for reporting.

General

License
MIT
Typescript Types
Built-in
Tree-shakeable
No

Popularity

GitHub Stargazers
3,038
Community Interest
2,905
Number of Forks
293

Maintenance

Commits
11/2110/220250
Last Commit
Open Issues
5
Closed Issues
410
Open Pull Requests
1
Closed Pull Requests
149

Versions

Versions Released
11/2110/22010
Latest Version Released
Jan 25, 2022
Current Tags
latest2.5.7
next3.0.0-alpha.7

Dependencies

Dependencies (1)
Dev Dependencies (3)

Contributors

willfarrell
willfarrell
Commits: 384
lmammino
lmammino
Commits: 113
greenkeeper[bot]
greenkeeper[bot]
Commits: 12
vladgolubev
vladgolubev
Commits: 12
thejuan
thejuan
Commits: 12
dkatavic
dkatavic
Commits: 11
gsingh1
gsingh1
Commits: 10
joseSantacruz
joseSantacruz
Commits: 9
theburningmonk
theburningmonk
Commits: 6
leog
leog
Commits: 6
ossareh
ossareh
Commits: 5
JimiPedros
JimiPedros
Commits: 4
munierujp
munierujp
Commits: 4
sdomagala
sdomagala
Commits: 4
denovodavid
denovodavid
Commits: 3