Deploy the Lambda function - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

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

Starting October 1, 2022, Amazon SDK for JavaScript (v3) will end support for Internet Explorer 11 (IE 11). For details, see Announcing the end of support for Internet Explorer 11 in the Amazon SDK for JavaScript (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 Amazon 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 Amazon 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.