UNPKG

@pulumi/aws

Version:

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

150 lines 6.81 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.getInvocationOutput = exports.getInvocation = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * Invokes an AWS Lambda Function and returns its results. Use this data source to execute Lambda functions during Pulumi operations and use their results in other resources or outputs. * * The Lambda function is invoked with [RequestResponse](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax) invocation type. * * > **Note:** The `aws.lambda.Invocation` data source invokes the function during the first `apply` and every subsequent `plan` when the function is known. * * > **Note:** If you get a `KMSAccessDeniedException: Lambda was unable to decrypt the environment variables because KMS access was denied` error when invoking a Lambda function with environment variables, the IAM role associated with the function may have been deleted and recreated after the function was created. You can fix the problem two ways: 1) updating the function's role to another role and then updating it back again to the recreated role. (When you create a function, Lambda grants permissions on the KMS key to the function's IAM role. If the IAM role is recreated, the grant is no longer valid. Changing the function's role or recreating the function causes Lambda to update the grant.) * * ## Example Usage * * ### Basic Invocation * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * const example = aws.lambda.getInvocation({ * functionName: exampleAwsLambdaFunction.functionName, * input: JSON.stringify({ * operation: "getStatus", * id: "123456", * }), * }); * export const result = example.then(example => std.jsondecode({ * input: example.result, * })).then(invoke => invoke.result); * ``` * * ### Dynamic Resource Configuration * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * // Get resource configuration from Lambda * const resourceConfig = aws.lambda.getInvocation({ * functionName: "resource-config-generator", * qualifier: "production", * input: JSON.stringify({ * environment: environment, * region: current.region, * service: "api", * }), * }); * const config = resourceConfig.then(resourceConfig => std.jsondecode({ * input: resourceConfig.result, * })).then(invoke => invoke.result); * // Use dynamic configuration * const example = new aws.elasticache.Cluster("example", { * clusterId: config?.cache?.clusterId, * engine: config?.cache?.engine, * nodeType: config?.cache?.nodeType, * numCacheNodes: config?.cache?.nodes, * parameterGroupName: config?.cache?.parameterGroup, * tags: config?.tags, * }); * ``` */ function getInvocation(args, opts) { opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {}); return pulumi.runtime.invoke("aws:lambda/getInvocation:getInvocation", { "functionName": args.functionName, "input": args.input, "qualifier": args.qualifier, "region": args.region, }, opts); } exports.getInvocation = getInvocation; /** * Invokes an AWS Lambda Function and returns its results. Use this data source to execute Lambda functions during Pulumi operations and use their results in other resources or outputs. * * The Lambda function is invoked with [RequestResponse](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax) invocation type. * * > **Note:** The `aws.lambda.Invocation` data source invokes the function during the first `apply` and every subsequent `plan` when the function is known. * * > **Note:** If you get a `KMSAccessDeniedException: Lambda was unable to decrypt the environment variables because KMS access was denied` error when invoking a Lambda function with environment variables, the IAM role associated with the function may have been deleted and recreated after the function was created. You can fix the problem two ways: 1) updating the function's role to another role and then updating it back again to the recreated role. (When you create a function, Lambda grants permissions on the KMS key to the function's IAM role. If the IAM role is recreated, the grant is no longer valid. Changing the function's role or recreating the function causes Lambda to update the grant.) * * ## Example Usage * * ### Basic Invocation * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * const example = aws.lambda.getInvocation({ * functionName: exampleAwsLambdaFunction.functionName, * input: JSON.stringify({ * operation: "getStatus", * id: "123456", * }), * }); * export const result = example.then(example => std.jsondecode({ * input: example.result, * })).then(invoke => invoke.result); * ``` * * ### Dynamic Resource Configuration * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * // Get resource configuration from Lambda * const resourceConfig = aws.lambda.getInvocation({ * functionName: "resource-config-generator", * qualifier: "production", * input: JSON.stringify({ * environment: environment, * region: current.region, * service: "api", * }), * }); * const config = resourceConfig.then(resourceConfig => std.jsondecode({ * input: resourceConfig.result, * })).then(invoke => invoke.result); * // Use dynamic configuration * const example = new aws.elasticache.Cluster("example", { * clusterId: config?.cache?.clusterId, * engine: config?.cache?.engine, * nodeType: config?.cache?.nodeType, * numCacheNodes: config?.cache?.nodes, * parameterGroupName: config?.cache?.parameterGroup, * tags: config?.tags, * }); * ``` */ function getInvocationOutput(args, opts) { opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {}); return pulumi.runtime.invokeOutput("aws:lambda/getInvocation:getInvocation", { "functionName": args.functionName, "input": args.input, "qualifier": args.qualifier, "region": args.region, }, opts); } exports.getInvocationOutput = getInvocationOutput; //# sourceMappingURL=getInvocation.js.map