Resource: aws_appsync_function

Provides an AppSync Function.

Example Usage

resource "aws_appsync_graphql_api" "example" {
  authentication_type = "API_KEY"
  name                = "example"
  schema              = <<EOF
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
}
EOF
}

resource "aws_appsync_datasource" "example" {
  api_id = aws_appsync_graphql_api.example.id
  name   = "example"
  type   = "HTTP"

  http_config {
    endpoint = "http://example.com"
  }
}

resource "aws_appsync_function" "example" {
  api_id                   = aws_appsync_graphql_api.example.id
  data_source              = aws_appsync_datasource.example.name
  name                     = "example"
  request_mapping_template = <<EOF
{
    "version": "2018-05-29",
    "method": "GET",
    "resourcePath": "/",
    "params":{
        "headers": $utils.http.copyheaders($ctx.request.headers)
    }
}
EOF

  response_mapping_template = <<EOF
#if($ctx.result.statusCode == 200)
    $ctx.result.body
#else
    $utils.appendError($ctx.result.body, $ctx.result.statusCode)
#end
EOF
}

Example Usage With Code

resource "aws_appsync_function" "example" {
  api_id      = aws_appsync_graphql_api.example.id
  data_source = aws_appsync_datasource.example.name
  name        = "example"
  code        = file("some-code-dir")

  runtime {
    name            = "APPSYNC_JS"
    runtime_version = "1.0.0"
  }
}

Argument Reference

This resource supports the following arguments:

Runtime

This argument supports the following arguments:

Sync Config

This argument supports the following arguments:

Lambda Conflict Handler Config

This argument supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import aws_appsync_function using the AppSync API ID and Function ID separated by -. For example:

import {
  to = aws_appsync_function.example
  id = "xxxxx-yyyyy"
}

Using terraform import, import aws_appsync_function using the AppSync API ID and Function ID separated by -. For example:

% terraform import aws_appsync_function.example xxxxx-yyyyy