Invoking Lambda with events from other AWS services - AWS Lambda

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
  1. Open the Functions page of the Lambda console.

  2. Select the function you want to create a trigger for.

  3. In the Function overview pane, choose Add trigger.

  4. Select the AWS service you want to invoke your function.

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

The following table lists services that can invoke Lambda functions.

Service Method of invocation

Amazon Alexa

Event-driven; synchronous invocation

Amazon Managed Streaming for Apache Kafka

Event source mapping

Self-managed Apache Kafka

Event source mapping

Amazon API Gateway

Event-driven; synchronous invocation

AWS CloudFormation

Event-driven; asynchronous invocation

Amazon CloudFront (Lambda@Edge)

Event-driven; synchronous 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

Event source mapping

Amazon Elastic File System

Special integration

Elastic Load Balancing (Application Load Balancer)

Event-driven; synchronous invocation

AWS IoT

Event-driven; asynchronous invocation

Amazon Kinesis

Event source mapping

Amazon Data Firehose

Event-driven; synchronous invocation

Amazon Lex

Event-driven; synchronous invocation

Amazon MQ

Event source mapping

Amazon Simple Email Service

Event-driven; asynchronous invocation

Amazon Simple Notification Service

Event-driven; asynchronous invocation

Amazon Simple Queue Service

Event source mapping

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