aws-cdk-lib.aws_apigateway.Stage

class Stage (construct)

LanguageType name
.NETAmazon.CDK.AWS.APIGateway.Stage
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#Stage
Javasoftware.amazon.awscdk.services.apigateway.Stage
Pythonaws_cdk.aws_apigateway.Stage
TypeScript (source)aws-cdk-lib » aws_apigateway » Stage

Implements IConstruct, IDependable, IResource, IStage

Example

// production stage
const prdLogGroup = new logs.LogGroup(this, "PrdLogs");
const api = new apigateway.RestApi(this, 'books', {
  deployOptions: {
    accessLogDestination: new apigateway.LogGroupLogDestination(prdLogGroup),
    accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields(),
  },
});
const deployment = new apigateway.Deployment(this, 'Deployment', {api});

// development stage
const devLogGroup = new logs.LogGroup(this, "DevLogs");
new apigateway.Stage(this, 'dev', {
  deployment,
  accessLogDestination: new apigateway.LogGroupLogDestination(devLogGroup),
  accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields({
    caller: false,
    httpMethod: true,
    ip: true,
    protocol: true,
    requestTime: true,
    resourcePath: true,
    responseLength: true,
    status: true,
    user: true,
  }),
});

Initializer

new Stage(scope: Construct, id: string, props: StageProps)

Parameters

  • scope Construct
  • id string
  • props StageProps

Construct Props

NameTypeDescription
deploymentDeploymentThe deployment that this stage points to [disable-awslint:ref-via-interface].
accessLogDestination?IAccessLogDestinationThe CloudWatch Logs log group.
accessLogFormat?AccessLogFormatA single line format of access logs of data, as specified by selected $content variables.
cacheClusterEnabled?booleanIndicates whether cache clustering is enabled for the stage.
cacheClusterSize?stringThe stage's cache cluster size.
cacheDataEncrypted?booleanIndicates whether the cached responses are encrypted.
cacheTtl?DurationSpecifies the time to live (TTL), in seconds, for cached responses.
cachingEnabled?booleanSpecifies whether responses should be cached and returned for requests.
clientCertificateId?stringThe identifier of the client certificate that API Gateway uses to call your integration endpoints in the stage.
dataTraceEnabled?booleanSpecifies whether data trace logging is enabled for this method.
description?stringA description of the purpose of the stage.
documentationVersion?stringThe version identifier of the API documentation snapshot.
loggingLevel?MethodLoggingLevelSpecifies the logging level for this method, which effects the log entries pushed to Amazon CloudWatch Logs.
methodOptions?{ [string]: MethodDeploymentOptions }Method deployment options for specific resources/methods.
metricsEnabled?booleanSpecifies whether Amazon CloudWatch metrics are enabled for this method.
stageName?stringThe name of the stage, which API Gateway uses as the first path segment in the invoked Uniform Resource Identifier (URI).
throttlingBurstLimit?numberSpecifies the throttling burst limit.
throttlingRateLimit?numberSpecifies the throttling rate limit.
tracingEnabled?booleanSpecifies whether Amazon X-Ray tracing is enabled for this method.
variables?{ [string]: string }A map that defines the stage variables.

deployment

Type: Deployment

The deployment that this stage points to [disable-awslint:ref-via-interface].


accessLogDestination?

Type: IAccessLogDestination (optional, default: No destination)

The CloudWatch Logs log group.


accessLogFormat?

Type: AccessLogFormat (optional, default: Common Log Format)

A single line format of access logs of data, as specified by selected $content variables.

The format must include either AccessLogFormat.contextRequestId() or AccessLogFormat.contextExtendedRequestId().

See also: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference


cacheClusterEnabled?

Type: boolean (optional, default: Disabled for the stage.)

Indicates whether cache clustering is enabled for the stage.


cacheClusterSize?

Type: string (optional, default: 0.5)

The stage's cache cluster size.


cacheDataEncrypted?

Type: boolean (optional, default: false)

Indicates whether the cached responses are encrypted.


cacheTtl?

Type: Duration (optional, default: Duration.minutes(5))

Specifies the time to live (TTL), in seconds, for cached responses.

The higher the TTL, the longer the response will be cached.

See also: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html


cachingEnabled?

Type: boolean (optional, default: Caching is Disabled.)

Specifies whether responses should be cached and returned for requests.

A cache cluster must be enabled on the stage for responses to be cached.


clientCertificateId?

Type: string (optional, default: None.)

The identifier of the client certificate that API Gateway uses to call your integration endpoints in the stage.


dataTraceEnabled?

Type: boolean (optional, default: false)

Specifies whether data trace logging is enabled for this method.

