Skip to content
v2.277.0

RestApiBaseProps Struct ​

Represents the props that all Rest APIs share.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_apigateway as apigateway } from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_s3 as s3 } from 'aws-cdk-lib';
import { aws_certificatemanager as interfaces_certificatemanager } from 'aws-cdk-lib/interfaces';

declare const accessLogDestination: apigateway.IAccessLogDestination;
declare const accessLogFormat: apigateway.AccessLogFormat;
declare const bucket: s3.Bucket;
declare const certificateRef: interfaces_certificatemanager.ICertificateRef;
declare const policyDocument: iam.PolicyDocument;
declare const vpcEndpoint: ec2.VpcEndpoint;
const restApiBaseProps: apigateway.RestApiBaseProps = {
  cloudWatchRole: false,
  cloudWatchRoleRemovalPolicy: cdk.RemovalPolicy.DESTROY,
  deploy: false,
  deployOptions: {
    accessLogDestination: accessLogDestination,
    accessLogFormat: accessLogFormat,
    cacheClusterEnabled: false,
    cacheClusterSize: 'cacheClusterSize',
    cacheDataEncrypted: false,
    cacheTtl: cdk.Duration.minutes(30),
    cachingEnabled: false,
    clientCertificateId: 'clientCertificateId',
    dataTraceEnabled: false,
    description: 'description',
    documentationVersion: 'documentationVersion',
    loggingLevel: apigateway.MethodLoggingLevel.OFF,
    methodOptions: {
      methodOptionsKey: {
        cacheDataEncrypted: false,
        cacheTtl: cdk.Duration.minutes(30),
        cachingEnabled: false,
        dataTraceEnabled: false,
        loggingLevel: apigateway.MethodLoggingLevel.OFF,
        metricsEnabled: false,
        throttlingBurstLimit: 123,
        throttlingRateLimit: 123,
      },
    },
    metricsEnabled: false,
    stageName: 'stageName',
    throttlingBurstLimit: 123,
    throttlingRateLimit: 123,
    tracingEnabled: false,
    variables: {
      variablesKey: 'variables',
    },
  },
  description: 'description',
  disableExecuteApiEndpoint: false,
  domainName: {
    certificate: certificateRef,
    domainName: 'domainName',

    // the properties below are optional
    basePath: 'basePath',
    endpointAccessMode: apigateway.EndpointAccessMode.STRICT,
    endpointType: apigateway.EndpointType.EDGE,
    mtls: {
      bucket: bucket,
      key: 'key',

      // the properties below are optional
      version: 'version',
    },
    securityPolicy: apigateway.SecurityPolicy.TLS_1_0,
  },
  endpointConfiguration: {
    types: [apigateway.EndpointType.EDGE],

    // the properties below are optional
    ipAddressType: apigateway.IpAddressType.IPV4,
    vpcEndpoints: [vpcEndpoint],
  },
  endpointExportName: 'endpointExportName',
  endpointTypes: [apigateway.EndpointType.EDGE],
  failOnWarnings: false,
  parameters: {
    parametersKey: 'parameters',
  },
  policy: policyDocument,
  restApiName: 'restApiName',
  retainDeployments: false,
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_apigateway as apigateway
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_iam as iam
from aws_cdk import aws_s3 as s3
from aws_cdk.interfaces import aws_certificatemanager as interfaces_certificatemanager

# access_log_destination: apigateway.IAccessLogDestination
# access_log_format: apigateway.AccessLogFormat
# bucket: s3.Bucket
# certificate_ref: interfaces_certificatemanager.ICertificateRef
# policy_document: iam.PolicyDocument
# vpc_endpoint: ec2.VpcEndpoint

rest_api_base_props = apigateway.RestApiBaseProps(
    cloud_watch_role=False,
    cloud_watch_role_removal_policy=cdk.RemovalPolicy.DESTROY,
    deploy=False,
    deploy_options=apigateway.StageOptions(
        access_log_destination=access_log_destination,
        access_log_format=access_log_format,
        cache_cluster_enabled=False,
        cache_cluster_size="cacheClusterSize",
        cache_data_encrypted=False,
        cache_ttl=cdk.Duration.minutes(30),
        caching_enabled=False,
        client_certificate_id="clientCertificateId",
        data_trace_enabled=False,
        description="description",
        documentation_version="documentationVersion",
        logging_level=apigateway.MethodLoggingLevel.OFF,
        method_options={
            "method_options_key": apigateway.MethodDeploymentOptions(
                cache_data_encrypted=False,
                cache_ttl=cdk.Duration.minutes(30),
                caching_enabled=False,
                data_trace_enabled=False,
                logging_level=apigateway.MethodLoggingLevel.OFF,
                metrics_enabled=False,
                throttling_burst_limit=123,
                throttling_rate_limit=123
            )
        },
        metrics_enabled=False,
        stage_name="stageName",
        throttling_burst_limit=123,
        throttling_rate_limit=123,
        tracing_enabled=False,
        variables={
            "variables_key": "variables"
        }
    ),
    description="description",
    disable_execute_api_endpoint=False,
    domain_name=apigateway.DomainNameOptions(
        certificate=certificate_ref,
        domain_name="domainName",

        # the properties below are optional
        base_path="basePath",
        endpoint_access_mode=apigateway.EndpointAccessMode.STRICT,
        endpoint_type=apigateway.EndpointType.EDGE,
        mtls=apigateway.MTLSConfig(
            bucket=bucket,
            key="key",

            # the properties below are optional
            version="version"
        ),
        security_policy=apigateway.SecurityPolicy.TLS_1_0
    ),
    endpoint_configuration=apigateway.EndpointConfiguration(
        types=[apigateway.EndpointType.EDGE],

        # the properties below are optional
        ip_address_type=apigateway.IpAddressType.IPV4,
        vpc_endpoints=[vpc_endpoint]
    ),
    endpoint_export_name="endpointExportName",
    endpoint_types=[apigateway.EndpointType.EDGE],
    fail_on_warnings=False,
    parameters={
        "parameters_key": "parameters"
    },
    policy=policy_document,
    rest_api_name="restApiName",
    retain_deployments=False
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.apigateway.*;
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.iam.*;
import software.amazon.awscdk.services.s3.*;
import software.amazon.awscdk.interfaces.certificatemanager.*;

IAccessLogDestination accessLogDestination;
AccessLogFormat accessLogFormat;
Bucket bucket;
ICertificateRef certificateRef;
PolicyDocument policyDocument;
VpcEndpoint vpcEndpoint;

RestApiBaseProps restApiBaseProps = RestApiBaseProps.builder()
        .cloudWatchRole(false)
        .cloudWatchRoleRemovalPolicy(RemovalPolicy.DESTROY)
        .deploy(false)
        .deployOptions(StageOptions.builder()
                .accessLogDestination(accessLogDestination)
                .accessLogFormat(accessLogFormat)
                .cacheClusterEnabled(false)
                .cacheClusterSize("cacheClusterSize")
                .cacheDataEncrypted(false)
                .cacheTtl(Duration.minutes(30))
                .cachingEnabled(false)
                .clientCertificateId("clientCertificateId")
                .dataTraceEnabled(false)
                .description("description")
                .documentationVersion("documentationVersion")
                .loggingLevel(MethodLoggingLevel.OFF)
                .methodOptions(Map.of(
                        "methodOptionsKey", MethodDeploymentOptions.builder()
                                .cacheDataEncrypted(false)
                                .cacheTtl(Duration.minutes(30))
                                .cachingEnabled(false)
                                .dataTraceEnabled(false)
                                .loggingLevel(MethodLoggingLevel.OFF)
                                .metricsEnabled(false)
                                .throttlingBurstLimit(123)
                                .throttlingRateLimit(123)
                                .build()))
                .metricsEnabled(false)
                .stageName("stageName")
                .throttlingBurstLimit(123)
                .throttlingRateLimit(123)
                .tracingEnabled(false)
                .variables(Map.of(
                        "variablesKey", "variables"))
                .build())
        .description("description")
        .disableExecuteApiEndpoint(false)
        .domainName(DomainNameOptions.builder()
                .certificate(certificateRef)
                .domainName("domainName")

                // the properties below are optional
                .basePath("basePath")
                .endpointAccessMode(EndpointAccessMode.STRICT)
                .endpointType(EndpointType.EDGE)
                .mtls(MTLSConfig.builder()
                        .bucket(bucket)
                        .key("key")

                        // the properties below are optional
                        .version("version")
                        .build())
                .securityPolicy(SecurityPolicy.TLS_1_0)
                .build())
        .endpointConfiguration(EndpointConfiguration.builder()
                .types(List.of(EndpointType.EDGE))

                // the properties below are optional
                .ipAddressType(IpAddressType.IPV4)
                .vpcEndpoints(List.of(vpcEndpoint))
                .build())
        .endpointExportName("endpointExportName")
        .endpointTypes(List.of(EndpointType.EDGE))
        .failOnWarnings(false)
        .parameters(Map.of(
                "parametersKey", "parameters"))
        .policy(policyDocument)
        .restApiName("restApiName")
        .retainDeployments(false)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.APIGateway;
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.S3;
using Amazon.CDK.Interfaces.CertificateManager;

IAccessLogDestination accessLogDestination;
AccessLogFormat accessLogFormat;
Bucket bucket;
ICertificateRef certificateRef;
PolicyDocument policyDocument;
VpcEndpoint vpcEndpoint;

var restApiBaseProps = new RestApiBaseProps {
    CloudWatchRole = false,
    CloudWatchRoleRemovalPolicy = RemovalPolicy.DESTROY,
    Deploy = false,
    DeployOptions = new StageOptions {
        AccessLogDestination = accessLogDestination,
        AccessLogFormat = accessLogFormat,
        CacheClusterEnabled = false,
        CacheClusterSize = "cacheClusterSize",
        CacheDataEncrypted = false,
        CacheTtl = Duration.Minutes(30),
        CachingEnabled = false,
        ClientCertificateId = "clientCertificateId",
        DataTraceEnabled = false,
        Description = "description",
        DocumentationVersion = "documentationVersion",
        LoggingLevel = MethodLoggingLevel.OFF,
        MethodOptions = new Dictionary<string, MethodDeploymentOptions> {
            { "methodOptionsKey", new MethodDeploymentOptions {
                CacheDataEncrypted = false,
                CacheTtl = Duration.Minutes(30),
                CachingEnabled = false,
                DataTraceEnabled = false,
                LoggingLevel = MethodLoggingLevel.OFF,
                MetricsEnabled = false,
                ThrottlingBurstLimit = 123,
                ThrottlingRateLimit = 123
            } }
        },
        MetricsEnabled = false,
        StageName = "stageName",
        ThrottlingBurstLimit = 123,
        ThrottlingRateLimit = 123,
        TracingEnabled = false,
        Variables = new Dictionary<string, string> {
            { "variablesKey", "variables" }
        }
    },
    Description = "description",
    DisableExecuteApiEndpoint = false,
    DomainName = new DomainNameOptions {
        Certificate = certificateRef,
        DomainName = "domainName",

        // the properties below are optional
        BasePath = "basePath",
        EndpointAccessMode = EndpointAccessMode.STRICT,
        EndpointType = EndpointType.EDGE,
        Mtls = new MTLSConfig {
            Bucket = bucket,
            Key = "key",

            // the properties below are optional
            Version = "version"
        },
        SecurityPolicy = SecurityPolicy.TLS_1_0
    },
    EndpointConfiguration = new EndpointConfiguration {
        Types = new [] { EndpointType.EDGE },

        // the properties below are optional
        IpAddressType = IpAddressType.IPV4,
        VpcEndpoints = new [] { vpcEndpoint }
    },
    EndpointExportName = "endpointExportName",
    EndpointTypes = new [] { EndpointType.EDGE },
    FailOnWarnings = false,
    Parameters = new Dictionary<string, string> {
        { "parametersKey", "parameters" }
    },
    Policy = policyDocument,
    RestApiName = "restApiName",
    RetainDeployments = false
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var accessLogDestination IAccessLogDestination
var accessLogFormat AccessLogFormat
var bucket Bucket
var certificateRef ICertificateRef
var policyDocument PolicyDocument
var vpcEndpoint VpcEndpoint

restApiBaseProps := &RestApiBaseProps{
	CloudWatchRole: jsii.Boolean(false),
	CloudWatchRoleRemovalPolicy: cdk.RemovalPolicy_DESTROY,
	Deploy: jsii.Boolean(false),
	DeployOptions: &StageOptions{
		AccessLogDestination: accessLogDestination,
		AccessLogFormat: accessLogFormat,
		CacheClusterEnabled: jsii.Boolean(false),
		CacheClusterSize: jsii.String("cacheClusterSize"),
		CacheDataEncrypted: jsii.Boolean(false),
		CacheTtl: cdk.Duration_Minutes(jsii.Number(30)),
		CachingEnabled: jsii.Boolean(false),
		ClientCertificateId: jsii.String("clientCertificateId"),
		DataTraceEnabled: jsii.Boolean(false),
		Description: jsii.String("description"),
		DocumentationVersion: jsii.String("documentationVersion"),
		LoggingLevel: awscdk.Aws_apigateway.MethodLoggingLevel_OFF,
		MethodOptions: map[string]MethodDeploymentOptions{
			"methodOptionsKey": &MethodDeploymentOptions{
				"cacheDataEncrypted": jsii.Boolean(false),
				"cacheTtl": cdk.Duration_*Minutes(jsii.Number(30)),
				"cachingEnabled": jsii.Boolean(false),
				"dataTraceEnabled": jsii.Boolean(false),
				"loggingLevel": awscdk.*Aws_apigateway.MethodLoggingLevel_OFF,
				"metricsEnabled": jsii.Boolean(false),
				"throttlingBurstLimit": jsii.Number(123),
				"throttlingRateLimit": jsii.Number(123),
			},
		},
		MetricsEnabled: jsii.Boolean(false),
		StageName: jsii.String("stageName"),
		ThrottlingBurstLimit: jsii.Number(123),
		ThrottlingRateLimit: jsii.Number(123),
		TracingEnabled: jsii.Boolean(false),
		Variables: map[string]*string{
			"variablesKey": jsii.String("variables"),
		},
	},
	Description: jsii.String("description"),
	DisableExecuteApiEndpoint: jsii.Boolean(false),
	DomainName: &DomainNameOptions{
		Certificate: certificateRef,
		DomainName: jsii.String("domainName"),

		// the properties below are optional
		BasePath: jsii.String("basePath"),
		EndpointAccessMode: awscdk.*Aws_apigateway.EndpointAccessMode_STRICT,
		EndpointType: awscdk.*Aws_apigateway.EndpointType_EDGE,
		Mtls: &MTLSConfig{
			Bucket: bucket,
			Key: jsii.String("key"),

			// the properties below are optional
			Version: jsii.String("version"),
		},
		SecurityPolicy: awscdk.*Aws_apigateway.SecurityPolicy_TLS_1_0,
	},
	EndpointConfiguration: &EndpointConfiguration{
		Types: []EndpointType{
			awscdk.*Aws_apigateway.EndpointType_EDGE,
		},

		// the properties below are optional
		IpAddressType: awscdk.*Aws_apigateway.IpAddressType_IPV4,
		VpcEndpoints: []IVpcEndpoint{
			vpcEndpoint,
		},
	},
	EndpointExportName: jsii.String("endpointExportName"),
	EndpointTypes: []EndpointType{
		awscdk.*Aws_apigateway.EndpointType_EDGE,
	},
	FailOnWarnings: jsii.Boolean(false),
	Parameters: map[string]*string{
		"parametersKey": jsii.String("parameters"),
	},
	Policy: policyDocument,
	RestApiName: jsii.String("restApiName"),
	RetainDeployments: jsii.Boolean(false),
}

Properties ​

cloudWatchRoleoptionalbooleancloud_watch_roleoptionalboolcloudWatchRoleoptionalBooleanCloudWatchRoleoptionalboolCloudWatchRoleoptional*bool#
Automatically configure an AWS CloudWatch role for API Gateway.

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

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

Requires cloudWatchRole to be enabled.

deployoptionalbooleandeployoptionalbooldeployoptionalBooleanDeployoptionalboolDeployoptional*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.

deployOptionsoptionalStageOptionsdeploy_optionsoptionalStageOptionsdeployOptionsoptionalStageOptionsDeployOptionsoptionalStageOptionsDeployOptionsoptionalStageOptions#
Options for the API Gateway stage that will always point to the latest deployment when `deploy` is enabled.

Default: Based on defaults of StageOptions.

If deploy is disabled, this value cannot be set.

descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string#
A description of the RestApi construct.

Default: 'Automatically created by the RestApi construct'

disableExecuteApiEndpointoptionalbooleandisable_execute_api_endpointoptionalbooldisableExecuteApiEndpointoptionalBooleanDisableExecuteApiEndpointoptionalboolDisableExecuteApiEndpointoptional*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.

domainNameoptionalDomainNameOptionsdomain_nameoptionalDomainNameOptionsdomainNameoptionalDomainNameOptionsDomainNameoptionalDomainNameOptionsDomainNameoptionalDomainNameOptions#
Configure a custom domain name and map it to this API.

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

endpointConfigurationoptionalEndpointConfigurationendpoint_configurationoptionalEndpointConfigurationendpointConfigurationoptionalEndpointConfigurationEndpointConfigurationoptionalEndpointConfigurationEndpointConfigurationoptionalEndpointConfiguration= EndpointType.EDGE#
The EndpointConfiguration property type specifies the endpoint types of a REST API.
endpointExportNameoptionalstringendpoint_export_nameoptionalstrendpointExportNameoptionalStringEndpointExportNameoptionalstringEndpointExportNameoptional*string#
Export name for the CfnOutput containing the API endpoint.

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

endpointTypesoptionalEndpointType[]endpoint_typesoptionaltyping.List[EndpointType]endpointTypesoptionalList<EndpointType>EndpointTypesoptionalEndpointType[]EndpointTypesoptional*[]EndpointType= EndpointType.EDGE#
A list of the endpoint types of the API.

Use this property when creating an API.

failOnWarningsoptionalbooleanfail_on_warningsoptionalboolfailOnWarningsoptionalBooleanFailOnWarningsoptionalboolFailOnWarningsoptional*bool= false#
Indicates whether to roll back the resource if a warning occurs while API Gateway is creating the RestApi resource.
parametersoptional{ [key: string]: string }parametersoptionaltyping.Mapping[str, str]parametersoptionalMap<String, String>ParametersoptionalIDictionary<string, string>Parametersoptional*map[string]*string#
Custom header parameters for the request.

Default: No parameters.

policyoptionalPolicyDocumentpolicyoptionalPolicyDocumentpolicyoptionalPolicyDocumentPolicyoptionalPolicyDocumentPolicyoptionalPolicyDocument#
A policy document that contains the permissions for this RestApi.

Default: No policy.

restApiNameoptionalstringrest_api_nameoptionalstrrestApiNameoptionalStringRestApiNameoptionalstringRestApiNameoptional*string#
A name for the API Gateway RestApi resource.

Default: ID of the RestApi construct.

retainDeploymentsoptionalbooleanretain_deploymentsoptionalboolretainDeploymentsoptionalBooleanRetainDeploymentsoptionalboolRetainDeploymentsoptional*bool= false#
Retains old deployment resources when the API changes.

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