-
Notifications
You must be signed in to change notification settings - Fork 151
/
invocation.go
347 lines (296 loc) · 12.3 KB
/
invocation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package lambda
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// 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.
//
// > **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 `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 `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
//
// ```go
// 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
// })
// }
//
// ```
type Invocation struct {
pulumi.CustomResourceState
// Name of the lambda function.
FunctionName pulumi.StringOutput `pulumi:"functionName"`
// JSON payload to the lambda function.
//
// The following arguments are optional:
Input pulumi.StringOutput `pulumi:"input"`
// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
Qualifier pulumi.StringPtrOutput `pulumi:"qualifier"`
// String result of the lambda function invocation.
Result pulumi.StringOutput `pulumi:"result"`
// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Triggers pulumi.StringMapOutput `pulumi:"triggers"`
}
// NewInvocation registers a new resource with the given unique name, arguments, and options.
func NewInvocation(ctx *pulumi.Context,
name string, args *InvocationArgs, opts ...pulumi.ResourceOption) (*Invocation, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.FunctionName == nil {
return nil, errors.New("invalid value for required argument 'FunctionName'")
}
if args.Input == nil {
return nil, errors.New("invalid value for required argument 'Input'")
}
var resource Invocation
err := ctx.RegisterResource("aws:lambda/invocation:Invocation", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetInvocation gets an existing Invocation resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetInvocation(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *InvocationState, opts ...pulumi.ResourceOption) (*Invocation, error) {
var resource Invocation
err := ctx.ReadResource("aws:lambda/invocation:Invocation", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Invocation resources.
type invocationState struct {
// Name of the lambda function.
FunctionName *string `pulumi:"functionName"`
// JSON payload to the lambda function.
//
// The following arguments are optional:
Input *string `pulumi:"input"`
// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
Qualifier *string `pulumi:"qualifier"`
// String result of the lambda function invocation.
Result *string `pulumi:"result"`
// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Triggers map[string]string `pulumi:"triggers"`
}
type InvocationState struct {
// Name of the lambda function.
FunctionName pulumi.StringPtrInput
// JSON payload to the lambda function.
//
// The following arguments are optional:
Input pulumi.StringPtrInput
// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
Qualifier pulumi.StringPtrInput
// String result of the lambda function invocation.
Result pulumi.StringPtrInput
// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Triggers pulumi.StringMapInput
}
func (InvocationState) ElementType() reflect.Type {
return reflect.TypeOf((*invocationState)(nil)).Elem()
}
type invocationArgs struct {
// Name of the lambda function.
FunctionName string `pulumi:"functionName"`
// JSON payload to the lambda function.
//
// The following arguments are optional:
Input string `pulumi:"input"`
// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
Qualifier *string `pulumi:"qualifier"`
// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Triggers map[string]string `pulumi:"triggers"`
}
// The set of arguments for constructing a Invocation resource.
type InvocationArgs struct {
// Name of the lambda function.
FunctionName pulumi.StringInput
// JSON payload to the lambda function.
//
// The following arguments are optional:
Input pulumi.StringInput
// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
Qualifier pulumi.StringPtrInput
// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
Triggers pulumi.StringMapInput
}
func (InvocationArgs) ElementType() reflect.Type {
return reflect.TypeOf((*invocationArgs)(nil)).Elem()
}
type InvocationInput interface {
pulumi.Input
ToInvocationOutput() InvocationOutput
ToInvocationOutputWithContext(ctx context.Context) InvocationOutput
}
func (*Invocation) ElementType() reflect.Type {
return reflect.TypeOf((**Invocation)(nil)).Elem()
}
func (i *Invocation) ToInvocationOutput() InvocationOutput {
return i.ToInvocationOutputWithContext(context.Background())
}
func (i *Invocation) ToInvocationOutputWithContext(ctx context.Context) InvocationOutput {
return pulumi.ToOutputWithContext(ctx, i).(InvocationOutput)
}
// InvocationArrayInput is an input type that accepts InvocationArray and InvocationArrayOutput values.
// You can construct a concrete instance of `InvocationArrayInput` via:
//
// InvocationArray{ InvocationArgs{...} }
type InvocationArrayInput interface {
pulumi.Input
ToInvocationArrayOutput() InvocationArrayOutput
ToInvocationArrayOutputWithContext(context.Context) InvocationArrayOutput
}
type InvocationArray []InvocationInput
func (InvocationArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Invocation)(nil)).Elem()
}
func (i InvocationArray) ToInvocationArrayOutput() InvocationArrayOutput {
return i.ToInvocationArrayOutputWithContext(context.Background())
}
func (i InvocationArray) ToInvocationArrayOutputWithContext(ctx context.Context) InvocationArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(InvocationArrayOutput)
}
// InvocationMapInput is an input type that accepts InvocationMap and InvocationMapOutput values.
// You can construct a concrete instance of `InvocationMapInput` via:
//
// InvocationMap{ "key": InvocationArgs{...} }
type InvocationMapInput interface {
pulumi.Input
ToInvocationMapOutput() InvocationMapOutput
ToInvocationMapOutputWithContext(context.Context) InvocationMapOutput
}
type InvocationMap map[string]InvocationInput
func (InvocationMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Invocation)(nil)).Elem()
}
func (i InvocationMap) ToInvocationMapOutput() InvocationMapOutput {
return i.ToInvocationMapOutputWithContext(context.Background())
}
func (i InvocationMap) ToInvocationMapOutputWithContext(ctx context.Context) InvocationMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(InvocationMapOutput)
}
type InvocationOutput struct{ *pulumi.OutputState }
func (InvocationOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Invocation)(nil)).Elem()
}
func (o InvocationOutput) ToInvocationOutput() InvocationOutput {
return o
}
func (o InvocationOutput) ToInvocationOutputWithContext(ctx context.Context) InvocationOutput {
return o
}
// Name of the lambda function.
func (o InvocationOutput) FunctionName() pulumi.StringOutput {
return o.ApplyT(func(v *Invocation) pulumi.StringOutput { return v.FunctionName }).(pulumi.StringOutput)
}
// JSON payload to the lambda function.
//
// The following arguments are optional:
func (o InvocationOutput) Input() pulumi.StringOutput {
return o.ApplyT(func(v *Invocation) pulumi.StringOutput { return v.Input }).(pulumi.StringOutput)
}
// Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`.
func (o InvocationOutput) Qualifier() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Invocation) pulumi.StringPtrOutput { return v.Qualifier }).(pulumi.StringPtrOutput)
}
// String result of the lambda function invocation.
func (o InvocationOutput) Result() pulumi.StringOutput {
return o.ApplyT(func(v *Invocation) pulumi.StringOutput { return v.Result }).(pulumi.StringOutput)
}
// Map of arbitrary keys and values that, when changed, will trigger a re-invocation.
func (o InvocationOutput) Triggers() pulumi.StringMapOutput {
return o.ApplyT(func(v *Invocation) pulumi.StringMapOutput { return v.Triggers }).(pulumi.StringMapOutput)
}
type InvocationArrayOutput struct{ *pulumi.OutputState }
func (InvocationArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Invocation)(nil)).Elem()
}
func (o InvocationArrayOutput) ToInvocationArrayOutput() InvocationArrayOutput {
return o
}
func (o InvocationArrayOutput) ToInvocationArrayOutputWithContext(ctx context.Context) InvocationArrayOutput {
return o
}
func (o InvocationArrayOutput) Index(i pulumi.IntInput) InvocationOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Invocation {
return vs[0].([]*Invocation)[vs[1].(int)]
}).(InvocationOutput)
}
type InvocationMapOutput struct{ *pulumi.OutputState }
func (InvocationMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Invocation)(nil)).Elem()
}
func (o InvocationMapOutput) ToInvocationMapOutput() InvocationMapOutput {
return o
}
func (o InvocationMapOutput) ToInvocationMapOutputWithContext(ctx context.Context) InvocationMapOutput {
return o
}
func (o InvocationMapOutput) MapIndex(k pulumi.StringInput) InvocationOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Invocation {
return vs[0].(map[string]*Invocation)[vs[1].(string)]
}).(InvocationOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*InvocationInput)(nil)).Elem(), &Invocation{})
pulumi.RegisterInputType(reflect.TypeOf((*InvocationArrayInput)(nil)).Elem(), InvocationArray{})
pulumi.RegisterInputType(reflect.TypeOf((*InvocationMapInput)(nil)).Elem(), InvocationMap{})
pulumi.RegisterOutputType(InvocationOutput{})
pulumi.RegisterOutputType(InvocationArrayOutput{})
pulumi.RegisterOutputType(InvocationMapOutput{})
}