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

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:

ApiId string

The ID of the associated AppSync API.

DataSource string

The Function DataSource name.

RequestMappingTemplate string

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

ResponseMappingTemplate string

The Function response mapping template.

Description string

The Function description.

FunctionVersion 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.

ApiId string

The ID of the associated AppSync API.

DataSource string

The Function DataSource name.

RequestMappingTemplate string

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

ResponseMappingTemplate string

The Function response mapping template.

Description string

The Function description.

FunctionVersion 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.

apiId string

The ID of the associated AppSync API.

dataSource string

The Function DataSource name.

requestMappingTemplate string

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

responseMappingTemplate string

The Function response mapping template.

description string

The Function description.

functionVersion 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_template str

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

response_mapping_template str

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:

Arn string

The ARN of the Function object.

FunctionId string

A unique ID representing the Function object.

Id string
The provider-assigned unique ID for this managed resource.
Arn string

The ARN of the Function object.

FunctionId string

A unique ID representing the Function object.

Id string
The provider-assigned unique ID for this managed resource.
arn string

The ARN of the Function object.

functionId string

A unique ID representing the Function object.

id string
The provider-assigned unique ID for this managed resource.
arn str

The ARN of the Function object.

function_id str

A unique ID representing the Function object.

id str
The provider-assigned unique ID for this managed resource.

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): Function
static 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:

ApiId string

The ID of the associated AppSync API.

Arn string

The ARN of the Function object.

DataSource string

The Function DataSource name.

Description string

The Function description.

FunctionId string

A unique ID representing the Function object.

FunctionVersion 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.

RequestMappingTemplate string

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

ResponseMappingTemplate string

The Function response mapping template.

ApiId string

The ID of the associated AppSync API.

Arn string

The ARN of the Function object.

DataSource string

The Function DataSource name.

Description string

The Function description.

FunctionId string

A unique ID representing the Function object.

FunctionVersion 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.

RequestMappingTemplate string

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

ResponseMappingTemplate string

The Function response mapping template.

apiId string

The ID of the associated AppSync API.

arn string

The ARN of the Function object.

dataSource string

The Function DataSource name.

description string

The Function description.

functionId string

A unique ID representing the Function object.

functionVersion 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.

requestMappingTemplate string

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

responseMappingTemplate string

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_template str

The Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.

response_mapping_template str

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 aws Terraform Provider.