Invocation
Use this resource to invoke a lambda function. The lambda function is invoked with the RequestResponse invocation type.
NOTE: This resource only invokes the function when the arguments call for a create or update. 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. 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());
}
}