CfnRestApi

class aws_cdk.aws_apigateway.CfnRestApi(scope, id, *, api_key_source_type=None, binary_media_types=None, body=None, body_s3_location=None, clone_from=None, description=None, disable_execute_api_endpoint=None, endpoint_configuration=None, fail_on_warnings=None, minimum_compression_size=None, mode=None, name=None, parameters=None, policy=None, tags=None)

Bases: CfnResource

A CloudFormation AWS::ApiGateway::RestApi.

The AWS::ApiGateway::RestApi resource creates a REST API. For more information, see restapi:create in the Amazon API Gateway REST API Reference . .. epigraph:

On January 1, 2016, the Swagger Specification was donated to the `OpenAPI initiative <https://docs.aws.amazon.com/https://www.openapis.org/>`_ , becoming the foundation of the OpenAPI Specification.
CloudformationResource:

AWS::ApiGateway::RestApi

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html

ExampleMetadata:

fixture=_generated

Example:

# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk.aws_apigateway as apigateway

# body: Any
# policy: Any

cfn_rest_api = apigateway.CfnRestApi(self, "MyCfnRestApi",
    api_key_source_type="apiKeySourceType",
    binary_media_types=["binaryMediaTypes"],
    body=body,
    body_s3_location=apigateway.CfnRestApi.S3LocationProperty(
        bucket="bucket",
        e_tag="eTag",
        key="key",
        version="version"
    ),
    clone_from="cloneFrom",
    description="description",
    disable_execute_api_endpoint=False,
    endpoint_configuration=apigateway.CfnRestApi.EndpointConfigurationProperty(
        types=["types"],
        vpc_endpoint_ids=["vpcEndpointIds"]
    ),
    fail_on_warnings=False,
    minimum_compression_size=123,
    mode="mode",
    name="name",
    parameters={
        "parameters_key": "parameters"
    },
    policy=policy,
    tags=[CfnTag(
        key="key",
        value="value"
    )]
)

Create a new AWS::ApiGateway::RestApi.

Parameters:
  • scope (Construct) –

    • scope in which this resource is defined.

  • id (str) –

    • scoped id of the resource.

  • api_key_source_type (Optional[str]) – The source of the API key for metering requests according to a usage plan. Valid values are: HEADER to read the API key from the X-API-Key header of a request. AUTHORIZER to read the API key from the UsageIdentifierKey from a custom authorizer.

  • binary_media_types (Optional[Sequence[str]]) – The list of binary media types supported by the RestApi. By default, the RestApi supports only UTF-8-encoded text payloads.

  • body (Optional[Any]) – An OpenAPI specification that defines a set of RESTful APIs in JSON format. For YAML templates, you can also provide the specification in YAML format.

  • body_s3_location (Union[IResolvable, S3LocationProperty, Dict[str, Any], None]) – The Amazon Simple Storage Service (Amazon S3) location that points to an OpenAPI file, which defines a set of RESTful APIs in JSON or YAML format.

  • clone_from (Optional[str]) – The ID of the RestApi that you want to clone from.

  • description (Optional[str]) – The description of the RestApi.

  • disable_execute_api_endpoint (Union[bool, IResolvable, None]) – Specifies whether clients can invoke your API by using the default execute-api endpoint. By default, clients can invoke your API with the default https://{api_id}.execute-api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke your API, disable the default endpoint

  • endpoint_configuration (Union[IResolvable, EndpointConfigurationProperty, Dict[str, Any], None]) – A list of the endpoint types of the API. Use this property when creating an API. When importing an existing API, specify the endpoint configuration types using the Parameters property.

  • fail_on_warnings (Union[bool, IResolvable, None]) – A query parameter to indicate whether to rollback the API update ( true ) or not ( false ) when a warning is encountered. The default value is false .

  • minimum_compression_size (Union[int, float, None]) – A nullable integer that is used to enable compression (with non-negative between 0 and 10485760 (10M) bytes, inclusive) or disable compression (with a null value) on an API. When compression is enabled, compression or decompression is not applied on the payload if the payload size is smaller than this value. Setting it to zero allows compression for any payload size.

  • mode (Optional[str]) – This property applies only when you use OpenAPI to define your REST API. The Mode determines how API Gateway handles resource updates. Valid values are overwrite or merge . For overwrite , the new API definition replaces the existing one. The existing API identifier remains unchanged. For merge , the new API definition is merged with the existing API. If you don’t specify this property, a default value is chosen. For REST APIs created before March 29, 2021, the default is overwrite . For REST APIs created after March 29, 2021, the new API definition takes precedence, but any container types such as endpoint configurations and binary media types are merged with the existing API. Use the default mode to define top-level RestApi properties in addition to using OpenAPI. Generally, it’s preferred to use API Gateway’s OpenAPI extensions to model these properties.

  • name (Optional[str]) – The name of the RestApi. A name is required if the REST API is not based on an OpenAPI specification.

  • parameters (Union[IResolvable, Mapping[str, str], None]) – Custom header parameters as part of the request. For example, to exclude DocumentationParts from an imported API, set ignore=documentation as a parameters value, as in the AWS CLI command of aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json' .

  • policy (Optional[Any]) – A policy document that contains the permissions for the RestApi resource. To set the ARN for the policy, use the !Join intrinsic function with "" as delimiter and values of "execute-api:/" and "*" .

  • tags (Optional[Sequence[Union[CfnTag, Dict[str, Any]]]]) – The key-value map of strings. The valid character set is [a-zA-Z+-=._:/]. The tag key can be up to 128 characters and must not start with aws: . The tag value can be up to 256 characters.