When enabled, API gateway will log the full API requests and responses. This can be useful to troubleshoot APIs, but can result in logging sensitive data. We recommend that you don't enable this feature for production APIs.


description?

Type: string (optional, default: No description.)

A description of the purpose of the stage.


documentationVersion?

Type: string (optional, default: No documentation version.)

The version identifier of the API documentation snapshot.


loggingLevel?

Type: MethodLoggingLevel (optional, default: Off)

Specifies the logging level for this method, which effects the log entries pushed to Amazon CloudWatch Logs.


methodOptions?

Type: { [string]: MethodDeploymentOptions } (optional, default: Common options will be used.)

Method deployment options for specific resources/methods.

These will override common options defined in StageOptions#methodOptions.


metricsEnabled?

Type: boolean (optional, default: false)

Specifies whether Amazon CloudWatch metrics are enabled for this method.


stageName?

Type: string (optional, default: "prod")

The name of the stage, which API Gateway uses as the first path segment in the invoked Uniform Resource Identifier (URI).


throttlingBurstLimit?

Type: number (optional, default: No additional restriction.)

Specifies the throttling burst limit.

The total rate of all requests in your AWS account is limited to 5,000 requests.

See also: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-throttling.html


throttlingRateLimit?

Type: number (optional, default: No additional restriction.)

Specifies the throttling rate limit.

The total rate of all requests in your AWS account is limited to 10,000 requests per second (rps).

See also: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-request-throttling.html


tracingEnabled?

Type: boolean (optional, default: false)

Specifies whether Amazon X-Ray tracing is enabled for this method.


variables?

Type: { [string]: string } (optional, default: No stage variables.)

A map that defines the stage variables.

Variable names must consist of alphanumeric characters, and the values must match the following regular expression: [A-Za-z0-9-._~:/?#&=,]+.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
restApiIRestApiRestApi to which this stage is associated.
stackStackThe stack in which this resource is defined.
stageArnstringReturns the resource ARN for this stage:.
stageNamestringName of this stage.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


restApi

Type: IRestApi

RestApi to which this stage is associated.


stack

Type: Stack

The stack in which this resource is defined.


stageArn

Type: string

Returns the resource ARN for this stage:.

arn:aws:apigateway:{region}::/restapis/{restApiId}/stages/{stageName}

Note that this is separate from the execute-api ARN for methods and resources within this stage.


stageName

Type: string

Name of this stage.

Methods

NameDescription
addApiKey(id, options?)Add an ApiKey to this stage.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
metric(metricName, props?)Returns the given named metric for this stage.
metricCacheHitCount(props?)Metric for the number of requests served from the API cache in a given period.
metricCacheMissCount(props?)Metric for the number of requests served from the backend in a given period, when API caching is enabled.
metricClientError(props?)Metric for the number of client-side errors captured in a given period.
metricCount(props?)Metric for the total number API requests in a given period.
metricIntegrationLatency(props?)Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.
metricLatency(props?)The time between when API Gateway receives a request from a client and when it returns a response to the client.
metricServerError(props?)Metric for the number of server-side errors captured in a given period.
toString()Returns a string representation of this construct.
urlForPath(path?)Returns the invoke URL for a certain path.
static fromStageAttributes(scope, id, attrs)Import a Stage by its attributes.

addApiKey(id, options?)

public addApiKey(id: string, options?: ApiKeyOptions): IApiKey

Parameters

  • id string
  • options ApiKeyOptions

Returns

  • IApiKey

Add an ApiKey to this stage.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


metric(metricName, props?)

public metric(metricName: string, props?: MetricOptions): Metric

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Returns the given named metric for this stage.


metricCacheHitCount(props?)

public metricCacheHitCount(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the number of requests served from the API cache in a given period.


metricCacheMissCount(props?)

public metricCacheMissCount(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the number of requests served from the backend in a given period, when API caching is enabled.


metricClientError(props?)

public metricClientError(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the number of client-side errors captured in a given period.


metricCount(props?)

public metricCount(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the total number API requests in a given period.


metricIntegrationLatency(props?)

public metricIntegrationLatency(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.


metricLatency(props?)

public metricLatency(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

The time between when API Gateway receives a request from a client and when it returns a response to the client.

The latency includes the integration latency and other API Gateway overhead.


metricServerError(props?)

public metricServerError(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the number of server-side errors captured in a given period.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


urlForPath(path?)

public urlForPath(path?: string): string

Parameters

  • path string — The resource path.

Returns

  • string

Returns the invoke URL for a certain path.


static fromStageAttributes(scope, id, attrs)

public static fromStageAttributes(scope: Construct, id: string, attrs: StageAttributes): IStage

Parameters

  • scope Construct
  • id string
  • attrs StageAttributes

Returns

  • IStage

Import a Stage by its attributes.