UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

192 lines (191 loc) 6.87 kB
import * as pulumi from "@pulumi/pulumi"; /** * Provides a list of AWS Lambda Functions in the current region. Use this data source to discover existing Lambda functions for inventory, monitoring, or bulk operations. * * ## Example Usage * * ### List All Functions * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const all = aws.lambda.getFunctions({}); * export const functionCount = all.then(all => all.functionNames).length; * export const allFunctionNames = all.then(all => all.functionNames); * ``` * * ### Use Function List for Bulk Operations * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * // Get all Lambda functions * const all = aws.lambda.getFunctions({}); * // Create CloudWatch alarms for all functions * const lambdaErrors: aws.cloudwatch.MetricAlarm[] = []; * all.then(all => all.functionNames).length.apply(rangeBody => { * for (const range = {value: 0}; range.value < rangeBody; range.value++) { * lambdaErrors.push(new aws.cloudwatch.MetricAlarm(`lambda_errors-${range.value}`, { * name: all.then(all => `${all.functionNames[range.value]}-errors`), * comparisonOperator: "GreaterThanThreshold", * evaluationPeriods: 2, * metricName: "Errors", * namespace: "AWS/Lambda", * period: 300, * statistic: "Sum", * threshold: 5, * alarmDescription: "This metric monitors lambda errors", * dimensions: { * FunctionName: all.then(all => all.functionNames[range.value]), * }, * tags: { * Environment: "monitoring", * Purpose: "lambda-error-tracking", * }, * })); * } * }); * ``` * * ### Create Function Inventory * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * export = async () => { * const all = await aws.lambda.getFunctions({}); * // Get detailed information for each function * const details = .map(__index => (await aws.lambda.getFunction({ * functionName: all.functionNames[__index], * }))); * const functionInventory = .map(([i, name]) => ({ * name: name, * arn: all.functionArns[i], * runtime: details.apply(details => details[i].runtime), * memorySize: details.apply(details => details[i].memorySize), * timeout: details.apply(details => details[i].timeout), * handler: details.apply(details => details[i].handler), * })); * return { * functionInventory: functionInventory, * }; * } * ``` */ export declare function getFunctions(args?: GetFunctionsArgs, opts?: pulumi.InvokeOptions): Promise<GetFunctionsResult>; /** * A collection of arguments for invoking getFunctions. */ export interface GetFunctionsArgs { /** * Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration. */ region?: string; } /** * A collection of values returned by getFunctions. */ export interface GetFunctionsResult { /** * List of Lambda Function ARNs. */ readonly functionArns: string[]; /** * List of Lambda Function names. */ readonly functionNames: string[]; /** * The provider-assigned unique ID for this managed resource. */ readonly id: string; readonly region: string; } /** * Provides a list of AWS Lambda Functions in the current region. Use this data source to discover existing Lambda functions for inventory, monitoring, or bulk operations. * * ## Example Usage * * ### List All Functions * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const all = aws.lambda.getFunctions({}); * export const functionCount = all.then(all => all.functionNames).length; * export const allFunctionNames = all.then(all => all.functionNames); * ``` * * ### Use Function List for Bulk Operations * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * // Get all Lambda functions * const all = aws.lambda.getFunctions({}); * // Create CloudWatch alarms for all functions * const lambdaErrors: aws.cloudwatch.MetricAlarm[] = []; * all.then(all => all.functionNames).length.apply(rangeBody => { * for (const range = {value: 0}; range.value < rangeBody; range.value++) { * lambdaErrors.push(new aws.cloudwatch.MetricAlarm(`lambda_errors-${range.value}`, { * name: all.then(all => `${all.functionNames[range.value]}-errors`), * comparisonOperator: "GreaterThanThreshold", * evaluationPeriods: 2, * metricName: "Errors", * namespace: "AWS/Lambda", * period: 300, * statistic: "Sum", * threshold: 5, * alarmDescription: "This metric monitors lambda errors", * dimensions: { * FunctionName: all.then(all => all.functionNames[range.value]), * }, * tags: { * Environment: "monitoring", * Purpose: "lambda-error-tracking", * }, * })); * } * }); * ``` * * ### Create Function Inventory * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * export = async () => { * const all = await aws.lambda.getFunctions({}); * // Get detailed information for each function * const details = .map(__index => (await aws.lambda.getFunction({ * functionName: all.functionNames[__index], * }))); * const functionInventory = .map(([i, name]) => ({ * name: name, * arn: all.functionArns[i], * runtime: details.apply(details => details[i].runtime), * memorySize: details.apply(details => details[i].memorySize), * timeout: details.apply(details => details[i].timeout), * handler: details.apply(details => details[i].handler), * })); * return { * functionInventory: functionInventory, * }; * } * ``` */ export declare function getFunctionsOutput(args?: GetFunctionsOutputArgs, opts?: pulumi.InvokeOutputOptions): pulumi.Output<GetFunctionsResult>; /** * A collection of arguments for invoking getFunctions. */ export interface GetFunctionsOutputArgs { /** * Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration. */ region?: pulumi.Input<string>; }