• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple CLI to test API Gateway endpoints with IAM authorization

AWS API Gateway Test CLI NPM Version

A simple CLI to test API Gateway endpoints with IAM authorization. Uses the AWS SDK, AWS Cognito JS SDK, and the generic API Gateway Client. Using the login information given, this tool logs a user into the Cognito User Pool, gets the temporary IAM credentials, and makes the API request. It can be difficult to do these steps by hand without scripting them.

Installation

To install globally run the following:

$ npm install -g aws-api-gateway-cli-test

You can also use it locally using:

$ npx aws-api-gateway-cli-test

Usage

If you have it globally installed:

$ apig-test \
  --username='johndoe' \
  --password='password' \
  --user-pool-id='us-east-1_Xxxxxxxx' \
  --app-client-id='29xxyyxxyxxxyyxxxyy' \
  --cognito-region='us-east-1' \
  --identity-pool-id='us-east-1:99xxyyx-9999-9999-xx0x-99xxxxxxxx' \
  --invoke-url='https://99xxxxxxx.execute-api.us-east-1.amazonaws.com' \
  --api-gateway-region='us-east-1' \
  --api-key='x3xaacea33DCDA3aqafae28aCdaeEWXX1ada3acx' \
  --path-template='/users' \
  --method='GET' \
  --params='{}' \
  --additional-params='{}' \
  --access-token-header='cognito-access-token' \
  --body='{}'

If you have it locally installed:

$ npx aws-api-gateway-cli-test --options

This command takes the following options:

  • username The username of the Cognito User Pool user.

  • password The password of the Cognito User Pool user.

  • user-pool-id The Cognito User Pool Id.

  • app-client-id The Cognito User Pool App Client Id.

  • cognito-region The Cognito User Pool region. Defaults to us-east-1.

  • identity-pool-id The Cognito Identity Pool Id.

  • invoke-url The API Gateway root endpoint.

  • api-gateway-region The API Gateway region. Defaults to us-east-1.

  • api-key The API key if required by the method. Defaults to none.

  • path-template The path template of the API.

  • method The API method. Defaults to GET.

  • params The API path params as a JSON string. Defaults to '{}'.

  • additional-params Any additional params (including the headers and querystring) as a JSON string. Defaults to '{}'.

  • access-token-header Header field on which to pass the access token.

  • body The request body as a JSON string. Defaults to '{}'. Alternatively, reference a file with a JSON string using --body='@mocks/create.json' where mocks/create.json is the file with the request body.

For additional documentation on the format for params and additional-params; refer to the generic API Gateway Client docs.

Examples

To pass in path parameters with your request.

$ npx aws-api-gateway-cli-test \
--username='[email protected]' \
--password='password' \
--user-pool-id='abc' \
--app-client-id='def' \
--cognito-region='us-east-1' \
--identity-pool-id='ghi' \
--invoke-url='https://123.execute-api.us-east-1.amazonaws.com/prod' \
--api-gateway-region='us-east-1' \
--path-template='/notes/{id}' \
--params='{"id":"456"}' \
--method='GET'

To pass in query parameters and headers with your request.

$ npx aws-api-gateway-cli-test \
--username='[email protected]' \
--password='password' \
--user-pool-id='abc' \
--app-client-id='def' \
--cognito-region='us-east-1' \
--identity-pool-id='ghi' \
--invoke-url='https://123.execute-api.us-east-1.amazonaws.com/prod' \
--api-gateway-region='us-east-1' \
--path-template='/notes' \
--additional-params='{"queryParams":{"param0":"abc"},"headers":{"param1":"123"}}' \
--method='GET'

Local Development

Clone the repo and initialize the project.

$ git clone https://github.com/AnomalyInnovations/aws-api-gateway-cli-test
$ cd aws-api-gateway-cli-test
$ npm install

Test the command using node index.js.

To install the apig-test command, run the following:

$ npm link

More Repositories

1

serverless-nodejs-starter

A Node.js starter for Serverless Framework with ES6 and TypeScript support
JavaScript
755
star
2

serverless-stack-demo-client

Source for the demo app client in the Serverless Stack Guide
JavaScript
636
star
3

serverless-bundle

Optimized packages for ES6 and TypeScript Node.js Lambda functions without any configuration.
JavaScript
531
star
4

serverless-stack-demo-api

Source for the demo app API in the Serverless Stack Guide
JavaScript
517
star
5

serverless-stack-demo-ext-api

Source for the extended version of the demo app API in Serverless Stack.
JavaScript
92
star
6

serverless-lerna-yarn-starter

A Serverless monorepo starter that uses Lerna and Yarn Workspaces.
JavaScript
83
star
7

serverless-typescript-starter

A Serverless starter that adds TypeScript, serverless-offline, linting, environment variables, and unit test support.
TypeScript
80
star
8

serverless-stack-demo-mono-api

A sample mono-repo multi-service Serverless application with AWS CloudFormation cross-stack references.
JavaScript
52
star
9

serverless-stack-demo-user-mgmt-client

Source for demo app client with user management in Serverless-Stack.com
JavaScript
41
star
10

serverless-stack-demo-ext-resources

Source for the extended version of the demo app resources in Serverless Stack.
JavaScript
40
star
11

serverless-python-starter

Python starter project for Serverless Framework
Python
37
star
12

serverless-stack-demo-fb-login-client

Source for the Facebook login demo app client in Serverless-Stack.com
JavaScript
31
star
13

sigV4Client

A standalone client for signing API Gateway requests for Signature Version 4
JavaScript
17
star
14

toolbeam-cli

CLI for Toolbeam
JavaScript
16
star
15

toolbeam-example-api

A simple API for the Toolbeam examples
JavaScript
4
star
16

serverless-cd-demo-a1c8

A demo Serverless Projects deployed using Seed
JavaScript
2
star