Skip to content
v2.274.0

RestApiBase L2 construct ​

Base implementation that are common to various implementations of IRestApi.

Example ​

ts
declare const api: apigateway.RestApi;
new cloudfront.Distribution(this, 'Distribution', {
  defaultBehavior: { origin: new origins.RestApiOrigin(api) },
});

Initializer ​

ts
new RestApiBase(scope: Construct, id: string, props?: RestApiBaseProps)
python
RestApiBase(scope: Construct, id: str, props: typing.Optional[RestApiBaseProps] = None)
java
new RestApiBase(Construct scope, String id, RestApiBaseProps props)
csharp
new RestApiBase(Construct scope, string id, RestApiBaseProps? props = null)
go
NewRestApiBase(Scope Construct, Id *string, Props RestApiBaseProps)

Construct Props ​

cloudWatchRolebooleancloud_watch_roleboolcloudWatchRoleBooleanCloudWatchRoleboolCloudWatchRole*bool= false if `@aws-cdk/aws-apigatewa…#
Automatically configure an AWS CloudWatch role for API Gateway.
default

Default: false if @aws-cdk/aws-apigateway:disableCloudWatchRole is enabled, true otherwise

cloudWatchRoleRemovalPolicyRemovalPolicycloud_watch_role_removal_policyRemovalPolicycloudWatchRoleRemovalPolicyRemovalPolicyCloudWatchRoleRemovalPolicyRemovalPolicyCloudWatchRoleRemovalPolicyRemovalPolicy= RemovalPolicy.RETAIN#
The removal policy applied to the AWS CloudWatch role when this resource is removed from the application.

Requires cloudWatchRole to be enabled.

deploybooleandeploybooldeployBooleanDeployboolDeploy*bool= true#
Indicates if a Deployment should be automatically created for this API, and recreated when the API model (resources, methods) changes.
notes

Since API Gateway deployments are immutable, When this option is enabled (by default), an AWS::ApiGateway::Deployment resource will automatically created with a logical ID that hashes the API model (methods, resources and options). This means that when the model changes, the logical ID of this CloudFormation resource will change, and a new deployment will be created.

If this is set, latestDeployment will refer to the Deployment object and deploymentStage will refer to a Stage that points to this deployment. To customize the stage options, use the deployOptions property.

A CloudFormation Output will also be defined with the root URL endpoint of this REST API.

deployOptionsStageOptionsdeploy_optionsStageOptionsdeployOptionsStageOptionsDeployOptionsStageOptionsDeployOptionsStageOptions= Based on defaults of `StageOptio…#
Options for the API Gateway stage that will always point to the latest deployment when `deploy` is enabled.

If deploy is disabled, this value cannot be set.

default

Default: Based on defaults of StageOptions.

descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= 'Automatically created by the Re…#
A description of the RestApi construct.
default

Default: 'Automatically created by the RestApi construct'

disableExecuteApiEndpointbooleandisable_execute_api_endpointbooldisableExecuteApiEndpointBooleanDisableExecuteApiEndpointboolDisableExecuteApiEndpoint*bool= false#
Specifies whether clients can invoke the API using the default execute-api endpoint.

To require that clients use a custom domain name to invoke the API, disable the default endpoint.

