Frequently asked questions - AWS Lambda

Frequently asked questions

Is it better to have one Lambda function containing all functionality or many Lambda functions?

In many cases, separating functionality into different functions can provide better performance and also make an application more maintainable and scalable. However, Lambda “monoliths” may be a useful stepping stone in migrating an existing application.

How much functionality should a single Lambda function contain?

The function should perform a single task in the flow of data across AWS services in your microservice. However, if the functional task is too small, this may incur additional latency in the application and overhead in managing large numbers of functions. The exact scope of a function is determined by the use case.

Can Lambda-based applications work in multiple Regions?

Yes, many serverless services provide replication and support for multiple Regions, including DynamoDB and S3. Lambda functions can be deployed in multiple Regions as part of a deployment pipeline, and API Gateway can be configured to support this configuration. See this example architecture that shows how this can be achieved.

Can Lambda functions run on a timed schedule?

Yes, you can use scheduled expressions for rules in EventBridge to trigger a Lambda function. This format uses cron syntax and can be set with a one-minute granularity. See this tutorial for an example.

How can a Lambda function retain state between invocations?

In many cases, a DynamoDB table is an ideal way to retain since it provides low-latency data access and can scale with the Lambda service. You can also store data in Amazon EFS for Lambda if you are using this service, and this provides low-latency access to file system storage.

What types of workloads are suited to event-driven architectures?

Event-driven architectures communicate across different systems using networks, which introduce variable latency. For workloads that require very low latency, such as real-time trading systems, this design may not be the best choice. However, for highly scalable and available workloads, or those with unpredictable traffic patterns, event-driven architectures can provide an effective way to meet these demands.

Why does the Lambda service have a 15-minute limit for functions?

Lambda functions exist to process events and most events are processed very quickly – typically, under 1 second for the majority of production invocations. The duration of a function is determined by the time taken to process one event. While there are some compute-intensive workloads that can take several minutes, very few require 15 minutes to complete.

If you find that you need a longer duration, ensure that your function code is processing single events, performing single tasks, and using the best practices outlined in this document. In many cases, functions can be redesigned to process single events and reduce the amount of time needed to process.