Socket
Socket
Sign inDemoInstall

@aws-sdk/client-lambda

Package Overview
Dependencies
145
Maintainers
5
Versions
377
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aws-sdk/client-lambda

AWS SDK for JavaScript Lambda Client for Node.js, Browser and React Native


Version published
Weekly downloads
2.4M
decreased by-7.62%
Maintainers
5
Created
Weekly downloads
 

Package description

What is @aws-sdk/client-lambda?

The @aws-sdk/client-lambda package is a client library for AWS Lambda that allows developers to interact with the AWS Lambda service programmatically. It provides methods to create, update, delete, and invoke Lambda functions, as well as manage function configurations, aliases, and versions.

What are @aws-sdk/client-lambda's main functionalities?

Invoke a Lambda function

This feature allows you to invoke an AWS Lambda function with optional payload. The response includes the result of the function execution.

{"const { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda');
const client = new LambdaClient({ region: 'us-west-2' });
const params = {
  FunctionName: 'my-lambda-function',
  Payload: Buffer.from(JSON.stringify({ key: 'value' }))
};
const command = new InvokeCommand(params);
client.send(command).then((response) => {
  console.log(response);
}).catch((error) => {
  console.error(error);
});"}

Create a Lambda function

This feature allows you to create a new AWS Lambda function by specifying the code, function name, handler, role, and runtime.

{"const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda');
const client = new LambdaClient({ region: 'us-west-2' });
const params = {
  Code: { /* code properties */ },
  FunctionName: 'my-new-function',
  Handler: 'index.handler',
  Role: 'arn:aws:iam::123456789012:role/lambda-role',
  Runtime: 'nodejs12.x'
};
const command = new CreateFunctionCommand(params);
client.send(command).then((response) => {
  console.log(response);
}).catch((error) => {
  console.error(error);
});"}

List Lambda functions

This feature allows you to list all of your AWS Lambda functions in a specific region.

{"const { LambdaClient, ListFunctionsCommand } = require('@aws-sdk/client-lambda');
const client = new LambdaClient({ region: 'us-west-2' });
const command = new ListFunctionsCommand({});
client.send(command).then((response) => {
  console.log(response.Functions);
}).catch((error) => {
  console.error(error);
});"}

Other packages similar to @aws-sdk/client-lambda

Changelog

Source

3.569.0 (2024-05-03)

Bug Fixes

  • clients: add deps required by default credential providers (#6055) (bfa8626)

Features

  • client-bedrock-agent: This release adds support for using Provisioned Throughput with Bedrock Agents. (7c1d339)
  • client-connectcases: This feature supports the release of Files related items (89b45ab)
  • client-connect: This release adds 5 new APIs for managing attachments: StartAttachedFileUpload, CompleteAttachedFileUpload, GetAttachedFile, BatchGetAttachedFileMetadata, DeleteAttachedFile. These APIs can be used to programmatically upload and download attachments to Connect resources, like cases. (1cbc8f9)
  • client-inspector2: This release adds CSV format to GetCisScanReport for Inspector v2 (79fb03b)
  • client-sagemaker: Amazon SageMaker Inference now supports m6i, c6i, r6i, m7i, c7i, r7i and g5 instance types for Batch Transform Jobs (c97f84a)
  • client-sesv2: Adds support for specifying replacement headers per BulkEmailEntry in SendBulkEmail in SESv2. (9dac593)
  • clients: update client endpoints as of 2024-05-03 (ca804cd)

Readme

Source

@aws-sdk/client-lambda

Description

AWS SDK for JavaScript Lambda Client for Node.js, Browser and React Native.

Lambda

Overview

Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging. With Lambda, you can run code for virtually any type of application or backend service. For more information about the Lambda service, see What is Lambda in the Lambda Developer Guide.

The Lambda API Reference provides information about each of the API methods, including details about the parameters in each API request and response.

You can use Software Development Kits (SDKs), Integrated Development Environment (IDE) Toolkits, and command line tools to access the API. For installation instructions, see Tools for Amazon Web Services.

For a list of Region-specific endpoints that Lambda supports, see Lambda endpoints and quotas in the Amazon Web Services General Reference..

When making the API calls, you will need to authenticate your request by providing a signature. Lambda supports signature version 4. For more information, see Signature Version 4 signing process in the Amazon Web Services General Reference..

CA certificates

Because Amazon Web Services SDKs use the CA certificates from your computer, changes to the certificates on the Amazon Web Services servers can cause connection failures when you attempt to use an SDK. You can prevent these failures by keeping your computer's CA certificates and operating system up-to-date. If you encounter this issue in a corporate environment and do not manage your own computer, you might need to ask an administrator to assist with the update process. The following list shows minimum operating system and Java versions:

  • Microsoft Windows versions that have updates from January 2005 or later installed contain at least one of the required CAs in their trust list.

  • Mac OS X 10.4 with Java for Mac OS X 10.4 Release 5 (February 2007), Mac OS X 10.5 (October 2007), and later versions contain at least one of the required CAs in their trust list.

  • Red Hat Enterprise Linux 5 (March 2007), 6, and 7 and CentOS 5, 6, and 7 all contain at least one of the required CAs in their default trusted CA list.

  • Java 1.4.2_12 (May 2006), 5 Update 2 (March 2005), and all later versions, including Java 6 (December 2006), 7, and 8, contain at least one of the required CAs in their default trusted CA list.

When accessing the Lambda management console or Lambda API endpoints, whether through browsers or programmatically, you will need to ensure your client machines support any of the following CAs:

  • Amazon Root CA 1

  • Starfield Services Root Certificate Authority - G2

  • Starfield Class 2 Certification Authority

Root certificates from the first two authorities are available from Amazon trust services, but keeping your computer up-to-date is the more straightforward solution. To learn more about ACM-provided certificates, see Amazon Web Services Certificate Manager FAQs.

Installing

To install the this package, simply type add or install @aws-sdk/client-lambda using your favorite package manager:

  • npm install @aws-sdk/client-lambda
  • yarn add @aws-sdk/client-lambda
  • pnpm add @aws-sdk/client-lambda

Getting Started

Import

The AWS SDK is modulized by clients and commands. To send a request, you only need to import the LambdaClient and the commands you need, for example ListLayersCommand:

// ES5 example
const { LambdaClient, ListLayersCommand } = require("@aws-sdk/client-lambda");
// ES6+ example
import { LambdaClient, ListLayersCommand } from "@aws-sdk/client-lambda";

Usage

To send a request, you:

  • Initiate client with configuration (e.g. credentials, region).
  • Initiate command with input parameters.
  • Call send operation on client with command object as input.
  • If you are using a custom http handler, you may call destroy() to close open connections.
// a client can be shared by different commands.
const client = new LambdaClient({ region: "REGION" });

const params = {
  /** input parameters */
};
const command = new ListLayersCommand(params);
Async/await

We recommend using await operator to wait for the promise returned by send operation as follows:

// async/await.
try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  // error handling.
} finally {
  // finally.
}

Async-await is clean, concise, intuitive, easy to debug and has better error handling as compared to using Promise chains or callbacks.

Promises

You can also use Promise chaining to execute send operation.

client.send(command).then(
  (data) => {
    // process data.
  },
  (error) => {
    // error handling.
  }
);

Promises can also be called using .catch() and .finally() as follows:

client
  .send(command)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  })
  .finally(() => {
    // finally.
  });
Callbacks

We do not recommend using callbacks because of callback hell, but they are supported by the send operation.

// callbacks.
client.send(command, (err, data) => {
  // process err and data.
});
v2 compatible style

The client can also send requests using v2 compatible style. However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post on modular packages in AWS SDK for JavaScript

import * as AWS from "@aws-sdk/client-lambda";
const client = new AWS.Lambda({ region: "REGION" });

// async/await.
try {
  const data = await client.listLayers(params);
  // process data.
} catch (error) {
  // error handling.
}

// Promises.
client
  .listLayers(params)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  });

