Method

class aws_cdk.aws_apigateway.Method(scope, id, *, http_method, resource, integration=None, options=None)

Bases: Resource

ExampleMetadata:

infused

Example:

# integration: apigateway.LambdaIntegration


api = apigateway.RestApi(self, "hello-api")

v1 = api.root.add_resource("v1")
echo = v1.add_resource("echo")
echo_method = echo.add_method("GET", integration, api_key_required=True)

plan = api.add_usage_plan("UsagePlan",
    name="Easy",
    throttle=apigateway.ThrottleSettings(
        rate_limit=10,
        burst_limit=2
    )
)

key = api.add_api_key("ApiKey")
plan.add_api_key(key)
Parameters:
  • scope (Construct) –

  • id (str) –

  • http_method (str) – The HTTP method (“GET”, “POST”, “PUT”, …) that clients use to call this method.

  • resource (IResource) – The resource this method is associated with. For root resource methods, specify the RestApi object.

  • integration (Optional[Integration]) – The backend system that the method calls when it receives a request. Default: - a new MockIntegration.

  • options (Union[MethodOptions, Dict[str, Any], None]) – Method options. Default: - No options.

Methods

add_method_response(*, status_code, response_models=None, response_parameters=None)

Add a method response to this method.

Parameters:
  • status_code (str) – The method response’s status code, which you map to an IntegrationResponse. Required.

  • response_models (Optional[Mapping[str, IModel]]) – The resources used for the response’s content type. Specify response models as key-value pairs (string-to-string maps), with a content type as the key and a Model resource name as the value. Default: None

  • response_parameters (Optional[Mapping[str, bool]]) – Response parameters that API Gateway sends to the client that called a method. Specify response parameters as key-value pairs (string-to-Boolean maps), with a destination as the key and a Boolean as the value. Specify the destination using the following pattern: method.response.header.name, where the name is a valid, unique header name. The Boolean specifies whether a parameter is required. Default: None

Return type:

None

apply_removal_policy(policy)

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

Parameters:

policy (RemovalPolicy) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

api

The API Gateway RestApi associated with this method.

env

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.

http_method
method_arn

.

arn:aws:execute-api:{region}:{account}:{restApiId}/{stage}/{method}/{path}

NOTE: {stage} will refer to the restApi.deploymentStage, which will automatically set if auto-deploy is enabled, or can be explicitly assigned. When not configured, {stage} will be set to ‘*’, as a shorthand for ‘all stages’.

Attribute:

true

Type:

Returns an execute-api ARN for this method

method_id

true

Type:

attribute

node

The construct tree node associated with this construct.

resource
rest_api

(deprecated) The RestApi associated with this Method.

Deprecated:
  • Throws an error if this Resource is not associated with an instance of RestApi. Use api instead.

Stability:

deprecated

stack

The stack in which this resource is defined.

test_method_arn

Returns an execute-api ARN for this method’s “test-invoke-stage” stage.

This stage is used by the AWS Console UI when testing the method.

Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool