Skip to content
GitHubXDiscord

Stage

The Stage resource allows you to manage AWS ApiGateway Stages for your API deployments, enabling you to define different environments like development, testing, and production.

Create a basic ApiGateway Stage with required properties and a description.

import AWS from "alchemy/aws/control";
const apiStage = await AWS.ApiGateway.Stage("myApiStage", {
RestApiId: "1234567890",
StageName: "dev",
Description: "Development stage for testing new features"
});

Configure a stage with additional settings like method settings and tracing enabled for better monitoring.

const advancedApiStage = await AWS.ApiGateway.Stage("advancedApiStage", {
RestApiId: "1234567890",
StageName: "prod",
Description: "Production stage with enhanced monitoring",
TracingEnabled: true,
MethodSettings: [{
HttpMethod: "*",
ResourceId: "abcdef1234",
ThrottlingBurstLimit: 100,
ThrottlingRateLimit: 50
}]
});

Set up a stage with canary release settings to gradually deploy changes.

const canaryApiStage = await AWS.ApiGateway.Stage("canaryApiStage", {
RestApiId: "1234567890",
StageName: "canary",
DeploymentId: "deployment123",
CanarySetting: {
PercentTraffic: 10,
StageVariableOverrides: {
"newFeatureEnabled": "true"
}
}
});

Enable access logging for the stage to monitor API requests.

const loggingApiStage = await AWS.ApiGateway.Stage("loggingApiStage", {
RestApiId: "1234567890",
StageName: "prod",
AccessLogSetting: {
DestinationArn: "arn:aws:logs:us-west-2:123456789012:log-group:my-api-logs",
Format: "${context.requestId} - ${context.identity.sourceIp} - ${context.httpMethod} ${context.path}"
}
});