AWS AppSync API Key

This page shows how to write Terraform and CloudFormation for AWS AppSync API Key and write them securely.

aws_appsync_api_key (Terraform)

The API Key in AWS AppSync can be configured in Terraform with the resource name aws_appsync_api_key. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L1
resource "aws_appsync_api_key" "api_key" {
  count       = length(var.api_key)
  api_id      = element(var.api_id, lookup(var.api_key[count.index], "api_id"))
  description = lookup(var.api_key[count.index], "description")
  expires     = lookup(var.api_key[count.index], "expires")
appsync_api_key.tf#L4
resource "aws_appsync_api_key" "appsync_api_key" {
  count = var.enable_appsync_api_key ? 1 : 0

  api_id = var.appsync_api_key_api_id != "" && !var.enable_appsync_graphql_api ? lower(var.appsync_api_key_api_id) : element(concat(aws_appsync_graphql_api.appsync_graphql_api.*.id, [""]), 0)

  description = var.appsync_api_key_description
appsync_api_key.tf#L4
resource "aws_appsync_api_key" "appsync_api_key" {
  count = var.enable_appsync_api_key ? 1 : 0

  api_id = var.appsync_api_key_api_id != "" && !var.enable_appsync_graphql_api ? lower(var.appsync_api_key_api_id) : element(concat(aws_appsync_graphql_api.appsync_graphql_api.*.id, [""]), 0)

  description = var.appsync_api_key_description
main.tf#L13
resource "aws_appsync_api_key" "main_key" {
  api_id  = aws_appsync_graphql_api.main.id
}

resource "aws_iam_role_policy_attachment" "logs" {
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs"
aws_appsync_api_key.tf#L1
resource "aws_appsync_api_key" "example" {
  api_id  = aws_appsync_graphql_api.example.id
  expires = "2020-12-31T23:00:00Z"
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an AppSync API Key.

AWS::AppSync::ApiKey (CloudFormation)

The ApiKey in AppSync can be configured in CloudFormation with the resource name AWS::AppSync::ApiKey. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

Explanation in CloudFormation Registry

The AWS::AppSync::ApiKey resource creates a unique key that you can distribute to clients who are executing GraphQL operations with AWS AppSync that require an API key.

Frequently asked questions

What is AWS AppSync API Key?

AWS AppSync API Key is a resource for AppSync of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS AppSync API Key?

For Terraform, the mikamakusa/terraform, asrkata/SebastianUA-terraform and SebastianUA/terraform source code examples are useful. See the Terraform Example section for further details.