Using Amazon Lambda with other services
Amazon Lambda integrates with other Amazon services to invoke functions or take other actions. These are some common use cases:
-
Invoke a function in response to resource lifecycle events, such as with Amazon Simple Storage Service (Amazon S3). For more information, see Using Amazon Lambda with Amazon S3.
-
Respond to incoming HTTP requests. For more information, see Tutorial: Using Lambda with API Gateway.
-
Consume events from a queue. For more information, see Using Lambda with Amazon SQS.
-
Run a function on a schedule. For more information, see Using Amazon Lambda with Amazon EventBridge (CloudWatch Events).
Depending on which service you're using with Lambda, the invocation generally works in one of two ways. An 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. Lambda integrates with Amazon Elastic File System and Amazon X-Ray in a way that doesn't involve invoking functions.
For more information, see Event-driven invocation and Lambda polling. Or, look up the service that you want to work with in the following section to find a link to information about using that service with Lambda.
You can also use Lambda functions to interact programmatically with other Amazon Web Services using one of the Amazon Software Development Kits
(SDKs). For example, you can have a Lambda function create an Amazon S3 bucket or write data to a DynamoDB table using an API call from within your
function. To learn more about Amazon SDKs, see Tools to build on Amazon
Listing of services and links to more information
Find the service that you want to work with in the following table, to determine which method of invocation you should use. Follow the link from the service name to find information about how to set up the integration between the services. These topics also include example events that you can use to test your function.
Tip
Entries in this table are alphabetical by service name, excluding the "Amazon" or "Amazon" prefix. You can also use your browser's search functionality to find your service in the list.
Service | Method of invocation |
---|---|
Event-driven; synchronous invocation |
|
Lambda polling |
|
Lambda polling |
|
Event-driven; synchronous invocation |
|
Event-driven; asynchronous 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 |
|
Lambda polling |
|
Special integration |
|
Event-driven; synchronous invocation |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Lambda polling |
|
Event-driven; synchronous invocation |
|
Event-driven; synchronous invocation |
|
Lambda polling |
|
Event-driven; asynchronous invocation |
|
Event-driven; asynchronous invocation |
|
Lambda polling |
|
Event-driven; asynchronous invocation |
|
Event-driven; synchronous invocation |
|
Event-driven; synchronous invocation |
|
Event-driven; synchronous invocation |
|
Special integration |
Event-driven invocation
Some services generate events that can invoke your Lambda function. For more information about designing these
types of architectures , see
Event driven architectures
When you implement an event-driven architecture, you grant the event-generating service permission to invoke your function in the function's resource-based policy. Then you configure that service to generate events that invoke your function.
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.
Lambda converts the event document into an object and passes it to your function handler. For compiled languages, Lambda provides definitions for event types in a library. For more information, see the topic about building functions with your language: Building Lambda functions with C#, Building Lambda functions with Go, Building Lambda functions with Java, or Building Lambda functions with PowerShell.
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 more information, see Synchronous invocation.
-
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. For more information, see Asynchronous invocation.
For more information about how Lambda manages error handling for synchronously and asychronously invoked functions, see Error handling and automatic retries in Amazon Lambda.
Lambda polling
For services that generate a queue or data stream, you set up an event source mapping in Lambda to have Lambda poll the queue or a data stream.
When you implement a Lambda polling architecture, you grant Lambda permission to access the other service in the function's execution role. Lambda reads data from the other service, creates an event, and invokes your function.