// callbacks.
client.listLayers(params, (err, data) => {
  // process err and data.
});

Troubleshooting

When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).

try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  const { requestId, cfId, extendedRequestId } = error.$metadata;
  console.log({ requestId, cfId, extendedRequestId });
  /**
   * The keys within exceptions are also parsed.
   * You can access them by specifying exception names:
   * if (error.name === 'SomeServiceException') {
   *     const value = error.specialKeyInException;
   * }
   */
}

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.

To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.

Contributing

This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-lambda package is updated. To contribute to client you can check our generate clients scripts.

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.

Client Commands (Operations List)

AddLayerVersionPermission

Command API Reference / Input / Output

AddPermission

Command API Reference / Input / Output

CreateAlias

Command API Reference / Input / Output

CreateCodeSigningConfig

Command API Reference / Input / Output

CreateEventSourceMapping

Command API Reference / Input / Output

CreateFunction

Command API Reference / Input / Output

CreateFunctionUrlConfig

Command API Reference / Input / Output

DeleteAlias

Command API Reference / Input / Output

DeleteCodeSigningConfig

Command API Reference / Input / Output

DeleteEventSourceMapping

Command API Reference / Input / Output

DeleteFunction

Command API Reference / Input / Output

DeleteFunctionCodeSigningConfig

