Invocation Args
Use this resource to invoke a lambda function. The lambda function is invoked with the RequestResponse invocation type.
NOTE: By default this resource only invokes the function when the arguments call for a create or replace. In other words, 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 theaws.lambda.Invocation
data source. To invoke the lambda function when the Pulumi resource is updated and deleted, see the CRUD Lifecycle Scope example below. NOTE: If you get aKMSAccessDeniedException: Lambda was unable to decrypt the environment variables because KMS access was denied
error when invoking anaws.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, or 2) by using Pulumi totaint
the function andapply
your configuration again to recreate the function. (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
Dynamic Invocation Example Using Triggers
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lambda.Invocation;
import com.pulumi.aws.lambda.InvocationArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Invocation("example", InvocationArgs.builder()
.functionName(aws_lambda_function.lambda_function_test().function_name())
.triggers(Map.of("redeployment", computeSHA1(serializeJson(
jsonArray(aws_lambda_function.example().environment())))))
.input(serializeJson(
jsonObject(
jsonProperty("key1", "value1"),
jsonProperty("key2", "value2")
)))
.build());
}
}
CRUD Lifecycle Scope
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lambda.Invocation;
import com.pulumi.aws.lambda.InvocationArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Invocation("example", InvocationArgs.builder()
.functionName(aws_lambda_function.lambda_function_test().function_name())
.input(serializeJson(
jsonObject(
jsonProperty("key1", "value1"),
jsonProperty("key2", "value2")
)))
.lifecycleScope("CRUD")
.build());
}
}
Constructors
Functions
Properties
Lifecycle scope of the resource to manage. Valid values are CREATE_ONLY
and CRUD
. Defaults to CREATE_ONLY
. CREATE_ONLY
will invoke the function only on creation or replacement. CRUD
will invoke the function on each lifecycle event, and augment the input JSON payload with additional lifecycle information.