Deploy the Lambda function - AWS SDK for JavaScript

Help us improve the AWS SDK for JavaScript version 3 (V3) documentation by providing feedback using the Feedback link, or create an issue or pull request on GitHub.

The AWS SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the AWS SDK for JavaScript version 3 (V3).

Deploy the Lambda function

This topic is part of a tutorial that demonstrates how to invoke a Lambda function through Amazon API Gateway using the AWS SDK for JavaScript. To start at the beginning of the tutorial, see Invoking Lambda with API Gateway.

In the root of your project, create a lambda-function-setup.ts file, and paste the content below into it.

Replace BUCKET_NAME with the name of the Amazon S3 bucket you uploaded the ZIP version of your Lambda function to. Replace ZIP_FILE_NAME with the name of name the ZIP version of your Lambda function. Replace ROLE with the Amazon Resource Number (ARN) of the IAM role you created in the Create the AWS resources topic of this tutorial. Replace LAMBDA_FUNCTION_NAME with a name for the Lambda function.

// Load the required Lambda client and commands. const { CreateFunctionCommand } = require ( "@aws-sdk/client-lambda" ); const { lambdaClient} = require ( "./libs/lambdaClient.js ); // Set the parameters. const params = { Code: { S3Bucket: "BUCKET_NAME", // BUCKET_NAME S3Key: "ZIP_FILE_NAME", // ZIP_FILE_NAME }, FunctionName: "LAMBDA_FUNCTION_NAME", Handler: "index.handler", Role: "IAM_ROLE_ARN", // IAM_ROLE_ARN; e.g., arn:aws:iam::650138640062:role/v3-lambda-tutorial-lambda-role Runtime: "nodejs12.x", Description: "Scans a DynamoDB table of employee details and using Amazon Simple Notification Services (Amazon SNS) to " + "send employees an email the each anniversary of their start-date.", }; const run = async () => { try { const data = await lambdaClient.send(new CreateFunctionCommand(params)); console.log("Success", data); // successful response } catch (err) { console.log("Error", err); // an error occurred } }; run();

Enter the following at the command line to deploy the Lambda function.

node lambda-function-setup.ts

This code example is available here on GitHub.