Command API Reference / Input / Output

DeleteFunctionConcurrency

Command API Reference / Input / Output

DeleteFunctionEventInvokeConfig

Command API Reference / Input / Output

DeleteFunctionUrlConfig

Command API Reference / Input / Output

DeleteLayerVersion

Command API Reference / Input / Output

DeleteProvisionedConcurrencyConfig

Command API Reference / Input / Output

GetAccountSettings

Command API Reference / Input / Output

GetAlias

Command API Reference / Input / Output

GetCodeSigningConfig

Command API Reference / Input / Output

GetEventSourceMapping

Command API Reference / Input / Output

GetFunction

Command API Reference / Input / Output

GetFunctionCodeSigningConfig

Command API Reference / Input / Output

GetFunctionConcurrency

Command API Reference / Input / Output

GetFunctionConfiguration

Command API Reference / Input / Output

GetFunctionEventInvokeConfig

Command API Reference / Input / Output

GetFunctionUrlConfig

Command API Reference / Input / Output

GetLayerVersion

Command API Reference / Input / Output

GetLayerVersionByArn

Command API Reference / Input / Output

GetLayerVersionPolicy

Command API Reference / Input / Output

GetPolicy

Command API Reference / Input / Output

GetProvisionedConcurrencyConfig

Command API Reference / Input / Output

GetRuntimeManagementConfig

Command API Reference / Input / Output

Invoke

Command API Reference / Input / Output

InvokeAsync

Command API Reference / Input / Output

InvokeWithResponseStream

Command API Reference / Input / Output

ListAliases

Command API Reference / Input / Output

ListCodeSigningConfigs

Command API Reference / Input / Output

ListEventSourceMappings

Command API Reference / Input / Output

ListFunctionEventInvokeConfigs

Command API Reference / Input / Output

ListFunctions

Command API Reference / Input / Output

ListFunctionsByCodeSigningConfig

Command API Reference / Input / Output

ListFunctionUrlConfigs

Command API Reference / Input / Output

ListLayers

Command API Reference / Input / Output

ListLayerVersions

Command API Reference / Input / Output

ListProvisionedConcurrencyConfigs

Command API Reference / Input / Output

ListTags

Command API Reference / Input / Output

ListVersionsByFunction

Command API Reference / Input / Output

PublishLayerVersion

Command API Reference / Input / Output

PublishVersion

Command API Reference / Input / Output

PutFunctionCodeSigningConfig

Command API Reference / Input / Output

PutFunctionConcurrency

Command API Reference / Input / Output

PutFunctionEventInvokeConfig

Command API Reference / Input / Output

PutProvisionedConcurrencyConfig

Command API Reference / Input / Output

PutRuntimeManagementConfig

Command API Reference / Input / Output

RemoveLayerVersionPermission

Command API Reference / Input / Output

RemovePermission

Command API Reference / Input / Output

TagResource

Command API Reference / Input / Output

UntagResource

Command API Reference / Input / Output

UpdateAlias

Command API Reference / Input / Output

UpdateCodeSigningConfig

Command API Reference / Input / Output

UpdateEventSourceMapping

Command API Reference / Input / Output

UpdateFunctionCode

Command API Reference / Input / Output

UpdateFunctionConfiguration

Command API Reference / Input / Output

UpdateFunctionEventInvokeConfig

Command API Reference / Input / Output

UpdateFunctionUrlConfig

Command API Reference / Input / Output

FAQs

Last updated on 03 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc