Since you need to run Lambda from the browser, you have two options you can achieve it.

  1. Use AWS Javascript SDK, set it up with user via static configuration or Cognito with IAM Permissions to your Lambda. You can also consider subscribing your Lambda functions to SNS Topic and run the Lambda by sending a message to the topic. This SNS approach would also require you to store and retrieve the submission state via separate call.

  2. Use AWS API Gateway to create RESTful endpoint with proper CORS configuration that you can ping from the browser using AJAX.

Both options have their pros and cons. More information about your use-case would be necessary to properly evaluate which one suits you best.

Answer from adamkonrad on Stack Overflow
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › define lambda function handler in node.js
Define Lambda function handler in Node.js - AWS Lambda
Set up your projectExample ... environment variablesUsing global stateBest practices · The Lambda function handler is the method in your function code that processes events....
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js
Building Lambda functions with Node.js - AWS Lambda
It relays any logs that your function outputs during invocation. If your function returns an error, Lambda formats the error and returns it to the invoker. ... All supported Lambda Node.js runtimes include a specific minor version of the AWS SDK for JavaScript v3, not the latest version
Discussions

Need example of calling AWS Lambda from JavaScript - Stack Overflow
Just need an example of how to call AWS Lambda from JavaScript running in a browser and display function result in JavaScript console. Incredibly, I cannot find any examples on Google or from AWS More on stackoverflow.com
🌐 stackoverflow.com
Why would I use Node.js in Lambda? Node main feature is handling concurrent many requests. If each request to lambda will spawn a new Node instance, whats the point?
That’s not really unique to Node. The majority of languages and web app platforms have concurrency mechanisms that will process multiple requests simultaneously. That is certainly a drawback of Lambda if you’re looking at raw CPU cycle efficiency and your application spends a lot of time waiting on synchronous downstream calls, but in most cases that doesn’t really matter. In practice, there are a lot of apps that can either use really fast data stores like Dynamo or use asynchronous processing models that minimize the amount of idle CPU time for a given request. Also, even with some inefficiencies when looking at high concurrency time periods, sometimes the ability for Lambda to immediately scale down during troughs in your load pattern makes up for it when looking at the global efficiency of the system (especially when you consider other operational overhead like patching servers.) Bottom line, people use Node with Lambda because they like the language and are familiar with it. Using the same language for the front end browser code and the backend is nice for teams that build full stack web apps. More on reddit.com
🌐 r/aws
82
56
February 8, 2020
Finding an AWS JavaScript Lambda module regardless of whether the lambda is hot or cold

../src/common

Remember that these are Unix file paths.

Also, if possible, minify your JS/TS before deployment.

More on reddit.com
🌐 r/aws
3
0
March 12, 2023
Invoking a lambda function from the Javascript SDK vs API Gateway?

I think API gateway, you can set it up to function exactly like a normal back end service. Define an endpoint signature, handle authentication, and use any http client you want.

More on reddit.com
🌐 r/aws
3
1
November 13, 2019
🌐
AWS
docs.aws.amazon.com › aws sdk for javascript › developer guide for sdk version 3 › work with aws services in the sdk for javascript › sdk for javascript code examples › aws lambda examples
AWS Lambda examples - AWS SDK for JavaScript
The JavaScript API for AWS Lambda is exposed through the LambdaService client class. Here are a list of examples that demonstrate how to create and use Lambda functions with the AWS SDK for JavaScript v3:
Top answer
1 of 5
12

Since you need to run Lambda from the browser, you have two options you can achieve it.

  1. Use AWS Javascript SDK, set it up with user via static configuration or Cognito with IAM Permissions to your Lambda. You can also consider subscribing your Lambda functions to SNS Topic and run the Lambda by sending a message to the topic. This SNS approach would also require you to store and retrieve the submission state via separate call.

  2. Use AWS API Gateway to create RESTful endpoint with proper CORS configuration that you can ping from the browser using AJAX.

Both options have their pros and cons. More information about your use-case would be necessary to properly evaluate which one suits you best.

2 of 5
10

I see people have used AWS SDK for Javascript but it is not required specially since you need to create Amazon Cognito identity pool with access enabled for unauthenticated identities (Atleast for beginners like me). Below code works fine for me -

<html>
    <head>
<script>
    function callAwsLambdaFunction() {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("myDiv").innerHTML = this.responseText;
            }
        };
        xhttp.open("GET", "https://test123.ap-south-1.amazonaws.com/dev", true);
        xhttp.send();

    }
    </script>   
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello world!</h1>
        <h1>Click below button to call API gatway and display result below!</h1>
        <h1><div id="myDiv"></div></h1>
        <button onclick="callAwsLambdaFunction()">Click me!</button><br>
        Regards,<br/>
        Aniket
    </body>
</html>

