github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/lambda/invocation.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package lambda
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Use this resource to invoke a lambda function. The lambda function is invoked with the [RequestResponse](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax) invocation type.
    16  //
    17  // > **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 the `lambda.Invocation` data source. To invoke the lambda function when the Pulumi resource is updated and deleted, see the CRUD Lifecycle Scope example below.
    18  //
    19  // > **NOTE:** If you get a `KMSAccessDeniedException: Lambda was unable to decrypt the environment variables because KMS access was denied` error when invoking an `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.)
    20  //
    21  // ## Example Usage
    22  //
    23  // ### Dynamic Invocation Example Using Triggers
    24  //
    25  // <!--Start PulumiCodeChooser -->
    26  // ```go
    27  // package main
    28  //
    29  // import (
    30  //
    31  //	"encoding/json"
    32  //
    33  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda"
    34  //	"github.com/pulumi/pulumi-std/sdk/go/std"
    35  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    36  //
    37  // )
    38  //
    39  //	func main() {
    40  //		pulumi.Run(func(ctx *pulumi.Context) error {
    41  //			tmpJSON0, err := json.Marshal([]interface{}{
    42  //				exampleAwsLambdaFunction.Environment,
    43  //			})
    44  //			if err != nil {
    45  //				return err
    46  //			}
    47  //			json0 := string(tmpJSON0)
    48  //			invokeSha1, err := std.Sha1(ctx, &std.Sha1Args{
    49  //				Input: json0,
    50  //			}, nil)
    51  //			if err != nil {
    52  //				return err
    53  //			}
    54  //			tmpJSON1, err := json.Marshal(map[string]interface{}{
    55  //				"key1": "value1",
    56  //				"key2": "value2",
    57  //			})
    58  //			if err != nil {
    59  //				return err
    60  //			}
    61  //			json1 := string(tmpJSON1)
    62  //			_, err = lambda.NewInvocation(ctx, "example", &lambda.InvocationArgs{
    63  //				FunctionName: pulumi.Any(lambdaFunctionTest.FunctionName),
    64  //				Triggers: pulumi.StringMap{
    65  //					"redeployment": invokeSha1.Result,
    66  //				},
    67  //				Input: pulumi.String(json1),
    68  //			})
    69  //			if err != nil {
    70  //				return err
    71  //			}
    72  //			return nil
    73  //		})
    74  //	}
    75  //
    76  // ```
    77  // <!--End PulumiCodeChooser -->
    78  //
    79  // ### CRUD Lifecycle Scope
    80  //
    81  // <!--Start PulumiCodeChooser -->
    82  // ```go
    83  // package main
    84  //
    85  // import (
    86  //
    87  //	"encoding/json"
    88  //
    89  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda"
    90  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    91  //
    92  // )
    93  //
    94  //	func main() {
    95  //		pulumi.Run(func(ctx *pulumi.Context) error {
    96  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    97  //				"key1": "value1",
    98  //				"key2": "value2",
    99  //			})
   100  //			if err != nil {
   101  //				return err
   102  //			}
   103  //			json0 := string(tmpJSON0)
   104  //			_, err = lambda.NewInvocation(ctx, "example", &lambda.InvocationArgs{
   105  //				FunctionName:   pulumi.Any(lambdaFunctionTest.FunctionName),
   106  //				Input:          pulumi.String(json0),
   107  //				LifecycleScope: pulumi.String("CRUD"),
   108  //			})
   109  //			if err != nil {
   110  //				return err
   111  //			}
   112  //			return nil
   113  //		})
   114  //	}
   115  //
   116  // ```
   117  // <!--End PulumiCodeChooser -->
   118  //
   119  // > **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.
   120  //
   121  // The key `tf` gets added with subkeys:
   122  //
   123  // * `action` - Action Pulumi performs on the resource. Values are `create`, `update`, or `delete`.
   124  // * `prevInput` - Input JSON payload from the previous invocation. This can be used to handle update and delete events.
   125  //
   126  // When the resource from the example above is created, the Lambda will get following JSON payload:
   127  //
   128  // If the input value of `key1` changes to "valueB", then the lambda will be invoked again with the following JSON payload:
   129  //
   130  // When the invocation resource is removed, the final invocation will have the following JSON payload:
   131  type Invocation struct {
   132  	pulumi.CustomResourceState
   133  
   134  	// Name of the lambda function.
   135  	FunctionName pulumi.StringOutput `pulumi:"functionName"`
   136  	// JSON payload to the lambda function.
   137  	//
   138  	// The following arguments are optional:
   139  	Input pulumi.StringOutput `pulumi:"input"`
   140  	// 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.
   141  	LifecycleScope pulumi.StringPtrOutput `pulumi:"lifecycleScope"`
   142  	// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
   143  	Qualifier pulumi.StringPtrOutput `pulumi:"qualifier"`
   144  	// String result of the lambda function invocation.
   145  	Result       pulumi.StringOutput    `pulumi:"result"`
   146  	TerraformKey pulumi.StringPtrOutput `pulumi:"terraformKey"`
   147  	// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
   148  	Triggers pulumi.StringMapOutput `pulumi:"triggers"`
   149  }
   150  
   151  // NewInvocation registers a new resource with the given unique name, arguments, and options.
   152  func NewInvocation(ctx *pulumi.Context,
   153  	name string, args *InvocationArgs, opts ...pulumi.ResourceOption) (*Invocation, error) {
   154  	if args == nil {
   155  		return nil, errors.New("missing one or more required arguments")
   156  	}
   157  
   158  	if args.FunctionName == nil {
   159  		return nil, errors.New("invalid value for required argument 'FunctionName'")
   160  	}
   161  	if args.Input == nil {
   162  		return nil, errors.New("invalid value for required argument 'Input'")
   163  	}
   164  	opts = internal.PkgResourceDefaultOpts(opts)
   165  	var resource Invocation
   166  	err := ctx.RegisterResource("aws:lambda/invocation:Invocation", name, args, &resource, opts...)
   167  	if err != nil {
   168  		return nil, err
   169  	}
   170  	return &resource, nil
   171  }
   172  
   173  // GetInvocation gets an existing Invocation resource's state with the given name, ID, and optional
   174  // state properties that are used to uniquely qualify the lookup (nil if not required).
   175  func GetInvocation(ctx *pulumi.Context,
   176  	name string, id pulumi.IDInput, state *InvocationState, opts ...pulumi.ResourceOption) (*Invocation, error) {
   177  	var resource Invocation
   178  	err := ctx.ReadResource("aws:lambda/invocation:Invocation", name, id, state, &resource, opts...)
   179  	if err != nil {
   180  		return nil, err
   181  	}
   182  	return &resource, nil
   183  }
   184  
   185  // Input properties used for looking up and filtering Invocation resources.
   186  type invocationState struct {
   187  	// Name of the lambda function.
   188  	FunctionName *string `pulumi:"functionName"`
   189  	// JSON payload to the lambda function.
   190  	//
   191  	// The following arguments are optional:
   192  	Input *string `pulumi:"input"`
   193  	// 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.
   194  	LifecycleScope *string `pulumi:"lifecycleScope"`
   195  	// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
   196  	Qualifier *string `pulumi:"qualifier"`
   197  	// String result of the lambda function invocation.
   198  	Result       *string `pulumi:"result"`
   199  	TerraformKey *string `pulumi:"terraformKey"`
   200  	// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
   201  	Triggers map[string]string `pulumi:"triggers"`
   202  }
   203  
   204  type InvocationState struct {
   205  	// Name of the lambda function.
   206  	FunctionName pulumi.StringPtrInput
   207  	// JSON payload to the lambda function.
   208  	//
   209  	// The following arguments are optional:
   210  	Input pulumi.StringPtrInput
   211  	// 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.
   212  	LifecycleScope pulumi.StringPtrInput
   213  	// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
   214  	Qualifier pulumi.StringPtrInput
   215  	// String result of the lambda function invocation.
   216  	Result       pulumi.StringPtrInput
   217  	TerraformKey pulumi.StringPtrInput
   218  	// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
   219  	Triggers pulumi.StringMapInput
   220  }
   221  
   222  func (InvocationState) ElementType() reflect.Type {
   223  	return reflect.TypeOf((*invocationState)(nil)).Elem()
   224  }
   225  
   226  type invocationArgs struct {
   227  	// Name of the lambda function.
   228  	FunctionName string `pulumi:"functionName"`
   229  	// JSON payload to the lambda function.
   230  	//
   231  	// The following arguments are optional:
   232  	Input string `pulumi:"input"`
   233  	// 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.
   234  	LifecycleScope *string `pulumi:"lifecycleScope"`
   235  	// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
   236  	Qualifier    *string `pulumi:"qualifier"`
   237  	TerraformKey *string `pulumi:"terraformKey"`
   238  	// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
   239  	Triggers map[string]string `pulumi:"triggers"`
   240  }
   241  
   242  // The set of arguments for constructing a Invocation resource.
   243  type InvocationArgs struct {
   244  	// Name of the lambda function.
   245  	FunctionName pulumi.StringInput
   246  	// JSON payload to the lambda function.
   247  	//
   248  	// The following arguments are optional:
   249  	Input pulumi.StringInput
   250  	// 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.
   251  	LifecycleScope pulumi.StringPtrInput
   252  	// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
   253  	Qualifier    pulumi.StringPtrInput
   254  	TerraformKey pulumi.StringPtrInput
   255  	// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
   256  	Triggers pulumi.StringMapInput
   257  }
   258  
   259  func (InvocationArgs) ElementType() reflect.Type {
   260  	return reflect.TypeOf((*invocationArgs)(nil)).Elem()
   261  }
   262  
   263  type InvocationInput interface {
   264  	pulumi.Input
   265  
   266  	ToInvocationOutput() InvocationOutput
   267  	ToInvocationOutputWithContext(ctx context.Context) InvocationOutput
   268  }
   269  
   270  func (*Invocation) ElementType() reflect.Type {
   271  	return reflect.TypeOf((**Invocation)(nil)).Elem()
   272  }
   273  
   274  func (i *Invocation) ToInvocationOutput() InvocationOutput {
   275  	return i.ToInvocationOutputWithContext(context.Background())
   276  }
   277  
   278  func (i *Invocation) ToInvocationOutputWithContext(ctx context.Context) InvocationOutput {
   279  	return pulumi.ToOutputWithContext(ctx, i).(InvocationOutput)
   280  }
   281  
   282  // InvocationArrayInput is an input type that accepts InvocationArray and InvocationArrayOutput values.
   283  // You can construct a concrete instance of `InvocationArrayInput` via:
   284  //
   285  //	InvocationArray{ InvocationArgs{...} }
   286  type InvocationArrayInput interface {
   287  	pulumi.Input
   288  
   289  	ToInvocationArrayOutput() InvocationArrayOutput
   290  	ToInvocationArrayOutputWithContext(context.Context) InvocationArrayOutput
   291  }
   292  
   293  type InvocationArray []InvocationInput
   294  
   295  func (InvocationArray) ElementType() reflect.Type {
   296  	return reflect.TypeOf((*[]*Invocation)(nil)).Elem()
   297  }
   298  
   299  func (i InvocationArray) ToInvocationArrayOutput() InvocationArrayOutput {
   300  	return i.ToInvocationArrayOutputWithContext(context.Background())
   301  }
   302  
   303  func (i InvocationArray) ToInvocationArrayOutputWithContext(ctx context.Context) InvocationArrayOutput {
   304  	return pulumi.ToOutputWithContext(ctx, i).(InvocationArrayOutput)
   305  }
   306  
   307  // InvocationMapInput is an input type that accepts InvocationMap and InvocationMapOutput values.
   308  // You can construct a concrete instance of `InvocationMapInput` via:
   309  //
   310  //	InvocationMap{ "key": InvocationArgs{...} }
   311  type InvocationMapInput interface {
   312  	pulumi.Input
   313  
   314  	ToInvocationMapOutput() InvocationMapOutput
   315  	ToInvocationMapOutputWithContext(context.Context) InvocationMapOutput
   316  }
   317  
   318  type InvocationMap map[string]InvocationInput
   319  
   320  func (InvocationMap) ElementType() reflect.Type {
   321  	return reflect.TypeOf((*map[string]*Invocation)(nil)).Elem()
   322  }
   323  
   324  func (i InvocationMap) ToInvocationMapOutput() InvocationMapOutput {
   325  	return i.ToInvocationMapOutputWithContext(context.Background())
   326  }
   327  
   328  func (i InvocationMap) ToInvocationMapOutputWithContext(ctx context.Context) InvocationMapOutput {
   329  	return pulumi.ToOutputWithContext(ctx, i).(InvocationMapOutput)
   330  }
   331  
   332  type InvocationOutput struct{ *pulumi.OutputState }
   333  
   334  func (InvocationOutput) ElementType() reflect.Type {
   335  	return reflect.TypeOf((**Invocation)(nil)).Elem()
   336  }
   337  
   338  func (o InvocationOutput) ToInvocationOutput() InvocationOutput {
   339  	return o
   340  }
   341  
   342  func (o InvocationOutput) ToInvocationOutputWithContext(ctx context.Context) InvocationOutput {
   343  	return o
   344  }
   345  
   346  // Name of the lambda function.
   347  func (o InvocationOutput) FunctionName() pulumi.StringOutput {
   348  	return o.ApplyT(func(v *Invocation) pulumi.StringOutput { return v.FunctionName }).(pulumi.StringOutput)
   349  }
   350  
   351  // JSON payload to the lambda function.
   352  //
   353  // The following arguments are optional:
   354  func (o InvocationOutput) Input() pulumi.StringOutput {
   355  	return o.ApplyT(func(v *Invocation) pulumi.StringOutput { return v.Input }).(pulumi.StringOutput)
   356  }
   357  
   358  // 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.
   359  func (o InvocationOutput) LifecycleScope() pulumi.StringPtrOutput {
   360  	return o.ApplyT(func(v *Invocation) pulumi.StringPtrOutput { return v.LifecycleScope }).(pulumi.StringPtrOutput)
   361  }
   362  
   363  // Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
   364  func (o InvocationOutput) Qualifier() pulumi.StringPtrOutput {
   365  	return o.ApplyT(func(v *Invocation) pulumi.StringPtrOutput { return v.Qualifier }).(pulumi.StringPtrOutput)
   366  }
   367  
   368  // String result of the lambda function invocation.
   369  func (o InvocationOutput) Result() pulumi.StringOutput {
   370  	return o.ApplyT(func(v *Invocation) pulumi.StringOutput { return v.Result }).(pulumi.StringOutput)
   371  }
   372  
   373  func (o InvocationOutput) TerraformKey() pulumi.StringPtrOutput {
   374  	return o.ApplyT(func(v *Invocation) pulumi.StringPtrOutput { return v.TerraformKey }).(pulumi.StringPtrOutput)
   375  }
   376  
   377  // Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
   378  func (o InvocationOutput) Triggers() pulumi.StringMapOutput {
   379  	return o.ApplyT(func(v *Invocation) pulumi.StringMapOutput { return v.Triggers }).(pulumi.StringMapOutput)
   380  }
   381  
   382  type InvocationArrayOutput struct{ *pulumi.OutputState }
   383  
   384  func (InvocationArrayOutput) ElementType() reflect.Type {
   385  	return reflect.TypeOf((*[]*Invocation)(nil)).Elem()
   386  }
   387  
   388  func (o InvocationArrayOutput) ToInvocationArrayOutput() InvocationArrayOutput {
   389  	return o
   390  }
   391  
   392  func (o InvocationArrayOutput) ToInvocationArrayOutputWithContext(ctx context.Context) InvocationArrayOutput {
   393  	return o
   394  }
   395  
   396  func (o InvocationArrayOutput) Index(i pulumi.IntInput) InvocationOutput {
   397  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Invocation {
   398  		return vs[0].([]*Invocation)[vs[1].(int)]
   399  	}).(InvocationOutput)
   400  }
   401  
   402  type InvocationMapOutput struct{ *pulumi.OutputState }
   403  
   404  func (InvocationMapOutput) ElementType() reflect.Type {
   405  	return reflect.TypeOf((*map[string]*Invocation)(nil)).Elem()
   406  }
   407  
   408  func (o InvocationMapOutput) ToInvocationMapOutput() InvocationMapOutput {
   409  	return o
   410  }
   411  
   412  func (o InvocationMapOutput) ToInvocationMapOutputWithContext(ctx context.Context) InvocationMapOutput {
   413  	return o
   414  }
   415  
   416  func (o InvocationMapOutput) MapIndex(k pulumi.StringInput) InvocationOutput {
   417  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Invocation {
   418  		return vs[0].(map[string]*Invocation)[vs[1].(string)]
   419  	}).(InvocationOutput)
   420  }
   421  
   422  func init() {
   423  	pulumi.RegisterInputType(reflect.TypeOf((*InvocationInput)(nil)).Elem(), &Invocation{})
   424  	pulumi.RegisterInputType(reflect.TypeOf((*InvocationArrayInput)(nil)).Elem(), InvocationArray{})
   425  	pulumi.RegisterInputType(reflect.TypeOf((*InvocationMapInput)(nil)).Elem(), InvocationMap{})
   426  	pulumi.RegisterOutputType(InvocationOutput{})
   427  	pulumi.RegisterOutputType(InvocationArrayOutput{})
   428  	pulumi.RegisterOutputType(InvocationMapOutput{})
   429  }