Invoking Lambda with events from other AWS services
Some AWS services can directly invoke Lambda functions using triggers. These services push events to Lambda, and the function is invoked immediately when the specified event occurs. Triggers are suitable for discrete events and real-time processing. When you create a trigger using the Lambda console, the console interacts with the corresponding AWS service to configure the event notification on that service. The trigger is actually stored and managed by the service that generates the events, not by Lambda.
The 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.
A function can have multiple triggers. Each trigger acts as a client invoking your function independently, and each event that Lambda passes to your function has data from only one trigger. Lambda converts the event document into an object and passes it to your function handler.
Depending on the service, the event-driven invocation can be synchronous or asynchronous.
-
For synchronous invocation, the service that generates the event waits for the response from your function. That service defines the data that the function needs to return in the response. The service controls the error strategy, such as whether to retry on errors.
-
For asynchronous invocation, Lambda queues the event before passing it to your function. When Lambda queues the event, it immediately sends a success response to the service that generated the event. After the function processes the event, Lambda doesn’t return a response to the event-generating service.
Creating a trigger
The easiest way to create a trigger is to use the Lambda console. When you create a trigger using the console, Lambda automatically adds the required permissions to the function's resource-based policy.
To create a trigger using the Lambda console
-
Open the Functions page
of the Lambda console. -
Select the function you want to create a trigger for.
-
In the Function overview pane, choose Add trigger.
-
Select the AWS service you want to invoke your function.
-
Fill out the options in the Trigger configuration pane and choose Add. Depending on the AWS service you choose to invoke your function, the trigger configuration options will be different.
Services that can invoke Lambda functions
The following table lists services that can invoke Lambda functions.
Service | Method of invocation |
---|---|
Event-driven; synchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; synchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; synchronous invocation |
|
Special integration |
|
Event-driven; synchronous invocation |
|
Event-driven; asynchronous invocation (event buses), synchronous or asynchronous invocation (pipes and schedules) |
|
Event-driven; asynchronous invocation |
|
Event-driven; synchronous invocation |
|
Event-driven; synchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; synchronous invocation |
|
Special integration |
|
Event-driven; synchronous or asynchronous invocation |
|
Event-driven; synchronous invocation |
|
Special integration |