npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-gateway-request-signer

v2.1.1

Published

Sign requests to IAM authorized API Gateway APIs

Downloads

55

Readme

API Gateway Request Signer

Build Status Maintainability npm version FOSSA Status

Sign requests to IAM authorized API Gateway APIs

Usage

First, create an instance of the client

import ApiGatewaySigner from "api-gateway-request-signer";

const apiSigner = new ApiGatewaySigner({
  endpoint: "https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/STAGE",
  region: "us-east-1"
});

Now, when you want to make a call to the api, create a signed request

const request = apiSigner.signRequest({
  method: HttpMethods.GET,
  path: `/path/to/some/resource`
});

Finally you're ready to actually make the request.

const result = await axios.get(request.url, { headers: request.headers });

Making Requests with Exponential Backoff

The ApiGatewaySigner has a convenience method called makeRequestWithRetries. Simply provide it with the same parameters as signRequest and a callback and it will take care of automatically retrying requests.

const data = await apiSigner.makeRequestWithRetries(
  {
    method: HttpMethods.GET,
    path: `/path/to/some/resource`
  },
  request => axios.get(request.url, { headers: request.headers }),
  3 // Number of times to retry the request
);

The method calls your callback with the signed request. If the callback throws an exception, then it is called again after a short delay.

The last parameter is optional, and it determines the number of times to retry the request. By default it's set to 5.

Credentials

To sign your request the library requires a set of credentials. You can provide these credentials as part of the initial config, or in environment variables.

Configuration

You can specify the credentials to sign requests with by passing them into the constructor using the accessKey, secretKey, and sessionToken config parameters.

const apiSigner = new ApiGatewaySigner({
  endpoint: "https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/STAGE",
  region: "us-east-1",

  accessKey: "SOME_KEY",
  secretKey: "SECRET",
  sessionToken: "SESSION_TOKEN"
});

Environment Variables

If values aren't provided in the constructor, the values of the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables will be used. These values will be populated by default in a lambda runtime environment.

See Lambda Environment Variables for more information.

License

FOSSA Status