Function
Provides an AppSync Function.
Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var testGraphQLApi = new Aws.AppSync.GraphQLApi("testGraphQLApi", new Aws.AppSync.GraphQLApiArgs
{
AuthenticationType = "API_KEY",
Schema = @"type Mutation {
putPost(id: ID!, title: String!): Post
}
type Post {
id: ID!
title: String!
}
type Query {
singlePost(id: ID!): Post
}
schema {
query: Query
mutation: Mutation
}
",
});
var testDataSource = new Aws.AppSync.DataSource("testDataSource", new Aws.AppSync.DataSourceArgs
{
ApiId = testGraphQLApi.Id,
HttpConfig = new Aws.AppSync.Inputs.DataSourceHttpConfigArgs
{
Endpoint = "http://example.com",
},
Type = "HTTP",
});
var testFunction = new Aws.AppSync.Function("testFunction", new Aws.AppSync.FunctionArgs
{
ApiId = testGraphQLApi.Id,
DataSource = testDataSource.Name,
Name = "tf_example",
RequestMappingTemplate = @"{
""version"": ""2018-05-29"",
""method"": ""GET"",
""resourcePath"": ""/"",
""params"":{
""headers"": $utils.http.copyheaders($ctx.request.headers)
}
}
",
ResponseMappingTemplate = @"#if($ctx.result.statusCode == 200)
$ctx.result.body
#else
$utils.appendError($ctx.result.body, $ctx.result.statusCode)
#end
",
});
}
}
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/appsync"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
testGraphQLApi, err := appsync.NewGraphQLApi(ctx, "testGraphQLApi", &appsync.GraphQLApiArgs{
AuthenticationType: pulumi.String("API_KEY"),
Schema: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "type Mutation {\n", " putPost(id: ID!, title: String!): Post\n", "}\n", "\n", "type Post {\n", " id: ID!\n", " title: String!\n", "}\n", "\n", "type Query {\n", " singlePost(id: ID!): Post\n", "}\n", "\n", "schema {\n", " query: Query\n", " mutation: Mutation\n", "}\n", "\n")),
})
if err != nil {
return err
}
testDataSource, err := appsync.NewDataSource(ctx, "testDataSource", &appsync.DataSourceArgs{
ApiId: testGraphQLApi.ID(),
HttpConfig: &appsync.DataSourceHttpConfigArgs{
Endpoint: pulumi.String("http://example.com"),
},
Type: pulumi.String("HTTP"),
})
if err != nil {
return err
}
_, err = appsync.NewFunction(ctx, "testFunction", &appsync.FunctionArgs{
ApiId: testGraphQLApi.ID(),
DataSource: testDataSource.Name,
Name: pulumi.String("tf_example"),
RequestMappingTemplate: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"version\": \"2018-05-29\",\n", " \"method\": \"GET\",\n", " \"resourcePath\": \"/\",\n", " \"params\":{\n", " \"headers\": ", "$", "utils.http.copyheaders(", "$", "ctx.request.headers)\n", " }\n", "}\n", "\n")),
ResponseMappingTemplate: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "#if(", "$", "ctx.result.statusCode == 200)\n", " ", "$", "ctx.result.body\n", "#else\n", " ", "$", "utils.appendError(", "$", "ctx.result.body, ", "$", "ctx.result.statusCode)\n", "#end\n", "\n")),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
test_graph_ql_api = aws.appsync.GraphQLApi("testGraphQLApi",
authentication_type="API_KEY",
schema="""type Mutation {
putPost(id: ID!, title: String!): Post
}
type Post {
id: ID!
title: String!
}
type Query {
singlePost(id: ID!): Post
}
schema {
query: Query
mutation: Mutation
}
""")
test_data_source = aws.appsync.DataSource("testDataSource",
api_id=test_graph_ql_api.id,
http_config={
"endpoint": "http://example.com",
},
type="HTTP")
test_function = aws.appsync.Function("testFunction",
api_id=test_graph_ql_api.id,
data_source=test_data_source.name,
name="tf_example",
request_mapping_template="""{
"version": "2018-05-29",
"method": "GET",
"resourcePath": "/",
"params":{
"headers": $utils.http.copyheaders($ctx.request.headers)
}
}
""",
response_mapping_template="""#if($ctx.result.statusCode == 200)
$ctx.result.body
#else
$utils.appendError($ctx.result.body, $ctx.result.statusCode)
#end
""")import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const testGraphQLApi = new aws.appsync.GraphQLApi("test", {
authenticationType: "API_KEY",
schema: `type Mutation {
putPost(id: ID!, title: String!): Post
}
type Post {
id: ID!
title: String!
}
type Query {
singlePost(id: ID!): Post
}
schema {
query: Query
mutation: Mutation
}
`,
});
const testDataSource = new aws.appsync.DataSource("test", {
apiId: testGraphQLApi.id,
httpConfig: {
endpoint: "http://example.com",
},
type: "HTTP",
});
const testFunction = new aws.appsync.Function("test", {
apiId: testGraphQLApi.id,
dataSource: testDataSource.name,
name: "tf_example",
requestMappingTemplate: `{
"version": "2018-05-29",
"method": "GET",
"resourcePath": "/",
"params":{
"headers": $utils.http.copyheaders($ctx.request.headers)
}
}
`,
responseMappingTemplate: `#if($ctx.result.statusCode == 200)
$ctx.result.body
#else
$utils.appendError($ctx.result.body, $ctx.result.statusCode)
#end
`,
});Create a Function Resource
new Function(name: string, args: FunctionArgs, opts?: CustomResourceOptions);def Function(resource_name, opts=None, api_id=None, data_source=None, description=None, function_version=None, name=None, request_mapping_template=None, response_mapping_template=None, __props__=None);func NewFunction(ctx *Context, name string, args FunctionArgs, opts ...ResourceOption) (*Function, error)public Function(string name, FunctionArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args FunctionArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args FunctionArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args FunctionArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
Function Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The Function resource accepts the following input properties:
- Api
Id string The ID of the associated AppSync API.
- Data
Source string The Function DataSource name.
- Request
Mapping stringTemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- Response
Mapping stringTemplate The Function response mapping template.
- Description string
The Function description.
- Function
Version string The version of the request mapping template. Currently the supported value is
2018-05-29.- Name string
The Function name. The function name does not have to be unique.
- Api
Id string The ID of the associated AppSync API.
- Data
Source string The Function DataSource name.
- Request
Mapping stringTemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- Response
Mapping stringTemplate The Function response mapping template.
- Description string
The Function description.
- Function
Version string The version of the request mapping template. Currently the supported value is
2018-05-29.- Name string
The Function name. The function name does not have to be unique.
- api
Id string The ID of the associated AppSync API.
- data
Source string The Function DataSource name.
- request
Mapping stringTemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- response
Mapping stringTemplate The Function response mapping template.
- description string
The Function description.
- function
Version string The version of the request mapping template. Currently the supported value is
2018-05-29.- name string
The Function name. The function name does not have to be unique.
- api_
id str The ID of the associated AppSync API.
- data_
source str The Function DataSource name.
- request_
mapping_ strtemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- response_
mapping_ strtemplate The Function response mapping template.
- description str
The Function description.
- function_
version str The version of the request mapping template. Currently the supported value is
2018-05-29.- name str
The Function name. The function name does not have to be unique.
Outputs
All input properties are implicitly available as output properties. Additionally, the Function resource produces the following output properties:
Look up an Existing Function Resource
Get an existing Function 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?: FunctionState, opts?: CustomResourceOptions): Functionstatic get(resource_name, id, opts=None, api_id=None, arn=None, data_source=None, description=None, function_id=None, function_version=None, name=None, request_mapping_template=None, response_mapping_template=None, __props__=None);func GetFunction(ctx *Context, name string, id IDInput, state *FunctionState, opts ...ResourceOption) (*Function, error)public static Function Get(string name, Input<string> id, FunctionState? state, CustomResourceOptions? opts = null)- 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.
The following state arguments are supported:
- Api
Id string The ID of the associated AppSync API.
- Arn string
The ARN of the Function object.
- Data
Source string The Function DataSource name.
- Description string
The Function description.
- Function
Id string A unique ID representing the Function object.
- Function
Version string The version of the request mapping template. Currently the supported value is
2018-05-29.- Name string
The Function name. The function name does not have to be unique.
- Request
Mapping stringTemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- Response
Mapping stringTemplate The Function response mapping template.
- Api
Id string The ID of the associated AppSync API.
- Arn string
The ARN of the Function object.
- Data
Source string The Function DataSource name.
- Description string
The Function description.
- Function
Id string A unique ID representing the Function object.
- Function
Version string The version of the request mapping template. Currently the supported value is
2018-05-29.- Name string
The Function name. The function name does not have to be unique.
- Request
Mapping stringTemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- Response
Mapping stringTemplate The Function response mapping template.
- api
Id string The ID of the associated AppSync API.
- arn string
The ARN of the Function object.
- data
Source string The Function DataSource name.
- description string
The Function description.
- function
Id string A unique ID representing the Function object.
- function
Version string The version of the request mapping template. Currently the supported value is
2018-05-29.- name string
The Function name. The function name does not have to be unique.
- request
Mapping stringTemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- response
Mapping stringTemplate The Function response mapping template.
- api_
id str The ID of the associated AppSync API.
- arn str
The ARN of the Function object.
- data_
source str The Function DataSource name.
- description str
The Function description.
- function_
id str A unique ID representing the Function object.
- function_
version str The version of the request mapping template. Currently the supported value is
2018-05-29.- name str
The Function name. The function name does not have to be unique.
- request_
mapping_ strtemplate The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
- response_
mapping_ strtemplate The Function response mapping template.
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.