Using AWS Lambda with other services - AWS Lambda

Using AWS Lambda with other services

AWS Lambda integrates with other AWS services to invoke functions or take other actions. These are some common use cases:

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.

You can also use Lambda functions to interact programmatically with other AWS services using one of the AWS 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 AWS SDKs, see Tools to build on AWS.

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 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

Amazon VPC Lattice

Event-driven; synchronous invocation

AWS X-Ray

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 in Serverless Land.

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.

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.