1. Packages
  2. AWS Classic
  3. API Docs
  4. lambda
  5. Invocation

Try AWS Native preview for resources not in the classic version.

AWS Classic v5.41.0 published on Monday, May 15, 2023 by Pulumi

aws.lambda.Invocation

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v5.41.0 published on Monday, May 15, 2023 by Pulumi

    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 the aws.lambda.Invocation data source.

    NOTE: If you get a KMSAccessDeniedException: Lambda was unable to decrypt the environment variables because KMS access was denied error when invoking an aws.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 to taint the function and apply 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

    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Text.Json;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    	private static string ComputeSHA1(string input) {
    		return BitConverter.ToString(
    			SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(input))
    		).Replace("-","").ToLowerInvariant());
    	}
    
    return await Deployment.RunAsync(() => 
    {
        var example = new Aws.Lambda.Invocation("example", new()
        {
            FunctionName = aws_lambda_function.Lambda_function_test.Function_name,
            Triggers = 
            {
                { "redeployment", ComputeSHA1(JsonSerializer.Serialize(new[]
                {
                    aws_lambda_function.Example.Environment,
                })) },
            },
            Input = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["key1"] = "value1",
                ["key2"] = "value2",
            }),
        });
    
    });
    
    package main
    
    import (
    	"crypto/sha1"
    	"encoding/json"
    	"fmt"
    
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/lambda"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func sha1Hash(input string) string {
    	hash := sha1.Sum([]byte(input))
    	return hex.EncodeToString(hash[:])
    }
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		tmpJSON0, err := json.Marshal([]interface{}{
    			aws_lambda_function.Example.Environment,
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		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(aws_lambda_function.Lambda_function_test.Function_name),
    			Triggers: pulumi.StringMap{
    				"redeployment": sha1Hash(json0),
    			},
    			Input: pulumi.String(json1),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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());
    
        }
    }
    
    import pulumi
    import hashlib
    import json
    import pulumi_aws as aws
    
    example = aws.lambda_.Invocation("example",
        function_name=aws_lambda_function["lambda_function_test"]["function_name"],
        triggers={
            "redeployment": hashlib.sha1(json.dumps([aws_lambda_function["example"]["environment"]]).encode()).hexdigest(),
        },
        input=json.dumps({
            "key1": "value1",
            "key2": "value2",
        }))
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as crypto from "crypto";
    
    const example = new aws.lambda.Invocation("example", {
        functionName: aws_lambda_function.lambda_function_test.function_name,
        triggers: {
            redeployment: crypto.createHash('sha1').update(JSON.stringify([aws_lambda_function.example.environment])).digest('hex'),
        },
        input: JSON.stringify({
            key1: "value1",
            key2: "value2",
        }),
    });
    

    Coming soon!

    Create Invocation Resource

    new Invocation(name: string, args: InvocationArgs, opts?: CustomResourceOptions);
    @overload
    def Invocation(resource_name: str,
                   opts: Optional[ResourceOptions] = None,
                   function_name: Optional[str] = None,
                   input: Optional[str] = None,
                   qualifier: Optional[str] = None,
                   triggers: Optional[Mapping[str, str]] = None)
    @overload
    def Invocation(resource_name: str,
                   args: InvocationArgs,
                   opts: Optional[ResourceOptions] = 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.
    
    
    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.

    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:

    FunctionName string

    Name of the lambda function.

    Input string

    JSON payload to the lambda function.

    Qualifier string

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    Triggers Dictionary<string, string>

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    FunctionName string

    Name of the lambda function.

    Input string

    JSON payload to the lambda function.

    Qualifier string

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    Triggers map[string]string

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    functionName String

    Name of the lambda function.

    input String

    JSON payload to the lambda function.

    qualifier String

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    triggers Map<String,String>

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    functionName string

    Name of the lambda function.

    input string

    JSON payload to the lambda function.

    qualifier string

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    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.

    qualifier str

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    triggers Mapping[str, str]

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    functionName String

    Name of the lambda function.

    input String

    JSON payload to the lambda function.

    qualifier String

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    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:

    Id string

    The provider-assigned unique ID for this managed resource.

    Result string

    String result of the lambda function invocation.

    Id string

    The provider-assigned unique ID for this managed resource.

    Result string

    String result of the lambda function invocation.

    id String

    The provider-assigned unique ID for this managed resource.

    result String

    String result of the lambda function invocation.

    id string

    The provider-assigned unique ID for this managed resource.

    result string

    String result of the lambda function invocation.

    id str

    The provider-assigned unique ID for this managed resource.

    result str

    String result of the lambda function invocation.

    id String

    The provider-assigned unique ID for this managed resource.

    result String

    String result of the lambda function invocation.

    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,
            qualifier: Optional[str] = None,
            result: 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.
    The following state arguments are supported:
    FunctionName string

    Name of the lambda function.

    Input string

    JSON payload to the lambda function.

    Qualifier string

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    Result string

    String result of the lambda function invocation.

    Triggers Dictionary<string, string>

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    FunctionName string

    Name of the lambda function.

    Input string

    JSON payload to the lambda function.

    Qualifier string

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    Result string

    String result of the lambda function invocation.

    Triggers map[string]string

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    functionName String

    Name of the lambda function.

    input String

    JSON payload to the lambda function.

    qualifier String

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    result String

    String result of the lambda function invocation.

    triggers Map<String,String>

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    functionName string

    Name of the lambda function.

    input string

    JSON payload to the lambda function.

    qualifier string

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    result string

    String result of the lambda function invocation.

    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.

    qualifier str

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    result str

    String result of the lambda function invocation.

    triggers Mapping[str, str]

    Map of arbitrary keys and values that, when changed, will trigger a re-invocation.

    functionName String

    Name of the lambda function.

    input String

    JSON payload to the lambda function.

    qualifier String

    Qualifier (i.e., version) of the lambda function. Defaults to $LATEST.

    result String

    String result of the lambda function invocation.

    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.

    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v5.41.0 published on Monday, May 15, 2023 by Pulumi