Above is sample index.html that I have added to my S3 bucket and made a static site. Couple of points to note -

  1. Make your index.html open from outside if you are using S3 for static site hosting.
  2. Make sure you turn on CORS for your API gateway if your website domain is not same as API gateway domain. Else you might get -

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://test123.ap-south-1.amazonaws.com/dev. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

🌐
AWS
docs.aws.amazon.com › javascript sdk › developer guide for sdk v2 › tutorials › tutorial: creating and using lambda functions
Tutorial: Creating and Using Lambda Functions - AWS SDK for JavaScript
The AWS SDK for JavaScript version 3 (v3) is a rewrite of v2 with some great new features, including modular architecture. For more information, see the AWS SDK for JavaScript v3 Developer Guide. ... Create AWS Lambda functions in Node.js and call them from JavaScript running in a web browser.
🌐
Medium
medium.com › hackernoon › getting-started-with-aws-lambda-and-node-js-4ce3259c6dfd
Getting Started with AWS Lambda and Node.js | by Adnan Rahić | HackerNoon.com | Medium
August 16, 2018 - Little did I know what AWS Lambda was, and how incredibly awesome it is. If you’re intrigued, stick around. I’ll only take a few minutes out of your already busy day, and you surely won’t mind. Function as a Service — Defining the architecture behind AWS Lambda.
🌐
Gideon Pyzer
gideonpyzer.dev › blog › 2017 › 02 › 05 › create-an-aws-lambda-function-in-javascript
Create an AWS Lambda Function in JavaScript - Gideon Pyzer
February 5, 2017 - It is now possible to write the lambda function in the ‘Lambda function code’ section. However, I don’t recommend it. It’s not a great way to write code, because it’s not easy to test. It’s also not good if you need to import node libraries, like we’ll need to do. Instead, open up your preferred text editor or IDE and run npm init. The handler is what gets executed by AWS.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › devops › aws-lambda-function-handler-in-nodejs
AWS Lambda Function Handler in Node.js - GeeksforGeeks
July 23, 2025 - That is, the main function that AWS Lambda executes when it invokes an event for a function that is configured to process such an event. The handler processes the event data and returns a response. In Node.js, this is a JavaScript function defined in your code.
🌐
AWS
docs.aws.amazon.com › aws sdk for javascript › developer guide for sdk version 3 › sdk for javascript (v3) code examples › lambda examples using sdk for javascript (v3)
Lambda examples using SDK for JavaScript (v3) - AWS SDK for JavaScript
Shows how to create an Amazon EventBridge scheduled event that invokes an AWS Lambda function. Configure EventBridge to use a cron expression to schedule when the Lambda function is invoked. In this example, you create a Lambda function by using the Lambda JavaScript runtime API.
🌐
AWS
docs.aws.amazon.com › javascript sdk › developer guide for sdk v2 › tutorials › tutorial: creating and using lambda functions › run the lambda function
Run the Lambda Function - AWS SDK for JavaScript
For more information, see the AWS SDK for JavaScript v3 Developer Guide. In this task, you run the application. Open a web browser. Open the index.html in the Amazon S3 bucket that hosts the application. To do this, go open the Amazon S3 bucket in the AWS console, select the bucket, and choose Open. Select the handle on the right side of the slot machine. The wheels begin to spin as the browser script invokes the Lambda function ...
🌐
AWS
docs.aws.amazon.com › AWSJavaScriptSDK › latest › AWS › Lambda.html
Class: AWS.Lambda — AWS SDK for JavaScript
For additional details and information on how to migrate, please refer to the announcement. ... Constructs a service interface object. Each API operation is exposed as a function on service. ... Lambda is a compute service that lets you run code without provisioning or managing servers.
🌐
Reddit
reddit.com › r/aws › why would i use node.js in lambda? node main feature is handling concurrent many requests. if each request to lambda will spawn a new node instance, whats the point?
r/aws on Reddit: Why would I use Node.js in Lambda? Node main feature is handling concurrent many requests. If each request to lambda will spawn a new Node instance, whats the point?
February 8, 2020 -

Maybe I'm missing something here, from an architectural point of view, I can't wrap my head on using node inside a lambda. Let's say I receive 3 requests, a single node instance would be able to handle this with ease, but if I use lambda, 3 lambdas with Node inside would be spawned, each would be idle while waiting for the callback.

Edit: Many very good answers. I will for sure discuss this with the team next week. Very happy with this community. Thanks and please keep them coming!

