FunctionType class

Provides an AppSync Function.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.appsync.GraphQLApi("example", {
    authenticationType: "API_KEY",
    name: "example",
    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 exampleDataSource = new aws.appsync.DataSource("example", {
    httpConfig: {
        endpoint: "http://example.com",
    },
    apiId: example.id,
    name: "example",
    type: "HTTP",
});
const exampleFunction = new aws.appsync.Function("example", {
    apiId: example.id,
    dataSource: exampleDataSource.name,
    name: "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
`,
});
import pulumi
import pulumi_aws as aws

example = aws.appsync.GraphQLApi("example",
    authentication_type="API_KEY",
    name="example",
    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
}
""")
example_data_source = aws.appsync.DataSource("example",
    http_config={
        "endpoint": "http://example.com",
    },
    api_id=example.id,
    name="example",
    type="HTTP")
example_function = aws.appsync.Function("example",
    api_id=example.id,
    data_source=example_data_source.name,
    name="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
""")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.AppSync.GraphQLApi("example", new()
    {
        AuthenticationType = "API_KEY",
        Name = "example",
        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 exampleDataSource = new Aws.AppSync.DataSource("example", new()
    {
        HttpConfig = new Aws.AppSync.Inputs.DataSourceHttpConfigArgs
        {
            Endpoint = "http://example.com",
        },
        ApiId = example.Id,
        Name = "example",
        Type = "HTTP",
    });

    var exampleFunction = new Aws.AppSync.Function("example", new()
    {
        ApiId = example.Id,
        DataSource = exampleDataSource.Name,
        Name = "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 (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/appsync"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := appsync.NewGraphQLApi(ctx, "example", &appsync.GraphQLApiArgs{
			AuthenticationType: pulumi.String("API_KEY"),
			Name:               pulumi.String("example"),
			Schema: pulumi.String(`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
}
`),
		})
		if err != nil {
			return err
		}
		exampleDataSource, err := appsync.NewDataSource(ctx, "example", &appsync.DataSourceArgs{
			HttpConfig: &appsync.DataSourceHttpConfigArgs{
				Endpoint: pulumi.String("http://example.com"),
			},
			ApiId: example.ID().ToIDOutput().ToStringOutput(),
			Name:  pulumi.String("example"),
			Type:  pulumi.String("HTTP"),
		})
		if err != nil {
			return err
		}
		_, err = appsync.NewFunction(ctx, "example", &appsync.FunctionArgs{
			ApiId:      example.ID().ToIDOutput().ToStringOutput(),
			DataSource: exampleDataSource.Name,
			Name:       pulumi.String("example"),
			RequestMappingTemplate: pulumi.String(`{
    \"version\": \"2018-05-29\",
    \"method\": \"GET\",
    \"resourcePath\": \"/\",
    \"params\":{
        \"headers\": $utils.http.copyheaders($ctx.request.headers)
    }
}
`),
			ResponseMappingTemplate: pulumi.String(`#if($ctx.result.statusCode == 200)
    $ctx.result.body
#else
    $utils.appendError($ctx.result.body, $ctx.result.statusCode)
#end
`),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_appsync_graphqlapi" "example" {
  authentication_type = "API_KEY"
  name                = "example"
  schema              = "type Mutation {\n  putPost(id: ID!, title: String!): Post\n}\n\ntype Post {\n  id: ID!\n  title: String!\n}\n\ntype Query {\n  singlePost(id: ID!): Post\n}\n\nschema {\n  query: Query\n  mutation: Mutation\n}\n"
}
resource "aws_appsync_datasource" "example" {
  http_config = {
    endpoint = "http://example.com"
  }
  api_id = aws_appsync_graphqlapi.example.id
  name   = "example"
  type   = "HTTP"
}
resource "aws_appsync_function" "example" {
  api_id                    = aws_appsync_graphqlapi.example.id
  data_source               = aws_appsync_datasource.example.name
  name                      = "example"
  request_mapping_template  = "{\n    \\\"version\\\": \\\"2018-05-29\\\",\n    \\\"method\\\": \\\"GET\\\",\n    \\\"resourcePath\\\": \\\"/\\\",\n    \\\"params\\\":{\n        \\\"headers\\\": $utils.http.copyheaders($ctx.request.headers)\n    }\n}\n"
  response_mapping_template = "#if($ctx.result.statusCode == 200)\n    $ctx.result.body\n#else\n    $utils.appendError($ctx.result.body, $ctx.result.statusCode)\n#end\n"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.appsync.GraphQLApi;
import com.pulumi.aws.appsync.GraphQLApiArgs;
import com.pulumi.aws.appsync.DataSource;
import com.pulumi.aws.appsync.DataSourceArgs;
import com.pulumi.aws.appsync.inputs.DataSourceHttpConfigArgs;
import com.pulumi.aws.appsync.Function;
import com.pulumi.aws.appsync.FunctionArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new GraphQLApi("example", GraphQLApiArgs.builder()
            .authenticationType("API_KEY")
            .name("example")
            .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
}
            """)
            .build());

        var exampleDataSource = new DataSource("exampleDataSource", DataSourceArgs.builder()
            .httpConfig(DataSourceHttpConfigArgs.builder()
                .endpoint("http://example.com")
                .build())
            .apiId(example.id())
            .name("example")
            .type("HTTP")
            .build());

        var exampleFunction = new Function("exampleFunction", FunctionArgs.builder()
            .apiId(example.id())
            .dataSource(exampleDataSource.name())
            .name("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
            """)
            .build());

    }
}
resources:
  example:
    type: aws:appsync:GraphQLApi
    properties:
      authenticationType: API_KEY
      name: example
      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
        }
  exampleDataSource:
    type: aws:appsync:DataSource
    name: example
    properties:
      httpConfig:
        endpoint: http://example.com
      apiId: ${example.id}
      name: example
      type: HTTP
  exampleFunction:
    type: aws:appsync:Function
    name: example
    properties:
      apiId: ${example.id}
      dataSource: ${exampleDataSource.name}
      name: 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

Example Usage With Code

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";

const example = new aws.appsync.Function("example", {
    runtime: {
        name: "APPSYNC_JS",
        runtimeVersion: "1.0.0",
    },
    apiId: exampleAwsAppsyncGraphqlApi.id,
    dataSource: exampleAwsAppsyncDatasource.name,
    name: "example",
    code: std.file({
        input: "some-code-dir",
    }).then(invoke => invoke.result),
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std

example = aws.appsync.Function("example",
    runtime={
        "name": "APPSYNC_JS",
        "runtime_version": "1.0.0",
    },
    api_id=example_aws_appsync_graphql_api["id"],
    data_source=example_aws_appsync_datasource["name"],
    name="example",
    code=std.file(input="some-code-dir").result)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.AppSync.Function("example", new()
    {
        Runtime = new Aws.AppSync.Inputs.FunctionRuntimeArgs
        {
            Name = "APPSYNC_JS",
            RuntimeVersion = "1.0.0",
        },
        ApiId = exampleAwsAppsyncGraphqlApi.Id,
        DataSource = exampleAwsAppsyncDatasource.Name,
        Name = "example",
        Code = Std.File.Invoke(new()
        {
            Input = "some-code-dir",
        }).Apply(invoke => invoke.Result),
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/appsync"
	"github.com/pulumi/pulumi-std/sdk/go/std"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		invokeFile, err := std.File(ctx, &std.FileArgs{
			Input: "some-code-dir",
		}, nil)
		if err != nil {
			return err
		}
		_, err = appsync.NewFunction(ctx, "example", &appsync.FunctionArgs{
			Runtime: &appsync.FunctionRuntimeArgs{
				Name:           pulumi.String("APPSYNC_JS"),
				RuntimeVersion: pulumi.String("1.0.0"),
			},
			ApiId:      pulumi.Any(exampleAwsAppsyncGraphqlApi.Id),
			DataSource: pulumi.Any(exampleAwsAppsyncDatasource.Name),
			Name:       pulumi.String("example"),
			Code:       pulumi.String(invokeFile.Result),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
    std = {
      source = "pulumi/std"
    }
  }
}

resource "aws_appsync_function" "example" {
  runtime = {
    name            = "APPSYNC_JS"
    runtime_version = "1.0.0"
  }
  api_id      = exampleAwsAppsyncGraphqlApi.id
  data_source = exampleAwsAppsyncDatasource.name
  name        = "example"
  code        = file("some-code-dir")
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.appsync.Function;
import com.pulumi.aws.appsync.FunctionArgs;
import com.pulumi.aws.appsync.inputs.FunctionRuntimeArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.FileArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new Function("example", FunctionArgs.builder()
            .runtime(FunctionRuntimeArgs.builder()
                .name("APPSYNC_JS")
                .runtimeVersion("1.0.0")
                .build())
            .apiId(exampleAwsAppsyncGraphqlApi.id())
            .dataSource(exampleAwsAppsyncDatasource.name())
            .name("example")
            .code(StdFunctions.file(FileArgs.builder()
                .input("some-code-dir")
                .build()).result())
            .build());

    }
}
resources:
  example:
    type: aws:appsync:Function
    properties:
      runtime:
        name: APPSYNC_JS
        runtimeVersion: 1.0.0
      apiId: ${exampleAwsAppsyncGraphqlApi.id}
      dataSource: ${exampleAwsAppsyncDatasource.name}
      name: example
      code:
        fn::invoke:
          function: std:file
          arguments:
            input: some-code-dir
          return: result

Import

Using pulumi import, import aws.appsync.Function using the AppSync API ID and Function ID separated by -. For example:

$ pulumi import aws:appsync/function:Function example xxxxx-yyyyy

Constructors

FunctionType(String name, {FunctionArgs? args, CustomResourceOptions? options})
Creates a new FunctionType. name The Pulumi resource name. args Arguments used to configure this FunctionType. The set of arguments for Function. options Resource options controlling this resource's behavior.
FunctionType.reference(String urn)
Creates a typed reference to an existing FunctionType resource.

Properties

apiId ↔ Output<String>
ID of the associated AppSync API.
latefinal
arn ↔ Output<String>
ARN of the Function object.
latefinal
childResources → Set<Resource>
finalinherited
code ↔ Output<String?>
Function code that contains the request and response functions. When code is used, the runtime is required. The runtime value must be APPSYNC_JS.
latefinal
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
dataSource ↔ Output<String>
Function data source name.
latefinal
description ↔ Output<String?>
Function description.
latefinal
functionId ↔ Output<String>
Unique ID representing the Function object.
latefinal
functionVersion ↔ Output<String>
Version of the request mapping template. Currently the supported value is 2018-05-29. Does not apply when specifying code.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
maxBatchSize ↔ Output<int?>
Maximum batching size for a resolver. Valid values are between 0 and 2000.
latefinal
name ↔ Output<String>
Function name. The function name does not have to be unique.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
requestMappingTemplate ↔ Output<String?>
Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
responseMappingTemplate ↔ Output<String?>
Function response mapping template.
latefinal
runtime ↔ Output<FunctionRuntime?>
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 Block for details.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
syncConfig ↔ Output<FunctionSyncConfig?>
Sync configuration for a resolver. See syncConfig Block for details.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {FunctionState? state, CustomResourceOptions? options}) → FunctionType
Gets an existing FunctionType resource's state with the given name and id.