Overview: serverless.yml

I once again used Serverless Framework to put everything together, but this time I’ve added the Serverless Step Functions plugin to make life easier.

Step Function: everyminute

Let me give you something better to look at instead of YAML. This is a screenshot from AWS’ recently released “Step Functions Workflow Studio”.

Function: interval

I’ve removed the SQS event trigger and the reserved concurrency, but the code is unchanged; it still simply logs its input and the current time.

How accurate is it?

EventBridge

The results in my previous post show that EventBridge rules appear to trigger on the same second of every minute, give or take ~500 milliseconds.

Step Functions

The Wait state offers second-level accuracy and the AWS console shows it waits for exactly 10,000 milliseconds. State transitions take ~10ms.

The raw invocation times are on GitHub.

Cost

Lambda & SQS

I didn’t actually publish the cost of the other solution, so let’s look at it now.

  • everyminute sending messages to SQS +
  • Lambda polling SQS for interval.

Step Functions

As Jeremy said in his tweet, using an Express Step Functions is the cheapest option. The Express pricing model charges $0.000001 for each execution and $0.00001667 per GB-second its running.

Enhancements

The most interesting enhancement is one Jeremy already pointed out: Express Step Functions can run for up to 5 minutes. That means you could change the EventBridge rule to trigger every 5 minutes instead of every minute. The Step Function would then invoke the Lambda function 30 times instead of 6 times.

  • Running the Step Function right up to the 5 minute limit seems risky. It is hard to reason about the Wait states, transition times, and Lambda service response times to make sure it all fits.
  • Due to transition times and Lambda service response times, I think that the longer the Step Function runs, the more the invocation times would move around. I like the reset given by starting a new execution.

Conclusion

This solution is great! Sure, it costs 6.5 times more, but it’s on a small enough scale that I suspect the extra $2.33 isn’t going to break the bank. If you wanted to invoke your function even more often, the price gap would close very slightly.

Principal Engineer @ Just Eat Takeaway.com | AWS Community Builder