Is it possible to remove API Gateway from the equation to serve Lambda over public internet?

Viewed 423

Currently, my application resides in lambda which I serve using HTTP API (API Gateway V2). This setup exists in multiple regions. Meaning, API Gateway invokes lambda in the same region which accesses DynamoDB Global Table in the same region. I use Route 53 to serve nearest API Gateway to user.

The problem I faced: API Gateway doesn't support redirection from http to https. I can achieve this with CloudFront. But, it'll increase cost as well as latency.

Can I remove API Gateway from the equation and use Lambda@Edge to access DynamoDB Table near the user? Can CloudFront be used to replace API Gateway?

1 Answers

Yes you can. The docs write:

Functions triggered by origin request and response events as well as functions triggered by viewer request and response events can make network calls to resources on the internet, and to AWS services such as Amazon S3 buckets, DynamoDB tables, or Amazon EC2 instances.

However, there are many limitations to what lambda@edge can do, as compared to a regular lambda. Examples are:

  • only python and nodejs,
  • difficulty in debugging, as lambda logs will be in region when it runs, not in one central region,
  • timeout limits on calls to DynamoDb (5 or 30 seconds) depending if its origin or viewer function,
  • no lambda layers
  • max memory of 128 MB for viewer side functions
  • deployment package size can be max 1 MB for viewer side functions

Thus if you can work with these and other limitations of lambda@edge, then you can use it to work with DynamoDb.

Related