Invoking Lambda functions - AWS Lambda

Invoking Lambda functions

After you deploy your Lambda function, you can invoke it in several ways:

All of these methods are direct ways to invoke your function. In Lambda, a common use case is to invoke your function based on an event that occurs elsewhere in your application. For example, Amazon Simple Queue Service (Amazon SQS) can invoke your function when a queue receives a message. For more information on these types of invocations, see Invoking Lambda functions from another AWS service.

When you invoke a function, you can choose to invoke it synchronously or asynchronously. With synchronous invocation, you wait for the function to process the event and return a response. With asynchronous invocation, Lambda queues the event for processing and returns a response immediately. The InvocationType request parameter in the Invoke API determines how Lambda invokes your function. A value of RequestResponse indicates synchronous invocation, and a value of Event indicates asynchronous invocation.

If the function invocation results in an error, for synchronous invocations, view the error message in the response and retry the invocation manually. For asynchronous invocations, Lambda handles retries automatically and can send invocation records to a destination.

Invoking Lambda functions from another AWS service

To invoke your function from another AWS service, create a trigger. A trigger is a resource you configure to allow other AWS services to invoke your function when certain events or conditions occur. 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.

Create triggers using the Lambda console. If you're using the AWS Serverless Application Model (AWS SAM), you can also configure a trigger using the Events property in the AWS::Serverless::Function resource.

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.

For a full list of the AWS services that can invoke your Lambda function by using a trigger, and for more information about configuring triggers for different services, see Using Lambda with other services.

A subset of triggers use streams or queues to hold events before sending them to your Lambda function. To configure these triggers to invoke your function, you need to create an event source mapping. An event source mapping is a resource that reads items from a stream or queue and creates events containing batches of items to send to your Lambda function. Each event can contain hundreds or thousands of items.

The following integrations require an event source mapping for invocation: