aws-cdk-lib.aws_apigateway.ProxyResource

class ProxyResource (construct)

LanguageType name
.NETAmazon.CDK.AWS.APIGateway.ProxyResource
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#ProxyResource
Javasoftware.amazon.awscdk.services.apigateway.ProxyResource
Pythonaws_cdk.aws_apigateway.ProxyResource
TypeScript (source)aws-cdk-lib » aws_apigateway » ProxyResource

Implements IConstruct, IDependable, IResource, IResource

Defines a {proxy+} greedy resource and an ANY method on a route.

See also: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html

Example

declare const resource: apigateway.Resource;
declare const handler: lambda.Function;
const proxy = resource.addProxy({
  defaultIntegration: new apigateway.LambdaIntegration(handler),

  // "false" will require explicitly adding methods on the `proxy` resource
  anyMethod: true // "true" is the default
});

Initializer

new ProxyResource(scope: Construct, id: string, props: ProxyResourceProps)

Parameters

  • scope Construct
  • id string
  • props ProxyResourceProps

Construct Props

NameTypeDescription
parentIResourceThe parent resource of this resource.
anyMethod?booleanAdds an "ANY" method to this resource.
defaultCorsPreflightOptions?CorsOptionsAdds a CORS preflight OPTIONS method to this resource and all child resources.
defaultIntegration?IntegrationAn integration to use as a default for all methods created within this API unless an integration is specified.
defaultMethodOptions?MethodOptionsMethod options to use as a default for all methods created within this API unless custom options are specified.

parent

Type: IResource

The parent resource of this resource.

You can either pass another Resource object or a RestApi object here.


anyMethod?

Type: boolean (optional, default: true)

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.


defaultCorsPreflightOptions?

Type: CorsOptions (optional, default: CORS is disabled)

Adds a CORS preflight OPTIONS method to this resource and all child resources.

You can add CORS at the resource-level using addCorsPreflight.


defaultIntegration?

Type: Integration (optional, default: Inherited from parent.)

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


defaultMethodOptions?

Type: MethodOptions (optional, default: Inherited from parent.)

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

Properties

NameTypeDescription
apiIRestApiThe rest API that this resource is part of.
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
pathstringThe full path of this resource.
resourceIdstringThe ID of the resource.
stackStackThe stack in which this resource is defined.
anyMethod?MethodIf props.anyMethod is true, this will be the reference to the 'ANY' method associated with this proxy resource.
defaultCorsPreflightOptions?CorsOptionsDefault options for CORS preflight OPTIONS method.
defaultIntegration?IntegrationAn integration to use as a default for all methods created within this API unless an integration is specified.
defaultMethodOptions?MethodOptionsMethod options to use as a default for all methods created within this API unless custom options are specified.
parentResource?IResourceThe parent of this resource or undefined for the root resource.

api

Type: IRestApi

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.


env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


path

Type: string

The full path of this resource.


resourceId

Type: string

The ID of the resource.


stack

Type: Stack

The stack in which this resource is defined.


anyMethod?

Type: Method (optional)

If props.anyMethod is true, this will be the reference to the 'ANY' method associated with this proxy resource.


defaultCorsPreflightOptions?

Type: CorsOptions (optional)

Default options for CORS preflight OPTIONS method.


defaultIntegration?

Type: Integration (optional)

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


defaultMethodOptions?

Type: MethodOptions (optional)

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


parentResource?

Type: IResource (optional)

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

Methods

NameDescription
addCorsPreflight(options)Adds an OPTIONS method to this resource which responds to Cross-Origin Resource Sharing (CORS) preflight requests.
addMethod(httpMethod, integration?, options?)Defines a new method for this resource.
addProxy(options?)Adds a greedy proxy resource ("{proxy+}") and an ANY method to this route.
addResource(pathPart, options?)Defines a new child resource where this resource is the parent.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
getResource(pathPart)Retrieves a child resource by path part.
resourceForPath(path)Gets or create all resources leading up to the specified path.
toString()Returns a string representation of this construct.

addCorsPreflight(options)

public addCorsPreflight(options: CorsOptions): Method

Parameters

  • options CorsOptions

Returns

  • Method

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.


addMethod(httpMethod, integration?, options?)

public addMethod(httpMethod: string, integration?: Integration, options?: MethodOptions): Method

Parameters

  • httpMethod string
  • integration Integration
  • options MethodOptions

Returns

  • Method

Defines a new method for this resource.


addProxy(options?)

public addProxy(options?: ProxyResourceOptions): ProxyResource

Parameters

  • options ProxyResourceOptions

Returns

  • ProxyResource

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


addResource(pathPart, options?)

public addResource(pathPart: string, options?: ResourceOptions): Resource

Parameters

  • pathPart string
  • options ResourceOptions

Returns

  • Resource

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


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

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


getResource(pathPart)

public getResource(pathPart: string): IResource

Parameters

  • pathPart string

Returns

  • IResource

Retrieves a child resource by path part.


resourceForPath(path)

public resourceForPath(path: string): Resource

Parameters

  • path string

Returns

  • Resource

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.

toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.