lambda-function-setup.ts - AWS Code Sample


/* Copyright, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 ABOUT THIS NODE.JS EXAMPLE: This example works with AWS SDK for JavaScript version 3 (v3), which is pending release. The preview version of the SDK is available at This example is in the 'AWS SDK for JavaScript v3 Developer Guide' at Purpose: lambda-function-setup.ts demonstrates how to create an Amazon Lambda function. Inputs (replace in code): - REGION - BUCKET_NAME - ZIP_FILE_NAME - IAM_ROLE_ARN Running the code: ts-node lambda-function-setup.ts */ // Load the Lambda client const { LambdaClient, CreateFunctionCommand } = require("@aws-sdk/client-lambda"); //Set the AWS Region const REGION = "REGION"; //e.g. "us-east-1" // Instantiate a Lambda client const lambda = new LambdaClient(REGION); //Set the parameters const params = { Code: { S3Bucket: "BUCKET_NAME", // BUCKET_NAME S3Key: "ZIP_FILE_NAME", // ZIP_FILE_NAME }, FunctionName: "slotpull", 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: "Slot machine game results generator", }; const run = async () => { try { const data = await lambda.send(new CreateFunctionCommand(params)); console.log("Success", data); // successful response } catch (err) { console.log("Error", err); // an error occurred } }; run();