AWS API Gateway V2 Deployment

This page shows how to write Terraform and CloudFormation for API Gateway V2 Deployment and write them securely.

aws_apigatewayv2_deployment (Terraform)

The Deployment in API Gateway V2 can be configured in Terraform with the resource name aws_apigatewayv2_deployment. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L7
resource "aws_apigatewayv2_deployment" "this" {
  api_id      = var.api_id
  description = var.description
  triggers    = var.triggers
}

api-gateway.tf#L1
resource "aws_apigatewayv2_deployment" "deployment" {
  api_id      = aws_apigatewayv2_api.api.id
  description = local.apigw_resource_name

  triggers = {
    redeployment = sha1(join(",", list(
aws_apigatewayv2_deployment.tf#L1
resource "aws_apigatewayv2_deployment" "Deployment" {
  api_id = aws_apigatewayv2_api.ppoker_websocket_api.id

  depends_on = [
    aws_apigatewayv2_route.connect_route,
    aws_apigatewayv2_route.disconnect_route,

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

Manages an Amazon API Gateway Version 2 deployment. More information can be found in the Amazon API Gateway Developer Guide. -> Note: Creating a deployment for an API requires at least one aws_apigatewayv2_route resource associated with that API. To avoid race conditions when all resources are being created together, you need to add implicit resource references via the triggers argument or explicit resource references using the resource depends_on meta-argument. -> It is recommended to enable the resource lifecycle configuration block create_before_destroy argument in this resource configuration to properly order redeployments in Terraform.

AWS::ApiGatewayV2::Deployment (CloudFormation)

The Deployment in ApiGatewayV2 can be configured in CloudFormation with the resource name AWS::ApiGatewayV2::Deployment. The following sections describe 1 example of how to use the resource and its parameters.

Example Usage from GitHub

AWS_ApiGatewayV2_DeploymentResource.schema.json#L15
      "default" : "AWS::ApiGatewayV2::Deployment"
    },
    "Properties" : {
      "$ref" : "AWS_ApiGatewayV2_Deployment.schema.json"
    }
  }

Parameters

Explanation in CloudFormation Registry

The AWS::ApiGatewayV2::Deployment resource creates a deployment for an API.

Frequently asked questions

What is AWS API Gateway V2 Deployment?

AWS API Gateway V2 Deployment is a resource for API Gateway V2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS API Gateway V2 Deployment?

For Terraform, the niveklabs/aws, saragerion/serverless-voting-app and paveg/ppoker source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the shiver-me-timbers/smt-cloudformation-parent source code example is useful. See the CloudFormation Example section for further details.