aws.lambda.Invocation
Explore with Pulumi AI
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 a
KMSAccessDeniedException: 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
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: lambdaFunctionTest.functionName,
triggers: {
redeployment: std.sha1({
input: JSON.stringify([exampleAwsLambdaFunction.environment]),
}).then(invoke => invoke.result),
},
input: JSON.stringify({
key1: "value1",
key2: "value2",
}),
});
import pulumi
import json
import pulumi_aws as aws
import pulumi_std as std
example = aws.lambda_.Invocation("example",
function_name=lambda_function_test["functionName"],
triggers={
"redeployment": std.sha1(input=json.dumps([example_aws_lambda_function["environment"]])).result,
},
input=json.dumps({
"key1": "value1",
"key2": "value2",
}))
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
tmpJSON0, err := json.Marshal([]interface{}{
exampleAwsLambdaFunction.Environment,
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
invokeSha1, err := std.Sha1(ctx, &std.Sha1Args{
Input: json0,
}, nil)
if err != nil {
return err
}
tmpJSON1, err := json.Marshal(map[string]interface{}{
"key1": "value1",
"key2": "value2",
})
if err != nil {
return err
}
json1 := string(tmpJSON1)
_, err = lambda.NewInvocation(ctx, "example", &lambda.InvocationArgs{
FunctionName: pulumi.Any(lambdaFunctionTest.FunctionName),
Triggers: pulumi.StringMap{
"redeployment": pulumi.String(invokeSha1.Result),
},
Input: pulumi.String(json1),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var example = new Aws.Lambda.Invocation("example", new()
{
FunctionName = lambdaFunctionTest.FunctionName,
Triggers =
{
{ "redeployment", Std.Sha1.Invoke(new()
{
Input = JsonSerializer.Serialize(new[]
{
exampleAwsLambdaFunction.Environment,
}),
}).Apply(invoke => invoke.Result) },
},
Input = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["key1"] = "value1",
["key2"] = "value2",
}),
});
});
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(lambdaFunctionTest.functionName())
.triggers(Map.of("redeployment", StdFunctions.sha1(Sha1Args.builder()
.input(serializeJson(
jsonArray(exampleAwsLambdaFunction.environment())))
.build()).result()))
.input(serializeJson(
jsonObject(
jsonProperty("key1", "value1"),
jsonProperty("key2", "value2")
)))
.build());
}
}
resources:
example:
type: aws:lambda:Invocation
properties:
functionName: ${lambdaFunctionTest.functionName}
triggers:
redeployment:
fn::invoke:
Function: std:sha1
Arguments:
input:
fn::toJSON:
- ${exampleAwsLambdaFunction.environment}
Return: result
input:
fn::toJSON:
key1: value1
key2: value2
CRUD Lifecycle Scope
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.lambda.Invocation("example", {
functionName: lambdaFunctionTest.functionName,
input: JSON.stringify({
key1: "value1",
key2: "value2",
}),
lifecycleScope: "CRUD",
});
import pulumi
import json
import pulumi_aws as aws
example = aws.lambda_.Invocation("example",
function_name=lambda_function_test["functionName"],
input=json.dumps({
"key1": "value1",
"key2": "value2",
}),
lifecycle_scope="CRUD")
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
tmpJSON0, err := json.Marshal(map[string]interface{}{
"key1": "value1",
"key2": "value2",
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
_, err = lambda.NewInvocation(ctx, "example", &lambda.InvocationArgs{
FunctionName: pulumi.Any(lambdaFunctionTest.FunctionName),
Input: pulumi.String(json0),
LifecycleScope: pulumi.String("CRUD"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.Lambda.Invocation("example", new()
{
FunctionName = lambdaFunctionTest.FunctionName,
Input = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["key1"] = "value1",
["key2"] = "value2",
}),
LifecycleScope = "CRUD",
});
});
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(lambdaFunctionTest.functionName())
.input(serializeJson(
jsonObject(
jsonProperty("key1", "value1"),
jsonProperty("key2", "value2")
)))
.lifecycleScope("CRUD")
.build());
}
}
resources:
example:
type: aws:lambda:Invocation
properties:
functionName: ${lambdaFunctionTest.functionName}
input:
fn::toJSON:
key1: value1
key2: value2
lifecycleScope: CRUD
NOTE:
lifecycle_scope = "CRUD"
will inject a keytf
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 keytf
in your own input JSON, the default key name can be overridden with thepulumi_key
argument.
The key tf
gets added with subkeys:
action
- Action Pulumi performs on the resource. Values arecreate
,update
, ordelete
.prev_input
- Input JSON payload from the previous invocation. This can be used to handle update and delete events.
When the resource from the example above is created, the Lambda will get following JSON payload:
{
"key1": "value1",
"key2": "value2",
"tf": {
"action": "create",
"prev_input": null
}
}
If the input value of key1
changes to “valueB”, then the lambda will be invoked again with the following JSON payload:
{
"key1": "valueB",
"key2": "value2",
"tf": {
"action": "update",
"prev_input": {
"key1": "value1",
"key2": "value2"
}
}
}
When the invocation resource is removed, the final invocation will have the following JSON payload:
{
"key1": "valueB",
"key2": "value2",
"tf": {
"action": "delete",
"prev_input": {
"key1": "valueB",
"key2": "value2"
}
}
}
Create Invocation Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new Invocation(name: string, args: InvocationArgs, opts?: CustomResourceOptions);
@overload
def Invocation(resource_name: str,
args: InvocationArgs,
opts: Optional[ResourceOptions] = None)
@overload
def Invocation(resource_name: str,
opts: Optional[ResourceOptions] = None,
function_name: Optional[str] = None,
input: Optional[str] = None,
lifecycle_scope: Optional[str] = None,
qualifier: Optional[str] = None,
terraform_key: Optional[str] = None,
triggers: Optional[Mapping[str, str]] = None)
func NewInvocation(ctx *Context, name string, args InvocationArgs, opts ...ResourceOption) (*Invocation, error)
public Invocation(string name, InvocationArgs args, CustomResourceOptions? opts = null)
public Invocation(String name, InvocationArgs args)
public Invocation(String name, InvocationArgs args, CustomResourceOptions options)
type: aws:lambda:Invocation
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args InvocationArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args InvocationArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args InvocationArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args InvocationArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args InvocationArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var invocationResource = new Aws.Lambda.Invocation("invocationResource", new()
{
FunctionName = "string",
Input = "string",
LifecycleScope = "string",
Qualifier = "string",
TerraformKey = "string",
Triggers =
{
{ "string", "string" },
},
});
example, err := lambda.NewInvocation(ctx, "invocationResource", &lambda.InvocationArgs{
FunctionName: pulumi.String("string"),
Input: pulumi.String("string"),
LifecycleScope: pulumi.String("string"),
Qualifier: pulumi.String("string"),
TerraformKey: pulumi.String("string"),
Triggers: pulumi.StringMap{
"string": pulumi.String("string"),
},
})
var invocationResource = new Invocation("invocationResource", InvocationArgs.builder()
.functionName("string")
.input("string")
.lifecycleScope("string")
.qualifier("string")
.terraformKey("string")
.triggers(Map.of("string", "string"))
.build());
invocation_resource = aws.lambda_.Invocation("invocationResource",
function_name="string",
input="string",
lifecycle_scope="string",
qualifier="string",
terraform_key="string",
triggers={
"string": "string",
})
const invocationResource = new aws.lambda.Invocation("invocationResource", {
functionName: "string",
input: "string",
lifecycleScope: "string",
qualifier: "string",
terraformKey: "string",
triggers: {
string: "string",
},
});
type: aws:lambda:Invocation
properties:
functionName: string
input: string
lifecycleScope: string
qualifier: string
terraformKey: string
triggers:
string: string
Invocation Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The Invocation resource accepts the following input properties:
- Function
Name string - Name of the lambda function.
- Input string
JSON payload to the lambda function.
The following arguments are optional:
- Lifecycle
Scope string - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - Qualifier string
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - Terraform
Key string - Triggers Dictionary<string, string>
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- Function
Name string - Name of the lambda function.
- Input string
JSON payload to the lambda function.
The following arguments are optional:
- Lifecycle
Scope string - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - Qualifier string
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - Terraform
Key string - Triggers map[string]string
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function
Name String - Name of the lambda function.
- input String
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle
Scope String - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier String
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - terraform
Key String - triggers Map<String,String>
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function
Name string - Name of the lambda function.
- input string
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle
Scope string - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier string
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - terraform
Key string - triggers {[key: string]: string}
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function_
name str - Name of the lambda function.
- input str
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle_
scope str - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier str
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - terraform_
key str - triggers Mapping[str, str]
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function
Name String - Name of the lambda function.
- input String
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle
Scope String - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier String
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - terraform
Key String - triggers Map<String>
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Outputs
All input properties are implicitly available as output properties. Additionally, the Invocation resource produces the following output properties:
Look up Existing Invocation Resource
Get an existing Invocation resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: InvocationState, opts?: CustomResourceOptions): Invocation
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
function_name: Optional[str] = None,
input: Optional[str] = None,
lifecycle_scope: Optional[str] = None,
qualifier: Optional[str] = None,
result: Optional[str] = None,
terraform_key: Optional[str] = None,
triggers: Optional[Mapping[str, str]] = None) -> Invocation
func GetInvocation(ctx *Context, name string, id IDInput, state *InvocationState, opts ...ResourceOption) (*Invocation, error)
public static Invocation Get(string name, Input<string> id, InvocationState? state, CustomResourceOptions? opts = null)
public static Invocation get(String name, Output<String> id, InvocationState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Function
Name string - Name of the lambda function.
- Input string
JSON payload to the lambda function.
The following arguments are optional:
- Lifecycle
Scope string - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - Qualifier string
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - Result string
- String result of the lambda function invocation.
- Terraform
Key string - Triggers Dictionary<string, string>
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- Function
Name string - Name of the lambda function.
- Input string
JSON payload to the lambda function.
The following arguments are optional:
- Lifecycle
Scope string - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - Qualifier string
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - Result string
- String result of the lambda function invocation.
- Terraform
Key string - Triggers map[string]string
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function
Name String - Name of the lambda function.
- input String
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle
Scope String - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier String
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - result String
- String result of the lambda function invocation.
- terraform
Key String - triggers Map<String,String>
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function
Name string - Name of the lambda function.
- input string
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle
Scope string - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier string
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - result string
- String result of the lambda function invocation.
- terraform
Key string - triggers {[key: string]: string}
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function_
name str - Name of the lambda function.
- input str
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle_
scope str - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier str
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - result str
- String result of the lambda function invocation.
- terraform_
key str - triggers Mapping[str, str]
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
- function
Name String - Name of the lambda function.
- input String
JSON payload to the lambda function.
The following arguments are optional:
- lifecycle
Scope String - Lifecycle scope of the resource to manage. Valid values are
CREATE_ONLY
andCRUD
. Defaults toCREATE_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. - qualifier String
- Qualifier (i.e., version) of the lambda function. Defaults to
$LATEST
. - result String
- String result of the lambda function invocation.
- terraform
Key String - triggers Map<String>
- Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.