DEV Community

Cover image for Different ways to invoke AWS Lambda Functions
Benjamin Ajewole for AWS Community Builders

Posted on

Different ways to invoke AWS Lambda Functions

AWS Lambda is a Serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. You can trigger Lambda from over 200 AWS services and software-as-a-service (SaaS) applications and only pay for what you use.

Check out my previous posts on how to create a Lambda function and deploy it the CI/CD way.

AWS Lambda can be invoked in several ways which include through the Lambda console, a function URL HTTP(S) endpoint, the Lambda API, Amazon API Gateway, an AWS SDK, the AWS Command Line Interface (AWS CLI), and AWS toolkits. You can also configure other AWS services to invoke your function, or you can configure Lambda to read from a stream or queue and invoke your function.

In this tutorial, we will be covering how to invoke using the Lambda console, function URL, AWS SDK and the AWS Command Line Interface (AWS CLI).

Invoking your Lambda function through the Lambda console

  • Go to the Lambda function
  • Click on Test
  • Input an Event Name and click on Invoke, this will invoke the function

Lambda Console

Invoking your Lambda function through the function URL

Function URLs are not supported in the following regions: Asia Pacific (Hyderabad) (ap-south-2), Asia Pacific (Melbourne) (ap-southeast-4), Europe (Spain) (eu-south-2), Europe (Zurich) (eu-central-2), Israel (Tel Aviv) (il-central-1), and Middle East (UAE) (me-central-1)

Follow these steps to create a function URL for your Lambda function

  • Go to the Lambda console
  • Click on the Configuration tab
  • Click on Function URL
  • Click on Create Function URL
  • Select None and click on Save
  • Open the link on your browser

Lambda Function URL

Invoking your Lambda function using AWS SDK

import {InvokeCommand, LambdaClient} from "@aws-sdk/client-lambda";

const client = new LambdaClient({
region: "eu-west-1"
});

client.send(new InvokeCommand({
  FunctionName: "helloWord"
}))
Enter fullscreen mode Exit fullscreen mode

Invoking your Lambda function using AWS CLI

# run this following commands

aws configure #configure aws cli

aws lambda invoke - function-name helloWorld response.json # invoke lambda function

cat response.json # read the response
Enter fullscreen mode Exit fullscreen mode

Happy coding!!

Top comments (0)