Skip to content

jon-nona/api-gateway-proxy-example

Repository files navigation

Api Gateway Proxy Example

A CDK stack to demonstrate API gateway Proxy Integration (Lambda and HTTP)

It exposes two proxie'd Flickr endpoints (photos/recent and photos/search) which respond to GET requests, one proxied via a Lambda proxy integration at /photos/search which corresponds to flickr.photos.search which returns the response in JSON format, and flickr.photos.getRecent which does the same thing, just via an API gateway HTTP integration, with no lambda.

A basic custom lambda authorizer sits in front of the API Gateway. Api Keys etc are retrieved by cdk in The Construct and passed to the relevant Lambda's environment at deploy time.

Use Cases:

  • Lambda: You want to proxy a third party api endpoint, but perform some computation between request/response.
  • HTTP: You want to proxy a third party api endpoint, and control the responses, map the output.

Benefits of using HTTP over lambda are obviously not paying for lambda invocations, or dealing with cold starts.

Benefits of proxying third party API's through your own in this manner include say for React Native Not storing sensitive API keys in your app code.

Table of Contents

Setup

  1. go through all the Prerequisites in Prerequisites
  2. npm i install NPM dependencies

If you run into issues, see the additional docs below *_bottom of page

Development

Setting up the environment

Several commands will require a working AWS CLI setup, and also that you have valid AWS_PROFILE and AWS_DEFAULT_REGION environment variables set for the AWS account you will be using. Be sure to do this before continuing.

You should create an environment.json file from environment.json.tpl and add a valid Flickr api key.

Testing

We use Jest for testing. To run unit tests, you can use one of the following commands, to run once, run in watch mode, or to run all tests and generate converage reports.

npm run test
npm run test:watch
npm run test:coverage

Run Locally

npm run local

This will start a local web server on port 3000 and make the API available to you locally. Typescript code will automatically be recompiled when there are changes while the server is running. You will need to kill and restart this if you change cdk/api-gateway-proxy-example-stack.ts or package.json.

Deploying

There is one stack defined for production. This repo uses CDK to define these stacks. To deploy you can run:

npx cdk synth
npx cdk deploy ApiGatewayProxyExampleStack

Additional Docs

⬆ back to top

License

ISC © 2020 Jonathan Arnold [email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published