Methods

add_deletion_override(path)

Syntactic sugar for addOverride(path, undefined).

Parameters:

path (str) – The path of the value to delete.

Return type:

None

add_depends_on(target)

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.

This can be used for resources across stacks (or nested stack) boundaries and the dependency will automatically be transferred to the relevant scope.

Parameters:

target (CfnResource) –

Return type:

None

add_metadata(key, value)

Add a value to the CloudFormation Resource Metadata.

Parameters:
  • key (str) –

  • value (Any) –

See:

Return type:

None

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.

add_override(path, value)

Adds an override to the synthesized CloudFormation resource.

To add a property override, either use addPropertyOverride or prefix path with “Properties.” (i.e. Properties.TopicName).

If the override is nested, separate each nested level using a dot (.) in the path parameter. If there is an array as part of the nesting, specify the index in the path.

To include a literal . in the property name, prefix with a \. In most programming languages you will need to write this as "\\." because the \ itself will need to be escaped.

For example:

cfn_resource.add_override("Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes", ["myattribute"])
cfn_resource.add_override("Properties.GlobalSecondaryIndexes.1.ProjectionType", "INCLUDE")

would add the overrides Example:

"Properties": {
   "GlobalSecondaryIndexes": [
     {
       "Projection": {
         "NonKeyAttributes": [ "myattribute" ]
         ...
       }
       ...
     },
     {
       "ProjectionType": "INCLUDE"
       ...
     },
   ]
   ...
}

The value argument to addOverride will not be processed or translated in any way. Pass raw JSON values in here with the correct capitalization for CloudFormation. If you pass CDK classes or structs, they will be rendered with lowercased key names, and CloudFormation will reject the template.

Parameters:
  • path (str) –

    • The path of the property, you can use dot notation to override values in complex types. Any intermdediate keys will be created as needed.

  • value (Any) –

    • The value. Could be primitive or complex.

Return type:

None

add_property_deletion_override(property_path)

Adds an override that deletes the value of a property from the resource definition.

Parameters:

property_path (str) – The path to the property.

Return type:

None

add_property_override(property_path, value)

Adds an override to a resource property.

Syntactic sugar for addOverride("Properties.<...>", value).

Parameters:
  • property_path (str) – The path of the property.

  • value (Any) – The value.

Return type:

None

apply_removal_policy(policy=None, *, apply_to_update_replace_policy=None, default=None)

Sets the deletion policy of the resource based on the removal policy specified.

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

Parameters:
  • policy (Optional[RemovalPolicy]) –

  • apply_to_update_replace_policy (Optional[bool]) – Apply the same deletion policy to the resource’s “UpdateReplacePolicy”. Default: true

  • default (Optional[RemovalPolicy]) – The default policy to apply in case the removal policy is not defined. Default: - Default value is resource specific. To determine the default value for a resoure, please consult that specific resource’s documentation.

Return type:

None

get_att(attribute_name)

Returns a token for an runtime attribute of this resource.

Ideally, use generated attribute accessors (e.g. resource.arn), but this can be used for future compatibility in case there is no generated attribute.

Parameters:

attribute_name (str) – The name of the attribute.