Top answer
1 of 27
29
That’s not really unique to Node. The majority of languages and web app platforms have concurrency mechanisms that will process multiple requests simultaneously. That is certainly a drawback of Lambda if you’re looking at raw CPU cycle efficiency and your application spends a lot of time waiting on synchronous downstream calls, but in most cases that doesn’t really matter. In practice, there are a lot of apps that can either use really fast data stores like Dynamo or use asynchronous processing models that minimize the amount of idle CPU time for a given request. Also, even with some inefficiencies when looking at high concurrency time periods, sometimes the ability for Lambda to immediately scale down during troughs in your load pattern makes up for it when looking at the global efficiency of the system (especially when you consider other operational overhead like patching servers.) Bottom line, people use Node with Lambda because they like the language and are familiar with it. Using the same language for the front end browser code and the backend is nice for teams that build full stack web apps.
2 of 27
12
> if I use lambda, 3 lambdas with Node inside would be spawned, each would be idle while waiting for the callback This is true of any other language, though. You could have three instances of a program written in Assembly waiting for data to return. > I can't wrap my head on using node inside a lambda The reasons to adopt Node over other platforms are varied, and not necessarily technical arguments. Node has fast startup times compared with .Net or Java. AWS themselves recommend Node in use-cases where cold-start latency matters; eg. web handlers. Most business applications are IO-bound. It doesn't matter which language you pick if you're sat waiting for data to return over the network. Javascript is easy to hire for - it's a lingua franca that most engineers have some skill with Modern front-end frameworks often support server-side rendering, which makes a single language attractive across the entire stack. As a result of the above, JS is the default option for Lambda, which means the best tooling and libraries are written for JS, compounding the advantages and mind-share. Architecture isn't really about making the best technical choice, it's about making the right _business_ decision in a technical context so that your choices support one another.
🌐
Medium
medium.com › @wwdhfernando › introduction-to-aws-lambda-and-a-simple-javascript-example-6002940471fe
Introduction to AWS Lambda and a Simple JavaScript Example | by Dilshan Fernando | Medium
January 16, 2025 - Response: The function performs its task and optionally returns a response to the triggering service. Let’s create a simple AWS Lambda function that processes a JSON payload and returns a greeting message.
🌐
AWS
aws.amazon.com › blogs › compute › node-js-24-runtime-now-available-in-aws-lambda
Node.js 24 runtime now available in AWS Lambda | Amazon Web Services
November 25, 2025 - You can develop Node.js 24 Lambda functions using the AWS Management Console, AWS Command Line Interface (AWS CLI), AWS SDK for JavaScript, AWS Serverless Application Model (AWS SAM), AWS Cloud Development Kit (AWS CDK), and other infrastructure as code tools.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with typescript
Building Lambda functions with TypeScript - AWS Lambda
You can use the Node.js runtime to run TypeScript code in AWS Lambda. Because Node.js doesn't run TypeScript code natively, you must first transpile your TypeScript code into JavaScript. Then, use the JavaScript files to deploy your function code to Lambda. Your code runs in an environment that includes the AWS SDK for JavaScript, with credentials from an AWS Identity and Access Management (IAM) role that you manage.
🌐
AWS
docs.aws.amazon.com › aws sdk code examples › code library › code examples by sdk using aws sdks › code examples for sdk for javascript (v2) › lambda examples using sdk for javascript (v2)
Lambda examples using SDK for JavaScript (v2) - AWS SDK Code Examples
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for JavaScript (v2) with Lambda. Scenarios are code examples that show you how to accomplish specific tasks by calling multiple functions within a service or combined with other AWS ...
🌐
Aws-otel
aws-otel.github.io › docs › getting-started › lambda › lambda-js
AWS Distro for OpenTelemetry Lambda Support For JavaScript | AWS Distro for OpenTelemetry
The AWS managed Lambda layer for ADOT JavaScript provides a plug and play user experience by automatically instrumenting a Lambda function, by packaging OpenTelemetry JavaScript together with an out-of-the-box configuration for AWS Lambda and AWS X-Ray.
🌐
Pulumi
pulumi.com › home › guides › how-to guides › create aws lambda functions from javascript callbacks
Create AWS Lambda Functions from JavaScript Callbacks | Pulumi Guides
1 month ago - The aws:lambda/callbackFunction:CallbackFunction resource, part of the Pulumi AWS provider, creates Lambda functions directly from JavaScript code, automatically packaging dependencies and managing deployment.
🌐
AWS
docs.aws.amazon.com › aws sdk for javascript › developer guide for sdk version 3 › work with aws services in the sdk for javascript › sdk for javascript code examples › invoking lambda with api gateway
Invoking Lambda with API Gateway - AWS SDK for JavaScript
AWS Lambda is a compute service that enables you to run code without provisioning or managing servers. You can create Lambda functions in various programming languages. For more information about AWS Lambda, see What is AWS Lambda. In this example, you create a Lambda function by using the ...
🌐
Pegasus One
pegasusone.com › home › how to use aws lambda function in node.js
How to Use AWS Lambda Function in Node.js - Pegasus One
February 6, 2026 - How do you use an AWS Lambda function in Node.js? You use an AWS Lambda function in Node.js by writing your function handler in JavaScript or TypeScript, wp_title()