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:
aws_cdk.core.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 theX-API-Key
header of a request. -AUTHORIZER
to read the API key from theUsageIdentifierKey
from a Lambda authorizer.binary_media_types (
Optional
[Sequence
[str
]]) – The list of binary media types that are supported by theRestApi
resource. Use~1
instead of/
in the media types, for exampleimage~1png
orapplication~1octet-stream
. By default,RestApi
supports only UTF-8-encoded text payloads. Duplicates are not allowed. For more information, see Enable Support for Binary Payloads in API Gateway in the API Gateway Developer Guide .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
,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 theRestApi
resource that you want to clone.description (
Optional
[str
]) – A description of theRestApi
resource.disable_execute_api_endpoint (
Union
[bool
,IResolvable
,None
]) – Specifies whether clients can invoke your API by using the defaultexecute-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
,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 theParameters
property.fail_on_warnings (
Union
[bool
,IResolvable
,None
]) – Indicates whether to roll back the resource if a warning occurs while API Gateway is creating theRestApi
resource.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. TheMode
determines how API Gateway handles resource updates. Valid values areoverwrite
ormerge
. Foroverwrite
, the new API definition replaces the existing one. The existing API identifier remains unchanged. Formerge
, the new API definition takes precedence, but any container types such as endpoint configurations and binary media types are merged with the existing API. Usemerge
to define top-levelRestApi
properties in addition to using OpenAPI. Generally, it’s preferred to use API Gateway’s OpenAPI extensions to model these properties. If you don’t specify this property, a default value is chosen. For REST APIs created before March 29, 2021, the default isoverwrite
. Otherwise, the default value ismerge
.name (
Optional
[str
]) – A name for theRestApi
resource.parameters (
Union
[IResolvable
,Mapping
[str
,str
],None
]) – Custom header parameters for the request.policy (
Optional
[Any
]) – A policy document that contains the permissions for theRestApi
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
[CfnTag
]]) – An array of arbitrary tags (key-value pairs) to associate with the API.
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
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.
- Return type
None
-
add_override
(path, value)¶ Adds an override to the synthesized CloudFormation resource.
To add a property override, either use
addPropertyOverride
or prefixpath
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 toaddOverride
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: truedefault (
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
-
get_metadata
(key)¶ Retrieve a value value from the CloudFormation Resource Metadata.
- Parameters
key (
str
) –- See
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.
- Return type
Any
-
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
¶ .
HEADER
to read the API key from theX-API-Key
header of a request.AUTHORIZER
to read the API key from theUsageIdentifierKey
from a Lambda authorizer.
- Link
- Type
The source of the API key for metering requests according to a usage plan. Valid values are
- Return type
Optional
[str
]
-
attr_root_resource_id
¶ The root resource ID for a
RestApi
resource, such asa0bc123d4e
.- CloudformationAttribute
RootResourceId
- Return type
str
-
binary_media_types
¶ The list of binary media types that are supported by the
RestApi
resource.Use
~1
instead of/
in the media types, for exampleimage~1png
orapplication~1octet-stream
. By default,RestApi
supports only UTF-8-encoded text payloads. Duplicates are not allowed. For more information, see Enable Support for Binary Payloads in API Gateway in the API Gateway Developer Guide .- Link
- Return type
Optional
[List
[str
]]
-
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.
-
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.
-
cfn_options
¶ Options for this resource, such as condition, update policy etc.
- Return type
-
cfn_resource_type
¶ AWS resource type.
- Return type
str
-
clone_from
¶ The ID of the
RestApi
resource that you want to clone.
-
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.
- Return type
List
[str
]
-
description
¶ A description of the
RestApi
resource.
-
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.
-
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.
-
fail_on_warnings
¶ Indicates whether to roll back the resource if a warning occurs while API Gateway is creating the
RestApi
resource.- Link
- Return type
Union
[bool
,IResolvable
,None
]
-
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)
.- Return type
str
- 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
- Return type
Union
[int
,float
,None
]
-
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
ormerge
.For
overwrite
, the new API definition replaces the existing one. The existing API identifier remains unchanged.For
merge
, the new API definition takes precedence, but any container types such as endpoint configurations and binary media types are merged with the existing API. Usemerge
to define top-levelRestApi
properties in addition to using OpenAPI. Generally, it’s preferred to use API Gateway’s OpenAPI extensions to model these properties.If you don’t specify this property, a default value is chosen. For REST APIs created before March 29, 2021, the default is
overwrite
. Otherwise, the default value ismerge
.
-
name
¶ A name for the
RestApi
resource.
-
node
¶ The construct tree node associated with this construct.
- Return type
-
parameters
¶ Custom header parameters for the request.
- Link
- Return type
Union
[IResolvable
,Mapping
[str
,str
],None
]
-
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"*"
.
-
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 })
.- Return type
str
-
stack
¶ The stack in which this element is defined.
CfnElements must be defined within a stack scope (directly or indirectly).
- Return type
An array of arbitrary tags (key-value pairs) to associate with the API.
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 or its custom domain name. Valid values include:. -EDGE
: For an edge-optimized API and its custom domain name. -REGIONAL
: For a regional API and its custom domain name. -PRIVATE
: For a private API.vpc_endpoint_ids (
Optional
[Sequence
[str
]]) –A list of VPC endpoint IDs of an API ( AWS::ApiGateway::RestApi ) against which to create Route53 ALIASes. It is only supported for
PRIVATE
endpoint type.
- Link
- 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
¶ .
EDGE
: For an edge-optimized API and its custom domain name.REGIONAL
: For a regional API and its custom domain name.PRIVATE
: For a private API.
- Link
- Type
A list of endpoint types of an API or its custom domain name. Valid values include
- Return type
Optional
[List
[str
]]
-
vpc_endpoint_ids
¶ //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html>`_ ) against which to create Route53 ALIASes. It is only supported for
PRIVATE
endpoint type.- Link
- Type
A list of VPC endpoint IDs of an API ( `AWS::ApiGateway::RestApi <https
- Return type
Optional
[List
[str
]]
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
- 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.
-
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.
-
key
¶ The file name of the OpenAPI file (Amazon S3 object name).
-
version
¶ For versioning-enabled buckets, a specific version of the OpenAPI file.