AWS — Different Ways to Trigger AWS Lambda Functions

Ashish Patel
Awesome Cloud
Published in
4 min readJul 3, 2023

AWS Lambda integration with other services — Understand AWS Lambda Invocations and Triggers.

Awesome Cloud — AWS Lambda Function Triggers

TL;DR:

AWS Lambda functions and triggers are the core components of building applications using AWS Lambda. Lambda integrates with other AWS services to invoke functions. Lambda function is the code and runtime that process events, while a trigger is the AWS service or application which generates events that invoke the function.

Depending on which service you’re using with Lambda, the invocation generally works in one of two ways. Event drives the invocation or Lambda polls a queue or data stream and invokes the function in response to activity in the queue or data stream. The event-driven invocation can be synchronous or asynchronous. Depending on how your function is invoked, scaling behavior and the types of errors that occur can vary.

Events are data structured in JSON format. The JSON structure varies depending on the service that generates it and the event type, but they all contain the data that the function needs to process the event. Lambda converts the event document into an object and passes it to the function handler.

Synchronous (Push-based) Invocations

For synchronous invocation, the service that generates the event waits for the function to process the event and returns a response when it’s finished. Many AWS services can emit events that trigger Lambda functions synchronously. Those services define the data that the function needs to return in the response. This is because the service that triggered the event sends response to a client or uses it to check if the event was handled successfully.

Synchronous invocations are the most straight forward way to invoke your Lambda functions. In this model, your functions execute immediately when you perform the Lambda Invoke API call. This can be accomplished through a variety of options such as CLI or SDKs.

The event-generating service controls the error strategy, such as whether to retry on errors. When you perform a synchronous invoke, you are responsible for checking the response and determining if there was an error and if you should retry the invoke.

The following is a list of AWS services that invoke Lambda functions synchronously:

Asynchronous (Event-based) Invocations

For asynchronous invocation, Lambda queues the events for processing before passing it to your function. When Lambda queues the event, it immediately sends a success response without additional information to the service that generated the event, and let Lambda handles the rest.

A separate process reads events from the queue and sends them to your function. After the function processes the event, Lambda doesn’t return a response to the event-generating service. These are simply fire-and-forget; the services that triggered the events don’t care if your Lambda function handled them correctly.

Lambda service manages the function’s asynchronous event queue. Lambda handles retries on errors and can send invocation records to a destination/ downstream resource such as Amazon SQS or Amazon EventBridge to chain together components of your application.

The following is a list of AWS services that invoke Lambda functions asynchronously:

Poll-based Invocations

This type of invocation model is designed to allow you to integrate with Stream and Queue based services with no code or server management. For poll-based (stream-based) event sources, AWS Lambda service polls the sources on your behalf, retrieve records, and then invokes the Lambda functions when records are detected on that sources.

When working with services that generate a queue or data stream, you create event source mappings in AWS Lambda. Lambda reads data items from the other service, creates an event, and invokes the function synchronously. You don’t need to grant Lambda permission to invoke the function, but it does need permission to read from the stream or queue.

The retry behavior for this model is based on data expiration in the data source.

The following are polling-based services:

Special Integration

Lambda provides special integration in a way that doesn’t involve invoking functions for below services.

Summary

AWS Lambda triggers are merely actions caused by specific AWS resources; These AWS services generate events that can invoke your Lambda function. Depending on the service, the event-driven invocation can be synchronous or asynchronous.

--

--

Ashish Patel
Awesome Cloud

Cloud Architect • 4x AWS Certified • 6x Azure Certified • 1x Kubernetes Certified • MCP • .NET • Terraform • DevOps • Blogger [https://bit.ly/iamashishpatel]