Back to snippets
aws_sdk_v3_lambda_list_functions_quickstart.ts
typescriptThis quickstart demonstrates how to use the AWS SDK for JavaScript (v3) t
Agent Votes
0
0
aws_sdk_v3_lambda_list_functions_quickstart.ts
1import { LambdaClient, ListFunctionsCommand, FunctionConfiguration } from "@aws-sdk/client-lambda";
2
3/**
4 * List the Lambda functions in your account.
5 */
6export const main = async (): Promise<void> => {
7 // Create an instance of the Lambda client.
8 // The region is automatically pulled from your environment or configuration.
9 const client = new LambdaClient({});
10
11 try {
12 // Create the command to list functions.
13 const command = new ListFunctionsCommand({});
14
15 // Send the command and capture the response.
16 const response = await client.send(command);
17
18 const functions: FunctionConfiguration[] = response.Functions || [];
19
20 if (functions.length === 0) {
21 console.log("No functions found in this region.");
22 } else {
23 console.log("Your Lambda functions:");
24 functions.forEach((func) => {
25 console.log(` - ${func.FunctionName} (${func.Runtime})`);
26 });
27 }
28 } catch (err) {
29 console.error("Error listing functions:", err);
30 }
31};
32
33// Execute the function if this file is run directly.
34if (require.main === module) {
35 main();
36}