github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/appsync/function.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 appsync 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 // Provides an AppSync Function. 16 // 17 // ## Example Usage 18 // 19 // <!--Start PulumiCodeChooser --> 20 // ```go 21 // package main 22 // 23 // import ( 24 // 25 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/appsync" 26 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 27 // 28 // ) 29 // 30 // func main() { 31 // pulumi.Run(func(ctx *pulumi.Context) error { 32 // example, err := appsync.NewGraphQLApi(ctx, "example", &appsync.GraphQLApiArgs{ 33 // AuthenticationType: pulumi.String("API_KEY"), 34 // Name: pulumi.String("example"), 35 // Schema: pulumi.String(`type Mutation { 36 // putPost(id: ID!, title: String!): Post 37 // } 38 // 39 // type Post { 40 // id: ID! 41 // title: String! 42 // } 43 // 44 // type Query { 45 // singlePost(id: ID!): Post 46 // } 47 // 48 // schema { 49 // query: Query 50 // mutation: Mutation 51 // } 52 // 53 // `), 54 // 55 // }) 56 // if err != nil { 57 // return err 58 // } 59 // exampleDataSource, err := appsync.NewDataSource(ctx, "example", &appsync.DataSourceArgs{ 60 // ApiId: example.ID(), 61 // Name: pulumi.String("example"), 62 // Type: pulumi.String("HTTP"), 63 // HttpConfig: &appsync.DataSourceHttpConfigArgs{ 64 // Endpoint: pulumi.String("http://example.com"), 65 // }, 66 // }) 67 // if err != nil { 68 // return err 69 // } 70 // _, err = appsync.NewFunction(ctx, "example", &appsync.FunctionArgs{ 71 // ApiId: example.ID(), 72 // DataSource: exampleDataSource.Name, 73 // Name: pulumi.String("example"), 74 // RequestMappingTemplate: pulumi.String(`{ 75 // "version": "2018-05-29", 76 // "method": "GET", 77 // "resourcePath": "/", 78 // "params":{ 79 // "headers": $utils.http.copyheaders($ctx.request.headers) 80 // } 81 // } 82 // 83 // `), 84 // 85 // ResponseMappingTemplate: pulumi.String(`#if($ctx.result.statusCode == 200) 86 // $ctx.result.body 87 // 88 // #else 89 // 90 // $utils.appendError($ctx.result.body, $ctx.result.statusCode) 91 // 92 // #end 93 // `), 94 // 95 // }) 96 // if err != nil { 97 // return err 98 // } 99 // return nil 100 // }) 101 // } 102 // 103 // ``` 104 // <!--End PulumiCodeChooser --> 105 // 106 // ### With Code 107 // 108 // <!--Start PulumiCodeChooser --> 109 // ```go 110 // package main 111 // 112 // import ( 113 // 114 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/appsync" 115 // "github.com/pulumi/pulumi-std/sdk/go/std" 116 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 117 // 118 // ) 119 // 120 // func main() { 121 // pulumi.Run(func(ctx *pulumi.Context) error { 122 // invokeFile, err := std.File(ctx, &std.FileArgs{ 123 // Input: "some-code-dir", 124 // }, nil) 125 // if err != nil { 126 // return err 127 // } 128 // _, err = appsync.NewFunction(ctx, "example", &appsync.FunctionArgs{ 129 // ApiId: pulumi.Any(exampleAwsAppsyncGraphqlApi.Id), 130 // DataSource: pulumi.Any(exampleAwsAppsyncDatasource.Name), 131 // Name: pulumi.String("example"), 132 // Code: invokeFile.Result, 133 // Runtime: &appsync.FunctionRuntimeArgs{ 134 // Name: pulumi.String("APPSYNC_JS"), 135 // RuntimeVersion: pulumi.String("1.0.0"), 136 // }, 137 // }) 138 // if err != nil { 139 // return err 140 // } 141 // return nil 142 // }) 143 // } 144 // 145 // ``` 146 // <!--End PulumiCodeChooser --> 147 // 148 // ## Import 149 // 150 // Using `pulumi import`, import `aws_appsync_function` using the AppSync API ID and Function ID separated by `-`. For example: 151 // 152 // ```sh 153 // $ pulumi import aws:appsync/function:Function example xxxxx-yyyyy 154 // ``` 155 type Function struct { 156 pulumi.CustomResourceState 157 158 // ID of the associated AppSync API. 159 ApiId pulumi.StringOutput `pulumi:"apiId"` 160 // ARN of the Function object. 161 Arn pulumi.StringOutput `pulumi:"arn"` 162 // The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS. 163 Code pulumi.StringPtrOutput `pulumi:"code"` 164 // Function data source name. 165 DataSource pulumi.StringOutput `pulumi:"dataSource"` 166 // Function description. 167 Description pulumi.StringPtrOutput `pulumi:"description"` 168 // Unique ID representing the Function object. 169 FunctionId pulumi.StringOutput `pulumi:"functionId"` 170 // Version of the request mapping template. Currently the supported value is `2018-05-29`. Does not apply when specifying `code`. 171 FunctionVersion pulumi.StringOutput `pulumi:"functionVersion"` 172 // Maximum batching size for a resolver. Valid values are between `0` and `2000`. 173 MaxBatchSize pulumi.IntPtrOutput `pulumi:"maxBatchSize"` 174 // Function name. The function name does not have to be unique. 175 Name pulumi.StringOutput `pulumi:"name"` 176 // Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template. 177 RequestMappingTemplate pulumi.StringPtrOutput `pulumi:"requestMappingTemplate"` 178 // Function response mapping template. 179 ResponseMappingTemplate pulumi.StringPtrOutput `pulumi:"responseMappingTemplate"` 180 // Describes a runtime used by an AWS AppSync pipeline resolver or AWS AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified. See Runtime. 181 Runtime FunctionRuntimePtrOutput `pulumi:"runtime"` 182 // Describes a Sync configuration for a resolver. See Sync Config. 183 SyncConfig FunctionSyncConfigPtrOutput `pulumi:"syncConfig"` 184 } 185 186 // NewFunction registers a new resource with the given unique name, arguments, and options. 187 func NewFunction(ctx *pulumi.Context, 188 name string, args *FunctionArgs, opts ...pulumi.ResourceOption) (*Function, error) { 189 if args == nil { 190 return nil, errors.New("missing one or more required arguments") 191 } 192 193 if args.ApiId == nil { 194 return nil, errors.New("invalid value for required argument 'ApiId'") 195 } 196 if args.DataSource == nil { 197 return nil, errors.New("invalid value for required argument 'DataSource'") 198 } 199 opts = internal.PkgResourceDefaultOpts(opts) 200 var resource Function 201 err := ctx.RegisterResource("aws:appsync/function:Function", name, args, &resource, opts...) 202 if err != nil { 203 return nil, err 204 } 205 return &resource, nil 206 } 207 208 // GetFunction gets an existing Function resource's state with the given name, ID, and optional 209 // state properties that are used to uniquely qualify the lookup (nil if not required). 210 func GetFunction(ctx *pulumi.Context, 211 name string, id pulumi.IDInput, state *FunctionState, opts ...pulumi.ResourceOption) (*Function, error) { 212 var resource Function 213 err := ctx.ReadResource("aws:appsync/function:Function", name, id, state, &resource, opts...) 214 if err != nil { 215 return nil, err 216 } 217 return &resource, nil 218 } 219 220 // Input properties used for looking up and filtering Function resources. 221 type functionState struct { 222 // ID of the associated AppSync API. 223 ApiId *string `pulumi:"apiId"` 224 // ARN of the Function object. 225 Arn *string `pulumi:"arn"` 226 // The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS. 227 Code *string `pulumi:"code"` 228 // Function data source name. 229 DataSource *string `pulumi:"dataSource"` 230 // Function description. 231 Description *string `pulumi:"description"` 232 // Unique ID representing the Function object. 233 FunctionId *string `pulumi:"functionId"` 234 // Version of the request mapping template. Currently the supported value is `2018-05-29`. Does not apply when specifying `code`. 235 FunctionVersion *string `pulumi:"functionVersion"` 236 // Maximum batching size for a resolver. Valid values are between `0` and `2000`. 237 MaxBatchSize *int `pulumi:"maxBatchSize"` 238 // Function name. The function name does not have to be unique. 239 Name *string `pulumi:"name"` 240 // Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template. 241 RequestMappingTemplate *string `pulumi:"requestMappingTemplate"` 242 // Function response mapping template. 243 ResponseMappingTemplate *string `pulumi:"responseMappingTemplate"` 244 // Describes a runtime used by an AWS AppSync pipeline resolver or AWS AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified. See Runtime. 245 Runtime *FunctionRuntime `pulumi:"runtime"` 246 // Describes a Sync configuration for a resolver. See Sync Config. 247 SyncConfig *FunctionSyncConfig `pulumi:"syncConfig"` 248 } 249 250 type FunctionState struct { 251 // ID of the associated AppSync API. 252 ApiId pulumi.StringPtrInput 253 // ARN of the Function object. 254 Arn pulumi.StringPtrInput 255 // The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS. 256 Code pulumi.StringPtrInput 257 // Function data source name. 258 DataSource pulumi.StringPtrInput 259 // Function description. 260 Description pulumi.StringPtrInput 261 // Unique ID representing the Function object. 262 FunctionId pulumi.StringPtrInput 263 // Version of the request mapping template. Currently the supported value is `2018-05-29`. Does not apply when specifying `code`. 264 FunctionVersion pulumi.StringPtrInput 265 // Maximum batching size for a resolver. Valid values are between `0` and `2000`. 266 MaxBatchSize pulumi.IntPtrInput 267 // Function name. The function name does not have to be unique. 268 Name pulumi.StringPtrInput 269 // Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template. 270 RequestMappingTemplate pulumi.StringPtrInput 271 // Function response mapping template. 272 ResponseMappingTemplate pulumi.StringPtrInput 273 // Describes a runtime used by an AWS AppSync pipeline resolver or AWS AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified. See Runtime. 274 Runtime FunctionRuntimePtrInput 275 // Describes a Sync configuration for a resolver. See Sync Config. 276 SyncConfig FunctionSyncConfigPtrInput 277 } 278 279 func (FunctionState) ElementType() reflect.Type { 280 return reflect.TypeOf((*functionState)(nil)).Elem() 281 } 282 283 type functionArgs struct { 284 // ID of the associated AppSync API. 285 ApiId string `pulumi:"apiId"` 286 // The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS. 287 Code *string `pulumi:"code"` 288 // Function data source name. 289 DataSource string `pulumi:"dataSource"` 290 // Function description. 291 Description *string `pulumi:"description"` 292 // Version of the request mapping template. Currently the supported value is `2018-05-29`. Does not apply when specifying `code`. 293 FunctionVersion *string `pulumi:"functionVersion"` 294 // Maximum batching size for a resolver. Valid values are between `0` and `2000`. 295 MaxBatchSize *int `pulumi:"maxBatchSize"` 296 // Function name. The function name does not have to be unique. 297 Name *string `pulumi:"name"` 298 // Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template. 299 RequestMappingTemplate *string `pulumi:"requestMappingTemplate"` 300 // Function response mapping template. 301 ResponseMappingTemplate *string `pulumi:"responseMappingTemplate"` 302 // Describes a runtime used by an AWS AppSync pipeline resolver or AWS AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified. See Runtime. 303 Runtime *FunctionRuntime `pulumi:"runtime"` 304 // Describes a Sync configuration for a resolver. See Sync Config. 305 SyncConfig *FunctionSyncConfig `pulumi:"syncConfig"` 306 } 307 308 // The set of arguments for constructing a Function resource. 309 type FunctionArgs struct { 310 // ID of the associated AppSync API. 311 ApiId pulumi.StringInput 312 // The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS. 313 Code pulumi.StringPtrInput 314 // Function data source name. 315 DataSource pulumi.StringInput 316 // Function description. 317 Description pulumi.StringPtrInput 318 // Version of the request mapping template. Currently the supported value is `2018-05-29`. Does not apply when specifying `code`. 319 FunctionVersion pulumi.StringPtrInput 320 // Maximum batching size for a resolver. Valid values are between `0` and `2000`. 321 MaxBatchSize pulumi.IntPtrInput 322 // Function name. The function name does not have to be unique. 323 Name pulumi.StringPtrInput 324 // Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template. 325 RequestMappingTemplate pulumi.StringPtrInput 326 // Function response mapping template. 327 ResponseMappingTemplate pulumi.StringPtrInput 328 // Describes a runtime used by an AWS AppSync pipeline resolver or AWS AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified. See Runtime. 329 Runtime FunctionRuntimePtrInput 330 // Describes a Sync configuration for a resolver. See Sync Config. 331 SyncConfig FunctionSyncConfigPtrInput 332 } 333 334 func (FunctionArgs) ElementType() reflect.Type { 335 return reflect.TypeOf((*functionArgs)(nil)).Elem() 336 } 337 338 type FunctionInput interface { 339 pulumi.Input 340 341 ToFunctionOutput() FunctionOutput 342 ToFunctionOutputWithContext(ctx context.Context) FunctionOutput 343 } 344 345 func (*Function) ElementType() reflect.Type { 346 return reflect.TypeOf((**Function)(nil)).Elem() 347 } 348 349 func (i *Function) ToFunctionOutput() FunctionOutput { 350 return i.ToFunctionOutputWithContext(context.Background()) 351 } 352 353 func (i *Function) ToFunctionOutputWithContext(ctx context.Context) FunctionOutput { 354 return pulumi.ToOutputWithContext(ctx, i).(FunctionOutput) 355 } 356 357 // FunctionArrayInput is an input type that accepts FunctionArray and FunctionArrayOutput values. 358 // You can construct a concrete instance of `FunctionArrayInput` via: 359 // 360 // FunctionArray{ FunctionArgs{...} } 361 type FunctionArrayInput interface { 362 pulumi.Input 363 364 ToFunctionArrayOutput() FunctionArrayOutput 365 ToFunctionArrayOutputWithContext(context.Context) FunctionArrayOutput 366 } 367 368 type FunctionArray []FunctionInput 369 370 func (FunctionArray) ElementType() reflect.Type { 371 return reflect.TypeOf((*[]*Function)(nil)).Elem() 372 } 373 374 func (i FunctionArray) ToFunctionArrayOutput() FunctionArrayOutput { 375 return i.ToFunctionArrayOutputWithContext(context.Background()) 376 } 377 378 func (i FunctionArray) ToFunctionArrayOutputWithContext(ctx context.Context) FunctionArrayOutput { 379 return pulumi.ToOutputWithContext(ctx, i).(FunctionArrayOutput) 380 } 381 382 // FunctionMapInput is an input type that accepts FunctionMap and FunctionMapOutput values. 383 // You can construct a concrete instance of `FunctionMapInput` via: 384 // 385 // FunctionMap{ "key": FunctionArgs{...} } 386 type FunctionMapInput interface { 387 pulumi.Input 388 389 ToFunctionMapOutput() FunctionMapOutput 390 ToFunctionMapOutputWithContext(context.Context) FunctionMapOutput 391 } 392 393 type FunctionMap map[string]FunctionInput 394 395 func (FunctionMap) ElementType() reflect.Type { 396 return reflect.TypeOf((*map[string]*Function)(nil)).Elem() 397 } 398 399 func (i FunctionMap) ToFunctionMapOutput() FunctionMapOutput { 400 return i.ToFunctionMapOutputWithContext(context.Background()) 401 } 402 403 func (i FunctionMap) ToFunctionMapOutputWithContext(ctx context.Context) FunctionMapOutput { 404 return pulumi.ToOutputWithContext(ctx, i).(FunctionMapOutput) 405 } 406 407 type FunctionOutput struct{ *pulumi.OutputState } 408 409 func (FunctionOutput) ElementType() reflect.Type { 410 return reflect.TypeOf((**Function)(nil)).Elem() 411 } 412 413 func (o FunctionOutput) ToFunctionOutput() FunctionOutput { 414 return o 415 } 416 417 func (o FunctionOutput) ToFunctionOutputWithContext(ctx context.Context) FunctionOutput { 418 return o 419 } 420 421 // ID of the associated AppSync API. 422 func (o FunctionOutput) ApiId() pulumi.StringOutput { 423 return o.ApplyT(func(v *Function) pulumi.StringOutput { return v.ApiId }).(pulumi.StringOutput) 424 } 425 426 // ARN of the Function object. 427 func (o FunctionOutput) Arn() pulumi.StringOutput { 428 return o.ApplyT(func(v *Function) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput) 429 } 430 431 // The function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS. 432 func (o FunctionOutput) Code() pulumi.StringPtrOutput { 433 return o.ApplyT(func(v *Function) pulumi.StringPtrOutput { return v.Code }).(pulumi.StringPtrOutput) 434 } 435 436 // Function data source name. 437 func (o FunctionOutput) DataSource() pulumi.StringOutput { 438 return o.ApplyT(func(v *Function) pulumi.StringOutput { return v.DataSource }).(pulumi.StringOutput) 439 } 440 441 // Function description. 442 func (o FunctionOutput) Description() pulumi.StringPtrOutput { 443 return o.ApplyT(func(v *Function) pulumi.StringPtrOutput { return v.Description }).(pulumi.StringPtrOutput) 444 } 445 446 // Unique ID representing the Function object. 447 func (o FunctionOutput) FunctionId() pulumi.StringOutput { 448 return o.ApplyT(func(v *Function) pulumi.StringOutput { return v.FunctionId }).(pulumi.StringOutput) 449 } 450 451 // Version of the request mapping template. Currently the supported value is `2018-05-29`. Does not apply when specifying `code`. 452 func (o FunctionOutput) FunctionVersion() pulumi.StringOutput { 453 return o.ApplyT(func(v *Function) pulumi.StringOutput { return v.FunctionVersion }).(pulumi.StringOutput) 454 } 455 456 // Maximum batching size for a resolver. Valid values are between `0` and `2000`. 457 func (o FunctionOutput) MaxBatchSize() pulumi.IntPtrOutput { 458 return o.ApplyT(func(v *Function) pulumi.IntPtrOutput { return v.MaxBatchSize }).(pulumi.IntPtrOutput) 459 } 460 461 // Function name. The function name does not have to be unique. 462 func (o FunctionOutput) Name() pulumi.StringOutput { 463 return o.ApplyT(func(v *Function) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput) 464 } 465 466 // Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template. 467 func (o FunctionOutput) RequestMappingTemplate() pulumi.StringPtrOutput { 468 return o.ApplyT(func(v *Function) pulumi.StringPtrOutput { return v.RequestMappingTemplate }).(pulumi.StringPtrOutput) 469 } 470 471 // Function response mapping template. 472 func (o FunctionOutput) ResponseMappingTemplate() pulumi.StringPtrOutput { 473 return o.ApplyT(func(v *Function) pulumi.StringPtrOutput { return v.ResponseMappingTemplate }).(pulumi.StringPtrOutput) 474 } 475 476 // Describes a runtime used by an AWS AppSync pipeline resolver or AWS AppSync function. Specifies the name and version of the runtime to use. Note that if a runtime is specified, code must also be specified. See Runtime. 477 func (o FunctionOutput) Runtime() FunctionRuntimePtrOutput { 478 return o.ApplyT(func(v *Function) FunctionRuntimePtrOutput { return v.Runtime }).(FunctionRuntimePtrOutput) 479 } 480 481 // Describes a Sync configuration for a resolver. See Sync Config. 482 func (o FunctionOutput) SyncConfig() FunctionSyncConfigPtrOutput { 483 return o.ApplyT(func(v *Function) FunctionSyncConfigPtrOutput { return v.SyncConfig }).(FunctionSyncConfigPtrOutput) 484 } 485 486 type FunctionArrayOutput struct{ *pulumi.OutputState } 487 488 func (FunctionArrayOutput) ElementType() reflect.Type { 489 return reflect.TypeOf((*[]*Function)(nil)).Elem() 490 } 491 492 func (o FunctionArrayOutput) ToFunctionArrayOutput() FunctionArrayOutput { 493 return o 494 } 495 496 func (o FunctionArrayOutput) ToFunctionArrayOutputWithContext(ctx context.Context) FunctionArrayOutput { 497 return o 498 } 499 500 func (o FunctionArrayOutput) Index(i pulumi.IntInput) FunctionOutput { 501 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Function { 502 return vs[0].([]*Function)[vs[1].(int)] 503 }).(FunctionOutput) 504 } 505 506 type FunctionMapOutput struct{ *pulumi.OutputState } 507 508 func (FunctionMapOutput) ElementType() reflect.Type { 509 return reflect.TypeOf((*map[string]*Function)(nil)).Elem() 510 } 511 512 func (o FunctionMapOutput) ToFunctionMapOutput() FunctionMapOutput { 513 return o 514 } 515 516 func (o FunctionMapOutput) ToFunctionMapOutputWithContext(ctx context.Context) FunctionMapOutput { 517 return o 518 } 519 520 func (o FunctionMapOutput) MapIndex(k pulumi.StringInput) FunctionOutput { 521 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Function { 522 return vs[0].(map[string]*Function)[vs[1].(string)] 523 }).(FunctionOutput) 524 } 525 526 func init() { 527 pulumi.RegisterInputType(reflect.TypeOf((*FunctionInput)(nil)).Elem(), &Function{}) 528 pulumi.RegisterInputType(reflect.TypeOf((*FunctionArrayInput)(nil)).Elem(), FunctionArray{}) 529 pulumi.RegisterInputType(reflect.TypeOf((*FunctionMapInput)(nil)).Elem(), FunctionMap{}) 530 pulumi.RegisterOutputType(FunctionOutput{}) 531 pulumi.RegisterOutputType(FunctionArrayOutput{}) 532 pulumi.RegisterOutputType(FunctionMapOutput{}) 533 }