@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
168 lines • 7.87 kB
JavaScript
;
// *** 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.Invocation = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Manages an AWS Lambda Function invocation. Use this resource to invoke a Lambda function with the [RequestResponse](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax) invocation type.
*
* > **Note:** By default this resource _only_ invokes the function when the arguments call for a create or replace. After an initial invocation on _apply_, if the arguments do not change, a subsequent _apply_ does not invoke the function again. To dynamically invoke the function, see the `triggers` example below. To always invoke a function on each _apply_, see the `aws.lambda.Invocation` data source. To invoke the Lambda function when the Pulumi resource is updated and deleted, see the CRUD Lifecycle Management example below.
*
* > **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";
*
* // Lambda function to invoke
* const example = new aws.lambda.Function("example", {
* code: new pulumi.asset.FileArchive("function.zip"),
* name: "data_processor",
* role: lambdaRole.arn,
* handler: "index.handler",
* runtime: aws.lambda.Runtime.Python3d12,
* });
* // Invoke the function once during resource creation
* const exampleInvocation = new aws.lambda.Invocation("example", {
* functionName: example.name,
* input: JSON.stringify({
* operation: "initialize",
* config: {
* environment: "production",
* debug: false,
* },
* }),
* });
* export const initializationResult = std.jsondecodeOutput({
* input: exampleInvocation.result,
* }).apply(invoke => invoke.result?.status);
* ```
*
* ### Dynamic Invocation with Triggers
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
* import * as std from "@pulumi/std";
*
* const example = new aws.lambda.Invocation("example", {
* functionName: exampleAwsLambdaFunction.functionName,
* triggers: {
* function_version: exampleAwsLambdaFunction.version,
* config_hash: std.sha256Output({
* input: JSON.stringify({
* environment: environment,
* timestamp: std.timestamp({}).then(invoke => invoke.result),
* }),
* }).apply(invoke => invoke.result),
* },
* input: JSON.stringify({
* operation: "process_data",
* environment: environment,
* batch_id: batchId.result,
* }),
* });
* ```
*
* ### CRUD Lifecycle Management
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.lambda.Invocation("example", {
* functionName: exampleAwsLambdaFunction.functionName,
* input: JSON.stringify({
* resource_name: "database_setup",
* database_url: exampleAwsDbInstance.endpoint,
* credentials: {
* username: dbUsername,
* password: dbPassword,
* },
* }),
* lifecycleScope: "CRUD",
* });
* ```
*
* > **Note:** `lifecycleScope = "CRUD"` will inject a key `tf` in the input event to pass lifecycle information! This allows the Lambda function to handle different lifecycle transitions uniquely. If you need to use a key `tf` in your own input JSON, the default key name can be overridden with the `pulumiKey` argument.
*
* The lifecycle key gets added with subkeys:
*
* * `action` - Action Pulumi performs on the resource. Values are `create`, `update`, or `delete`.
* * `prevInput` - Input JSON payload from the previous invocation. This can be used to handle update and delete events.
*
* When the resource from the CRUD example above is created, the Lambda will receive the following JSON payload:
*
* If the `databaseUrl` changes, the Lambda will be invoked again with:
*
* When the invocation resource is removed, the final invocation will have:
*/
class Invocation extends pulumi.CustomResource {
/**
* Get an existing Invocation resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new Invocation(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of Invocation. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === Invocation.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["functionName"] = state?.functionName;
resourceInputs["input"] = state?.input;
resourceInputs["lifecycleScope"] = state?.lifecycleScope;
resourceInputs["qualifier"] = state?.qualifier;
resourceInputs["region"] = state?.region;
resourceInputs["result"] = state?.result;
resourceInputs["terraformKey"] = state?.terraformKey;
resourceInputs["triggers"] = state?.triggers;
}
else {
const args = argsOrState;
if (args?.functionName === undefined && !opts.urn) {
throw new Error("Missing required property 'functionName'");
}
if (args?.input === undefined && !opts.urn) {
throw new Error("Missing required property 'input'");
}
resourceInputs["functionName"] = args?.functionName;
resourceInputs["input"] = args?.input;
resourceInputs["lifecycleScope"] = args?.lifecycleScope;
resourceInputs["qualifier"] = args?.qualifier;
resourceInputs["region"] = args?.region;
resourceInputs["terraformKey"] = args?.terraformKey;
resourceInputs["triggers"] = args?.triggers;
resourceInputs["result"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(Invocation.__pulumiType, name, resourceInputs, opts);
}
}
exports.Invocation = Invocation;
/** @internal */
Invocation.__pulumiType = 'aws:lambda/invocation:Invocation';
//# sourceMappingURL=invocation.js.map