Return type:

Reference

get_metadata(key)

Retrieve a value value from the CloudFormation Resource Metadata.

Parameters:

key (str) –

See:

Return type:

Any

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.

inspect(inspector)

Examines the CloudFormation resource and discloses attributes.

Parameters:

inspector (TreeInspector) –

  • tree inspector to collect and process attributes.

Return type:

None

override_logical_id(new_logical_id)

Overrides the auto-generated logical ID with a specific ID.

Parameters:

new_logical_id (str) – The new logical ID to use for this stack element.

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Returns:

a string representation of this resource

Attributes

CFN_RESOURCE_TYPE_NAME = 'AWS::ApiGateway::RestApi'
api_key_source_type

The source of the API key for metering requests according to a usage plan.

Valid values are: HEADER to read the API key from the X-API-Key header of a request. AUTHORIZER to read the API key from the UsageIdentifierKey from a custom authorizer.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-apikeysourcetype

attr_rest_api_id

The string identifier of the associated RestApi.

CloudformationAttribute:

RestApiId

attr_root_resource_id

The root resource ID for a RestApi resource, such as a0bc123d4e .

CloudformationAttribute:

RootResourceId

binary_media_types

The list of binary media types supported by the RestApi.

By default, the RestApi supports only UTF-8-encoded text payloads.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-binarymediatypes

body

An OpenAPI specification that defines a set of RESTful APIs in JSON format.

For YAML templates, you can also provide the specification in YAML format.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-body

body_s3_location

The Amazon Simple Storage Service (Amazon S3) location that points to an OpenAPI file, which defines a set of RESTful APIs in JSON or YAML format.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-bodys3location

cfn_options

Options for this resource, such as condition, update policy etc.

cfn_resource_type

AWS resource type.

clone_from

The ID of the RestApi that you want to clone from.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-clonefrom

creation_stack

return:

the stack trace of the point where this Resource was created from, sourced from the +metadata+ entry typed +aws:cdk:logicalId+, and with the bottom-most node +internal+ entries filtered.

description

The description of the RestApi.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-description

disable_execute_api_endpoint

Specifies whether clients can invoke your API by using the default execute-api endpoint.

By default, clients can invoke your API with the default https://{api_id}.execute-api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke your API, disable the default endpoint

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-disableexecuteapiendpoint

endpoint_configuration

A list of the endpoint types of the API.

Use this property when creating an API. When importing an existing API, specify the endpoint configuration types using the Parameters property.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-endpointconfiguration

fail_on_warnings

A query parameter to indicate whether to rollback the API update ( true ) or not ( false ) when a warning is encountered.

The default value is false .

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-failonwarnings

logical_id

The logical ID for this CloudFormation stack element.

The logical ID of the element is calculated from the path of the resource node in the construct tree.

To override this value, use overrideLogicalId(newLogicalId).

Returns:

the logical ID as a stringified token. This value will only get resolved during synthesis.

minimum_compression_size

A nullable integer that is used to enable compression (with non-negative between 0 and 10485760 (10M) bytes, inclusive) or disable compression (with a null value) on an API.

When compression is enabled, compression or decompression is not applied on the payload if the payload size is smaller than this value. Setting it to zero allows compression for any payload size.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-minimumcompressionsize

mode

This property applies only when you use OpenAPI to define your REST API.

The Mode determines how API Gateway handles resource updates.

Valid values are overwrite or merge .

For overwrite , the new API definition replaces the existing one. The existing API identifier remains unchanged.

For merge , the new API definition is merged with the existing API.

If you don’t specify this property, a default value is chosen. For REST APIs created before March 29, 2021, the default is overwrite . For REST APIs created after March 29, 2021, the new API definition takes precedence, but any container types such as endpoint configurations and binary media types are merged with the existing API.

Use the default mode to define top-level RestApi properties in addition to using OpenAPI. Generally, it’s preferred to use API Gateway’s OpenAPI extensions to model these properties.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-mode

name

The name of the RestApi.

A name is required if the REST API is not based on an OpenAPI specification.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-name

node

The construct tree node associated with this construct.

parameters

Custom header parameters as part of the request.

For example, to exclude DocumentationParts from an imported API, set ignore=documentation as a parameters value, as in the AWS CLI command of aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json' .

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-parameters

policy

A policy document that contains the permissions for the RestApi resource.

