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.
- go through all the Prerequisites in Prerequisites
npm i
install NPM dependencies
If you run into issues, see the additional docs below *_bottom of page
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.
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
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
.
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
ISC © 2020 Jonathan Arnold [email protected]