domainNameDomainNameOptionsdomain_nameDomainNameOptionsdomainNameDomainNameOptionsDomainNameDomainNameOptionsDomainNameDomainNameOptions= no domain name is defined, use `…#
Configure a custom domain name and map it to this API.
default

Default: no domain name is defined, use addDomainName or directly define a DomainName.

endpointConfigurationEndpointConfigurationendpoint_configurationEndpointConfigurationendpointConfigurationEndpointConfigurationEndpointConfigurationEndpointConfigurationEndpointConfigurationEndpointConfiguration= EndpointType.EDGE#
The EndpointConfiguration property type specifies the endpoint types of a REST API.
endpointExportNamestringendpoint_export_namestrendpointExportNameStringEndpointExportNamestringEndpointExportName*string= when no export name is given, ou…#
Export name for the CfnOutput containing the API endpoint.
default

Default: when no export name is given, output will be created without export

endpointTypesEndpointType[]endpoint_typestyping.List[EndpointType]endpointTypesList<EndpointType>EndpointTypesEndpointType[]EndpointTypes*[]EndpointType= EndpointType.EDGE#
A list of the endpoint types of the API.

Use this property when creating an API.

failOnWarningsbooleanfail_on_warningsboolfailOnWarningsBooleanFailOnWarningsboolFailOnWarnings*bool= false#
Indicates whether to roll back the resource if a warning occurs while API Gateway is creating the RestApi resource.
parameters{ [key: string]: string }parameterstyping.Mapping[str, str]parametersMap<String, String>ParametersIDictionary<string, string>Parameters*map[string]*string= No parameters.#
Custom header parameters for the request.
A policy document that contains the permissions for this RestApi.
restApiNamestringrest_api_namestrrestApiNameStringRestApiNamestringRestApiName*string= ID of the RestApi construct.#
A name for the API Gateway RestApi resource.
retainDeploymentsbooleanretain_deploymentsboolretainDeploymentsBooleanRetainDeploymentsboolRetainDeployments*bool= false#
Retains old deployment resources when the API changes.

This allows manually reverting stages to point to old deployments via the AWS Console.

Properties ​

deploymentStageStagedeployment_stageStagedeploymentStageStageDeploymentStageStageDeploymentStageStagerequired#
API Gateway stage that points to the latest deployment (if defined).

If deploy is disabled, you will need to explicitly assign this value in order to set up integrations.

domainNameDomainNamedomain_nameDomainNamedomainNameDomainNameDomainNameDomainNameDomainNameDomainName#
The first domain name mapped to this API, if defined through the `domainName` configuration prop, or added via `addDomainName`.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

latestDeploymentDeploymentlatest_deploymentDeploymentlatestDeploymentDeploymentLatestDeploymentDeploymentLatestDeploymentDeployment#
API Gateway deployment that represents the latest changes of the API.

This resource will be automatically updated every time the REST API model changes. This will be undefined if deploy is false.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
restApiIdstringrest_api_idstrrestApiIdStringRestApiIdstringRestApiId*stringrequired#
The ID of this API Gateway RestApi.
restApiNamestringrest_api_namestrrestApiNameStringRestApiNamestringRestApiName*stringrequired#
A human friendly name for this Rest API.

Note that this is different from restApiId.

restApiRefRestApiReferencerest_api_refRestApiReferencerestApiRefRestApiReferenceRestApiRefRestApiReferenceRestApiRefRestApiReferencerequired#
A reference to a RestApi resource.
restApiRootResourceIdstringrest_api_root_resource_idstrrestApiRootResourceIdStringRestApiRootResourceIdstringRestApiRootResourceId*stringrequired#
The resource ID of the root resource.
Represents the root resource of this API endpoint ('/').

Resources and Methods are added to this resource.

stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
urlstringurlstrurlStringUrlstringUrl*stringrequired#
The deployed root URL of this REST API.

Methods ​

addApiKey(id: string, options?: ApiKeyOptions): IApiKeydef add_api_key(self, id: str, options: typing.Optional[ApiKeyOptions] = None) -> IApiKeypublic IApiKey addApiKey(String id, ApiKeyOptions options)public IApiKey AddApiKey(string id, ApiKeyOptions? options = null)func AddApiKey(Id *string, Options ApiKeyOptions) IApiKey#
Add an ApiKey to the deploymentStage.
addDomainName(id: string, options: DomainNameOptions): DomainNamedef add_domain_name(self, id: str, options: DomainNameOptions) -> DomainNamepublic DomainName addDomainName(String id, DomainNameOptions options)public DomainName AddDomainName(string id, DomainNameOptions options)func AddDomainName(Id *string, Options DomainNameOptions) DomainName#
Defines an API Gateway domain name and maps it to this API.
2 parameters

Parameters

  • ididididId — The construct id.
  • optionsoptionsoptionsoptionsOptions — custom domain options.
addGatewayResponse(id: string, options: GatewayResponseOptions): GatewayResponsedef add_gateway_response(self, id: str, options: GatewayResponseOptions) -> GatewayResponsepublic GatewayResponse addGatewayResponse(String id, GatewayResponseOptions options)public GatewayResponse AddGatewayResponse(string id, GatewayResponseOptions options)func AddGatewayResponse(Id *string, Options GatewayResponseOptions) GatewayResponse#
Adds a new gateway response.
addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResultdef add_to_resource_policy(self, statement: PolicyStatement) -> AddToResourcePolicyResultpublic AddToResourcePolicyResult addToResourcePolicy(PolicyStatement statement)public AddToResourcePolicyResult AddToResourcePolicy(PolicyStatement statement)func AddToResourcePolicy(Statement PolicyStatement) AddToResourcePolicyResult#
Add a statement to the resource's resource policy.
addUsagePlan(id: string, props?: UsagePlanProps): UsagePlandef add_usage_plan(self, id: str, props: typing.Optional[UsagePlanProps] = None) -> UsagePlanpublic UsagePlan addUsagePlan(String id, UsagePlanProps props)public UsagePlan AddUsagePlan(string id, UsagePlanProps? props = null)func AddUsagePlan(Id *string, Props UsagePlanProps) UsagePlan#
Adds a usage plan.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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).

arnForExecuteApi(method?: string, path?: string, stage?: string): stringdef arn_for_execute_api(self, method: typing.Optional[str] = None, path: typing.Optional[str] = None, stage: typing.Optional[str] = None) -> strpublic String arnForExecuteApi(String method, String path, String stage)public string ArnForExecuteApi(string? method = null, string? path = null, string? stage = null)func ArnForExecuteApi(Method *string, Path *string, Stage *string) *string#
Gets the "execute-api" ARN.
grantInvokeFromVpcEndpointsOnly(vpcEndpoints: IVpcEndpoint[]): voiddef grant_invoke_from_vpc_endpoints_only(self, vpc_endpoints: typing.List[IVpcEndpoint]) -> Nonepublic void grantInvokeFromVpcEndpointsOnly(List<IVpcEndpoint> vpcEndpoints)public void GrantInvokeFromVpcEndpointsOnly(IVpcEndpoint[] vpcEndpoints)func GrantInvokeFromVpcEndpointsOnly(VpcEndpoints *[]IVpcEndpoint)#
Add a resource policy that only allows API execution from a VPC Endpoint to create a private API.
1 parameter

Parameters

  • vpcEndpointsvpc_endpointsvpcEndpointsvpcEndpointsVpcEndpoints — the interface VPC endpoints to grant access to.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
metric(metricName: string, props?: MetricOptions): Metricdef metric(self, metric_name: str, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricOptions props)public Metric Metric(string metricName, MetricOptions? props = null)func Metric(MetricName *string, Props MetricOptions) Metric#
Returns the given named metric for this API.
metricCacheHitCount(props?: MetricOptions): Metricdef metric_cache_hit_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricCacheHitCount(MetricOptions props)public Metric MetricCacheHitCount(MetricOptions? props = null)func MetricCacheHitCount(Props MetricOptions) Metric#
Metric for the number of requests served from the API cache in a given period.

Default: sum over 5 minutes

metricCacheMissCount(props?: MetricOptions): Metricdef metric_cache_miss_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricCacheMissCount(MetricOptions props)public Metric MetricCacheMissCount(MetricOptions? props = null)func MetricCacheMissCount(Props MetricOptions) Metric#
Metric for the number of requests served from the backend in a given period, when API caching is enabled.

Default: sum over 5 minutes

metricClientError(props?: MetricOptions): Metricdef metric_client_error(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricClientError(MetricOptions props)public Metric MetricClientError(MetricOptions? props = null)func MetricClientError(Props MetricOptions) Metric#
Metric for the number of client-side errors captured in a given period.

Default: sum over 5 minutes

metricCount(props?: MetricOptions): Metricdef metric_count(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricCount(MetricOptions props)public Metric MetricCount(MetricOptions? props = null)func MetricCount(Props MetricOptions) Metric#
Metric for the total number API requests in a given period.

Default: sample count over 5 minutes

metricIntegrationLatency(props?: MetricOptions): Metricdef metric_integration_latency(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricIntegrationLatency(MetricOptions props)public Metric MetricIntegrationLatency(MetricOptions? props = null)func MetricIntegrationLatency(Props MetricOptions) Metric#
Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.

Default: average over 5 minutes.

metricLatency(props?: MetricOptions): Metricdef metric_latency(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricLatency(MetricOptions props)public Metric MetricLatency(MetricOptions? props = null)func MetricLatency(Props MetricOptions) 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.

Default: average over 5 minutes.

metricServerError(props?: MetricOptions): Metricdef metric_server_error(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricServerError(MetricOptions props)public Metric MetricServerError(MetricOptions? props = null)func MetricServerError(Props MetricOptions) Metric#
Metric for the number of server-side errors captured in a given period.

Default: sum over 5 minutes

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
urlForPath(path?: string): stringdef url_for_path(self, path: typing.Optional[str] = None) -> strpublic String urlForPath(String path)public string UrlForPath(string? path = null)func UrlForPath(Path *string) *string#
Returns the URL for an HTTP path.

Fails if deploymentStage is not set either by deploy or explicitly.

with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.