IResource

class aws_cdk.aws_apigateway.IResource(*args, **kwargs)

Bases: aws_cdk.core.IResource, typing_extensions.Protocol

__init__(*args, **kwargs)

Methods

add_cors_preflight(*, allow_origins, allow_credentials=None, allow_headers=None, allow_methods=None, disable_cache=None, expose_headers=None, max_age=None, status_code=None)

Adds an OPTIONS method to this resource which responds to Cross-Origin Resource Sharing (CORS) preflight requests.

Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own.

Parameters
  • options – CORS options.

  • allow_origins (List[str]) – Specifies the list of origins that are allowed to make requests to this resource. If you wish to allow all origins, specify Cors.ALL_ORIGINS or [ * ]. Responses will include the Access-Control-Allow-Origin response header. If Cors.ALL_ORIGINS is specified, the Vary: Origin response header will also be included.

  • allow_credentials (Optional[bool]) – The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to frontend JavaScript code when the request’s credentials mode (Request.credentials) is “include”. When a request’s credentials mode (Request.credentials) is “include”, browsers will only expose the response to frontend JavaScript code if the Access-Control-Allow-Credentials value is true. Credentials are cookies, authorization headers or TLS client certificates. Default: false

  • allow_headers (Optional[List[str]]) – The Access-Control-Allow-Headers response header is used in response to a preflight request which includes the Access-Control-Request-Headers to indicate which HTTP headers can be used during the actual request. Default: Cors.DEFAULT_HEADERS

  • allow_methods (Optional[List[str]]) – The Access-Control-Allow-Methods response header specifies the method or methods allowed when accessing the resource in response to a preflight request. If ANY is specified, it will be expanded to Cors.ALL_METHODS. Default: Cors.ALL_METHODS

  • disable_cache (Optional[bool]) – Sets Access-Control-Max-Age to -1, which means that caching is disabled. This option cannot be used with maxAge. Default: - cache is enabled

  • expose_headers (Optional[List[str]]) – The Access-Control-Expose-Headers response header indicates which headers can be exposed as part of the response by listing their names. If you want clients to be able to access other headers, you have to list them using the Access-Control-Expose-Headers header. Default: - only the 6 CORS-safelisted response headers are exposed: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma

  • max_age (Optional[Duration]) – The Access-Control-Max-Age response header indicates how long the results of a preflight request (that is the information contained in the Access-Control-Allow-Methods and Access-Control-Allow-Headers headers) can be cached. To disable caching altogther use disableCache: true. Default: - browser-specific (see reference)

  • status_code (Union[int, float, None]) – Specifies the response status code returned from the OPTIONS method. Default: 204

return :rtype: Method :return: a Method object

see :see: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

add_method(http_method, target=None, *, api_key_required=None, authorization_type=None, authorizer=None, method_responses=None, operation_name=None, request_models=None, request_parameters=None, request_validator=None)

Defines a new method for this resource.

Parameters
  • http_method (str) – The HTTP method.

  • target (Optional[Integration]) – The target backend integration for this method.

  • options – Method options, such as authentication.

  • api_key_required (Optional[bool]) – Indicates whether the method requires clients to submit a valid API key. Default: false

  • authorization_type (Optional[AuthorizationType]) – Method authorization. Default: None open access

  • authorizer (Optional[IAuthorizer]) – If authorizationType is Custom, this specifies the ID of the method authorizer resource.

  • method_responses (Optional[List[MethodResponse]]) – The responses that can be sent to the client who calls the method. Default: None This property is not required, but if these are not supplied for a Lambda proxy integration, the Lambda function must return a value of the correct format, for the integration response to be correctly mapped to a response to the client.

  • operation_name (Optional[str]) – A friendly operation name for the method. For example, you can assign the OperationName of ListPets for the GET /pets method.

  • request_models (Optional[Mapping[str, IModel]]) – The resources that are used for the response’s content type. Specify request models as key-value pairs (string-to-string mapping), with a content type as the key and a Model resource name as the value

  • request_parameters (Optional[Mapping[str, bool]]) – The request parameters that API Gateway accepts. Specify request parameters as key-value pairs (string-to-Boolean mapping), with a source as the key and a Boolean as the value. The Boolean specifies whether a parameter is required. A source must match the format method.request.location.name, where the location is querystring, path, or header, and name is a valid, unique parameter name. Default: None

  • request_validator (Optional[IRequestValidator]) – The ID of the associated request validator.

return :rtype: Method :return: The newly created Method object.

add_proxy(*, any_method=None, default_cors_preflight_options=None, default_integration=None, default_method_options=None)

Adds a greedy proxy resource (“{proxy+}”) and an ANY method to this route.

Parameters
  • options – Default integration and method options.

  • any_method (Optional[bool]) – Adds an “ANY” method to this resource. If set to false, you will have to explicitly add methods to this resource after it’s created. Default: true

  • default_cors_preflight_options (Optional[CorsOptions]) – Adds a CORS preflight OPTIONS method to this resource and all child resources. You can add CORS at the resource-level using addCorsPreflight. Default: - CORS is disabled

  • default_integration (Optional[Integration]) – An integration to use as a default for all methods created within this API unless an integration is specified. Default: - Inherited from parent.

  • default_method_options (Optional[MethodOptions]) – Method options to use as a default for all methods created within this API unless custom options are specified. Default: - Inherited from parent.

Return type

ProxyResource

add_resource(path_part, *, default_cors_preflight_options=None, default_integration=None, default_method_options=None)

Defines a new child resource where this resource is the parent.

Parameters
  • path_part (str) – The path part for the child resource.

  • options – Resource options.

  • default_cors_preflight_options (Optional[CorsOptions]) – Adds a CORS preflight OPTIONS method to this resource and all child resources. You can add CORS at the resource-level using addCorsPreflight. Default: - CORS is disabled

  • default_integration (Optional[Integration]) – An integration to use as a default for all methods created within this API unless an integration is specified. Default: - Inherited from parent.

  • default_method_options (Optional[MethodOptions]) – Method options to use as a default for all methods created within this API unless custom options are specified. Default: - Inherited from parent.

return :rtype: Resource :return: A Resource object

get_resource(path_part)

Retrieves a child resource by path part.

Parameters

path_part (str) – The path part of the child resource.

return :rtype: Optional[IResource] :return: the child resource or undefined if not found

resource_for_path(path)

Gets or create all resources leading up to the specified path.

  • Path may only start with “/” if this method is called on the root resource.

  • All resources are created using default options.

Parameters

path (str) – The relative path.

return :rtype: Resource :return: a new or existing resource.

Attributes

default_cors_preflight_options

Default options for CORS preflight OPTIONS method.

Return type

Optional[CorsOptions]

default_integration

An integration to use as a default for all methods created within this API unless an integration is specified.

Return type

Optional[Integration]

default_method_options

Method options to use as a default for all methods created within this API unless custom options are specified.

Return type

Optional[MethodOptions]

node

The construct node in the tree.

Return type

ConstructNode

parent_resource

The parent of this resource or undefined for the root resource.

Return type

Optional[IResource]

path

The full path of this resuorce.

Return type

str

resource_id

The ID of the resource.

attribute: :attribute:: true

Return type

str

rest_api

The rest API that this resource is part of.

The reason we need the RestApi object itself and not just the ID is because the model is being tracked by the top-level RestApi object for the purpose of calculating it’s hash to determine the ID of the deployment. This allows us to automatically update the deployment when the model of the REST API changes.

Return type

RestApi

stack

The stack in which this resource is defined.

Return type

Stack