AWS API Gateway default response and Trigger AWS Lambda

℡╲_俬逩灬. 提交于 2019-12-06 14:04:28

Another asynchronous model many customers have used:

  1. Set up an API configured to send requests to Amazon Kinesis. This API could acknowledge the request.
  2. Set up AWS Lambda to consume your Kinesis stream.

This setup has some advantages for high workload APIs as fetches from the Kinesis stream can be batched and don't require a 1-to-1 scaling of both your API Gateway limits and Lambda limits.

Update

To answer your questions about scalability:

Kinesis

Kinesis scales by adding what it calls "shards" to the stream. Each shard handles a portion of your traffic, based on a partition key. Each shard scales up to 1000 rps or 1MBps (see limits). Even with the lower default 25 shards, this would support up to 25,000 rps or 25MBps with an evenly distributed partition key.

API Gateway

API Gateway has a default account level limit of 500 rps, but this can easily be extended by requesting a limit increase. We have customers in production that are using the service at limits above your current suggested scale.

If you want a fast response from the API and not have to wait for the processing of data, you could:

  • post an event to an API Gateway endpoint
  • trigger an AWS Lambda Function A
  • call asynchronously a Lambda Function B using the AWS SDK in the Lambda Function A
  • Call context.succeed() or context.done() or the callback function in the Lambda Function A so it respond back to API Gateway
  • the Lambda Function B can process the data while API Gateway already received a response
Mikelax

You should first run some tests to see what type of real world response times you are getting from having your lambda function complete all the logic. If the times are above what you feel are acceptable for your use case, here is another asynchronous solution utilizing an SNS Topic to trigger a secondary Lambda function.

  1. Client Request to API Gateway -> Calls Lambda function A
  2. Lambda A verifies payload and then publishes to SNS Topic X
  3. Lambda A returns {fine} success message -> API Gateway -> client
  4. SNS Topic X triggers Lambda function B
  5. Lambda function B implements given logic
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!