AWS Lambda integrates with other AWS 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 AWS 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 AWS Lambda with Amazon SQS.
- Run a function on a schedule. For more information, see Using AWS 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 AWS 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.
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 "AWS" prefix. You can also use your browser's search functionality to find your service in the list.
Service | Method of invocation |
---|---|
Amazon Alexa | Event-driven; synchronous invocation |
Amazon Managed Streaming for Apache Kafka | Lambda polling |
Self-managed Apache Kafka | Lambda polling |
Amazon API Gateway | Event-driven; synchronous invocation |
AWS CloudFormation | Event-driven; asynchronous invocation |
Amazon CloudFront (Lambda@Edge) | Event-driven; synchronous invocation |
Amazon EventBridge (CloudWatch Events) | Event-driven; asynchronous invocation |
Amazon CloudWatch Logs | Event-driven; asynchronous invocation |
AWS CodeCommit | Event-driven; asynchronous invocation |
AWS CodePipeline | Event-driven; asynchronous invocation |
Amazon Cognito | Event-driven; synchronous invocation |
AWS Config | Event-driven; asynchronous invocation |
Amazon Connect | Event-driven; synchronous invocation |
Amazon DynamoDB | Lambda polling |
Amazon Elastic File System | Special integration |
Elastic Load Balancing (Application Load Balancer) | Event-driven; synchronous invocation |
AWS IoT | Event-driven; asynchronous invocation |
AWS IoT Events | Event-driven; asynchronous invocation |
Amazon Kinesis | Lambda polling |
Amazon Kinesis Data Firehose | Event-driven; synchronous invocation |
Amazon Lex | Event-driven; synchronous invocation |
Amazon MQ | Lambda polling |
Amazon Simple Email Service | Event-driven; asynchronous invocation |
Amazon Simple Notification Service | Event-driven; asynchronous invocation |
Amazon Simple Queue Service | Lambda polling |
Amazon Simple Storage Service (Amazon S3) | Event-driven; asynchronous invocation |
Amazon Simple Storage Service Batch | Event-driven; synchronous invocation |
Secrets Manager | Event-driven; synchronous invocation |
AWS X-Ray | Special integration |
Some services generate events that can invoke your Lambda function. For more information about designing these types of architectures , see Event driven architectures in the Lambda operator guide.
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 AWS Lambda.
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.