To set the ARN for the policy, use the !Join intrinsic function with "" as delimiter and values of "execute-api:/" and "*" .

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-policy

ref

Return a string that will be resolved to a CloudFormation { Ref } for this element.

If, by any chance, the intrinsic reference of a resource is not a string, you could coerce it to an IResolvable through Lazy.any({ produce: resource.ref }).

stack

The stack in which this element is defined.

CfnElements must be defined within a stack scope (directly or indirectly).

tags

The key-value map of strings.

The valid character set is [a-zA-Z+-=._:/]. The tag key can be up to 128 characters and must not start with aws: . The tag value can be up to 256 characters.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-tags

Static Methods

classmethod is_cfn_element(x)

Returns true if a construct is a stack element (i.e. part of the synthesized cloudformation template).

Uses duck-typing instead of instanceof to allow stack elements from different versions of this library to be included in the same stack.

Parameters:

x (Any) –

Return type:

bool

Returns:

The construct as a stack element or undefined if it is not a stack element.

classmethod is_cfn_resource(construct)

Check whether the given construct is a CfnResource.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool

EndpointConfigurationProperty

class CfnRestApi.EndpointConfigurationProperty(*, types=None, vpc_endpoint_ids=None)

Bases: object

The EndpointConfiguration property type specifies the endpoint types of a REST API.

EndpointConfiguration is a property of the AWS::ApiGateway::RestApi resource.

Parameters:
  • types (Optional[Sequence[str]]) – A list of endpoint types of an API (RestApi) or its custom domain name (DomainName). For an edge-optimized API and its custom domain name, the endpoint type is "EDGE" . For a regional API and its custom domain name, the endpoint type is REGIONAL . For a private API, the endpoint type is PRIVATE .

  • vpc_endpoint_ids (Optional[Sequence[str]]) – A list of VpcEndpointIds of an API (RestApi) against which to create Route53 ALIASes. It is only supported for PRIVATE endpoint type.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html

ExampleMetadata:

fixture=_generated

Example:

# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk.aws_apigateway as apigateway

endpoint_configuration_property = apigateway.CfnRestApi.EndpointConfigurationProperty(
    types=["types"],
    vpc_endpoint_ids=["vpcEndpointIds"]
)

Attributes

types

A list of endpoint types of an API (RestApi) or its custom domain name (DomainName).

For an edge-optimized API and its custom domain name, the endpoint type is "EDGE" . For a regional API and its custom domain name, the endpoint type is REGIONAL . For a private API, the endpoint type is PRIVATE .

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-types

vpc_endpoint_ids

A list of VpcEndpointIds of an API (RestApi) against which to create Route53 ALIASes.

It is only supported for PRIVATE endpoint type.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-vpcendpointids

S3LocationProperty

class CfnRestApi.S3LocationProperty(*, bucket=None, e_tag=None, key=None, version=None)

Bases: object

S3Location is a property of the AWS::ApiGateway::RestApi resource that specifies the Amazon S3 location of a OpenAPI (formerly Swagger) file that defines a set of RESTful APIs in JSON or YAML.

On January 1, 2016, the Swagger Specification was donated to the OpenAPI initiative , becoming the foundation of the OpenAPI Specification.

Parameters:
  • bucket (Optional[str]) – The name of the S3 bucket where the OpenAPI file is stored.

  • e_tag (Optional[str]) – The Amazon S3 ETag (a file checksum) of the OpenAPI file. If you don’t specify a value, API Gateway skips ETag validation of your OpenAPI file.

  • key (Optional[str]) – The file name of the OpenAPI file (Amazon S3 object name).

  • version (Optional[str]) – For versioning-enabled buckets, a specific version of the OpenAPI file.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html

ExampleMetadata:

fixture=_generated

Example:

# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk.aws_apigateway as apigateway

s3_location_property = apigateway.CfnRestApi.S3LocationProperty(
    bucket="bucket",
    e_tag="eTag",
    key="key",
    version="version"
)

Attributes

bucket

The name of the S3 bucket where the OpenAPI file is stored.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-bucket

e_tag

The Amazon S3 ETag (a file checksum) of the OpenAPI file.

If you don’t specify a value, API Gateway skips ETag validation of your OpenAPI file.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-etag

key

The file name of the OpenAPI file (Amazon S3 object name).

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-key

version

For versioning-enabled buckets, a specific version of the OpenAPI file.

Link:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-version