Function or functionless?

In addition to facilitating the integration between your Lambda functions, managed services can entirely replace a Lambda function in some scenarios. Indeed, as dis‐ cussed in “The Functionless Integration Pattern” on page 236, a growing trend among serverless engineers is to only use Lambda functions to perform tasks when absolutely necessary and instead leverage various managed services to delegate work to AWS.

Writing and deploying a Lambda function comes with an obvious labor cost. The function’s code must be tested, operated, and maintained for as long as it is in use. Of course, there will always be valid use cases for leveraging Lambda functions in your architecture, but it’s important to consider whether a native service integration can be used instead.

Let’s consider some common tasks and compare the utilization of Lambda functions and managed services:

Event data enrichment

As events flow through your system you will inevitably need to transform and enrich their payloads with additional fields. Managed services such as Step Func‐ tions (via input and output processing) and EventBridge (via input transforma‐ tion) support static data operations using JSONPath. JSONPath operations can be considered static as they can only use the data provided as input and cannot generate new values, such as timestamps or calculated values. For dynamic data enrichment, you may be able to utilize Step Functions intrinsic functions or implement custom business logic in a Lambda function as part of your event processing pipeline.

Event communication and routing

Using Lambda functions to transport data is usually unnecessary. In the vast majority of cases you should rely on a managed service, such as Amazon Event‐ Bridge, SNS, Kinesis, or SQS, to transmit messages between producers and con‐ sumers and trigger activity in your serverless application. As Ajay Nair, General Manager for AWS Lambda, once said: “Use Lambda functions to transform, not transport.”

Event batching

Many managed services support some form of batching or buffering, including Amazon Kinesis and SQS. Using a managed service should generally be preferred over implementing your own batch mechanism.

HTTP requests

When making network requests to third-party APIs, you can use the Step Func‐ tions HTTP task or EventBridge API destinations (as described in Chapter 5) if you do not need to handle the response.

Intensive compute

When you need to coordinate large-scale parallel data processing you can use a Step Functions map (for up to 40 parallel executions) or distributed map (for up to 10,000 parallel executions) to invoke a single Lambda function concurrently, rather than managing the map in the function itself.

Leave a Reply

Your email address will not be published. Required fields are marked *