Skip to content
GitHubXDiscord

Stage

The Stage resource lets you manage AWS ApiGatewayV2 Stages and their configurations for API deployments.

Create a basic stage with required properties and a common optional property.

import AWS from "alchemy/aws/control";
const apiGatewayStage = await AWS.ApiGatewayV2.Stage("myApiStage", {
ApiId: "abc1234xyz",
StageName: "production",
Description: "Production stage for the API",
AutoDeploy: true
});

Configure a stage with logging settings and stage variables.

const advancedStage = await AWS.ApiGatewayV2.Stage("advancedApiStage", {
ApiId: "abc1234xyz",
StageName: "development",
Description: "Development stage with detailed logging",
AccessLogSettings: {
DestinationArn: "arn:aws:logs:us-west-2:123456789012:log-group:/aws/apigateway/myApiLogGroup",
Format: "$context.identity.sourceIp - $context.requestId"
},
StageVariables: {
"version": "1.0",
"featureFlag": "true"
}
});

Create a stage with custom route settings to fine-tune API behavior.

const customRouteStage = await AWS.ApiGatewayV2.Stage("customRouteStage", {
ApiId: "abc1234xyz",
StageName: "custom",
RouteSettings: [{
RouteId: "route123",
DataTraceEnabled: true,
DetailedMetricsEnabled: true
}]
});

Define an access policy that restricts access to specific IP addresses.

const accessPolicyStage = await AWS.ApiGatewayV2.Stage("policyStage", {
ApiId: "abc1234xyz",
StageName: "secured",
AccessPolicyId: "policyId123",
Tags: {
"Environment": "production",
"Department": "engineering"
}
});