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
resource "aws_apigatewayv2_deployment" "this" {
api_id = var.api_id
description = var.description
triggers = var.triggers
}
resource "aws_apigatewayv2_deployment" "deployment" {
api_id = aws_apigatewayv2_api.api.id
description = local.apigw_resource_name
triggers = {
redeployment = sha1(join(",", list(
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,
Parameters
-
api_id
required - string -
auto_deployed
optional computed - bool -
description
optional - string -
id
optional computed - string -
triggers
optional - map from string to string
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 thetriggers
argument or explicit resource references using the resourcedepends_on
meta-argument. -> It is recommended to enable the resourcelifecycle
configuration blockcreate_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
"default" : "AWS::ApiGatewayV2::Deployment"
},
"Properties" : {
"$ref" : "AWS_ApiGatewayV2_Deployment.schema.json"
}
}
Parameters
-
Description
optional - String -
StageName
optional - String -
ApiId
required - String
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.