Home > Software engineering >  Adding time delay in Step Functions vs Lambda
Adding time delay in Step Functions vs Lambda

Time:11-15

I need to write some endpoint that simulate the response of third party server to run performance test regularly. I have decided to go with API Gateway to Step Function (waits 2 seconds) to Lambda that returns response based on the request. This needs to be done to emulate latency of 2 seconds on third party service. The question is what would be the cheapest solution to solve the task using these services.

Should I go only with Lambda alone (no Step Functions and even API Gateway)? If I use only Lambda we would need many concurrent Lambdas each running for 2 seconds. What is the cheapest solution?

CodePudding user response:

When working with AWS services and trying to work out pricing, you should use the AWS Price Calculator. Each service also has pricing breakdowns:

Here's a quick work-up I did:

Service Price Request/day Notes
Lambda $32/mo 10k 5 second runtime
Step Function $76/mo 10k n/a

From these numbers, the most cost effective solution would be to remove the Step Functions from the orchestration and just go with Lambdas.

A nice addition of using Lambdas are the ability to pass in a parameter to specify the 3rd party end-point latency. Or even a range or latency, i.e., random delay between 1 second and 3 seconds.

You can review this estimate here.

CodePudding user response:

Consider a SQS Delay Queue in front of the Lambda to simulate the 2 second latency. The first million SQS messages are always free each month, the next million cost $0.40.

Your Lambdas will execute without any artificial delay, reducing your compute cost by (more than?) half.

  • Related