Thursday, February 6, 2020

Using AWS lambda as a Proxy for any service



AWS Lambda


Amazon Web Services has a generous free tier for Lambda which involves 1 million free invocations.

With the release of HTTP API for API Gateway, you can use Lambda as a proxy for any service.

The source code is available here -> AWS Lambda Proxy using Nodejs

Why would you  use Lambda as a Proxy?

  1. Security - We don't want to expose the API end-point directly to the internet
  2. Resilience - If the external service goes down, we can use lambda to re-direct to an another instance of the API.

How to use AWS Lambda as a Proxy?

aws-lambda-proxy
AWS Lambda Proxy Architecture

  1.  You start by creating a new lambda function (we will call it the proxyJS). This will be the end-point where user submits the form. 
    api-gateway-trigger-aws-lambda
    API Gateway Trigger for Proxy Lambda (Click to enlarge)
  2.  Now we can call any external end-point. But in order to de-couple our architecture, we will use an AWS SNS topic that will get data from the Proxy lambda.
  3. sns-trigger-aws-lambda
    SNS Trigger for AWS Lambda



  4. This topic will be subscribed by another Lambda function called externalJS that will call an external service with the topic data
  5. In the above architecture, we are calling an external Google Cloud HTTP function using Nodejs using the above lambda



No comments:

Post a Comment

What do you think?.

© 2007-2020 DMCA.com Protection Status
The content is copyrighted to Sundeep Machado


Note: The author is not responsible for damages related to improper use of software, techniques, tips and copyright claims.