Resource: awsAppsyncFunction
Provides an AppSync Function.
Example Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsAppsyncGraphqlApiExample = new aws.appsyncGraphqlApi.AppsyncGraphqlApi(
this,
"example",
{
authenticationType: "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",
}
);
const awsAppsyncDatasourceExample = new aws.appsyncDatasource.AppsyncDatasource(
this,
"example_1",
{
apiId: awsAppsyncGraphqlApiExample.id,
httpConfig: {
endpoint: "http://example.com",
},
name: "example",
type: "HTTP",
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAppsyncDatasourceExample.overrideLogicalId("example");
const awsAppsyncFunctionExample = new aws.appsyncFunction.AppsyncFunction(
this,
"example_2",
{
apiId: awsAppsyncGraphqlApiExample.id,
dataSource: awsAppsyncDatasourceExample.name,
name: "example",
requestMappingTemplate:
'{\n "version": "2018-05-29",\n "method": "GET",\n "resourcePath": "/",\n "params":{\n "headers": $utils.http.copyheaders($ctx.request.headers)\n }\n}\n',
responseMappingTemplate:
"#if($ctx.result.statusCode == 200)\n $ctx.result.body\n#else\n $utils.appendError($ctx.result.body, $ctx.result.statusCode)\n#end\n",
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAppsyncFunctionExample.overrideLogicalId("example");
Example Usage With Code
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.appsyncFunction.AppsyncFunction(this, "example", {
apiId: "${aws_appsync_graphql_api.example.id}",
code: '${file("some-code-dir")}',
dataSource: "${aws_appsync_datasource.example.name}",
name: "example",
runtime: {
name: "APPSYNC_JS",
runtimeVersion: "1.0.0",
},
});
Argument Reference
The following arguments are supported:
apiId
- (Required) ID of the associated AppSync API.code
- (Optional) 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.dataSource
- (Required) Function data source name.maxBatchSize
- (Optional) Maximum batching size for a resolver. Valid values are between0
and2000
.name
- (Required) Function name. The function name does not have to be unique.requestMappingTemplate
- (Optional) Function request mapping template. Functions support only the 2018-05-29 version of the request mapping template.responseMappingTemplate
- (Optional) Function response mapping template.description
- (Optional) Function description.runtime
- (Optional) 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.syncConfig
- (Optional) Describes a Sync configuration for a resolver. See Sync Config.functionVersion
- (Optional) Version of the request mapping template. Currently the supported value is20180529
. Does not apply when specifyingcode
.
Runtime
The following arguments are supported:
name
- (Optional) The name of the runtime to use. Currently, the only allowed value isAPPSYNC_JS
.runtimeVersion
- (Optional) The version of the runtime to use. Currently, the only allowed version is100
.
Sync Config
The following arguments are supported:
conflictDetection
- (Optional) Conflict Detection strategy to use. Valid values arenone
andversion
.conflictHandler
- (Optional) Conflict Resolution strategy to perform in the event of a conflict. Valid values arenone
,OPTIMISTIC_CONCURRENCY
,automerge
, andlambda
.lambdaConflictHandlerConfig
- (Optional) Lambda Conflict Handler Config when configuringlambda
as the Conflict Handler. See Lambda Conflict Handler Config.
Lambda Conflict Handler Config
The following arguments are supported:
lambdaConflictHandlerArn
- (Optional) ARN for the Lambda function to use as the Conflict Handler.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
id
- API Function ID (Formatted as ApiId-FunctionId)arn
- ARN of the Function object.functionId
- Unique ID representing the Function object.
Import
awsAppsyncFunction
can be imported using the AppSync API ID and Function ID separated by -
, e.g.,