aws-cdk-lib.aws_apigateway.Method

class Method (construct)

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

Implements IConstruct, IDependable, IResource

Example

declare const integration: apigateway.LambdaIntegration;

const api = new apigateway.RestApi(this, 'hello-api');

const v1 = api.root.addResource('v1');
const echo = v1.addResource('echo');
const echoMethod = echo.addMethod('GET', integration, { apiKeyRequired: true });

const plan = api.addUsagePlan('UsagePlan', {
  name: 'Easy',
  throttle: {
    rateLimit: 10,
    burstLimit: 2
  }
});

const key = api.addApiKey('ApiKey');
plan.addApiKey(key);

Initializer

new Method(scope: Construct, id: string, props: MethodProps)

Parameters

  • scope Construct
  • id string
  • props MethodProps

Construct Props

NameTypeDescription
httpMethodstringThe HTTP method ("GET", "POST", "PUT", ...) that clients use to call this method.
resourceIResourceThe resource this method is associated with.
integration?IntegrationThe backend system that the method calls when it receives a request.
options?MethodOptionsMethod options.

httpMethod

Type: string

The HTTP method ("GET", "POST", "PUT", ...) that clients use to call this method.


resource

Type: IResource

The resource this method is associated with.

For root resource methods, specify the RestApi object.


integration?

Type: Integration (optional, default: a new MockIntegration.)

The backend system that the method calls when it receives a request.


options?

Type: MethodOptions (optional, default: No options.)

Method options.

Properties

NameTypeDescription
apiIRestApiThe API Gateway RestApi associated with this method.
envResourceEnvironmentThe environment this resource belongs to.
httpMethodstring
methodArnstringReturns an execute-api ARN for this method:.
methodIdstring
nodeNodeThe tree node.
resourceIResource
stackStackThe stack in which this resource is defined.
testMethodArnstringReturns an execute-api ARN for this method's "test-invoke-stage" stage.

api

Type: IRestApi

The API Gateway RestApi associated with this method.


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.


httpMethod

Type: string


methodArn

Type: string

Returns an execute-api ARN for this method:.

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


methodId

Type: string


node

Type: Node

The tree node.


resource

Type: IResource


stack

Type: Stack

The stack in which this resource is defined.


testMethodArn

Type: string

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.

Methods

NameDescription
addMethodResponse(methodResponse)Add a method response to this method.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
grantExecute(grantee)Grants an IAM principal permission to invoke this method.
metric(metricName, stage, props?)Returns the given named metric for this API method.
metricCacheHitCount(stage, props?)Metric for the number of requests served from the API cache in a given period.
metricCacheMissCount(stage, props?)Metric for the number of requests served from the backend in a given period, when API caching is enabled.
metricClientError(stage, props?)Metric for the number of client-side errors captured in a given period.
metricCount(stage, props?)Metric for the total number API requests in a given period.
metricIntegrationLatency(stage, props?)Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.
metricLatency(stage, props?)The time between when API Gateway receives a request from a client and when it returns a response to the client.
metricServerError(stage, props?)Metric for the number of server-side errors captured in a given period.
toString()Returns a string representation of this construct.

addMethodResponse(methodResponse)

public addMethodResponse(methodResponse: MethodResponse): void

Parameters

  • methodResponse MethodResponse

Add a method response to this method.


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


grantExecute(grantee)

public grantExecute(grantee: IGrantable): Grant

Parameters

  • grantee IGrantable — the principal.

Returns

  • Grant

Grants an IAM principal permission to invoke this method.


metric(metricName, stage, props?)

public metric(metricName: string, stage: IStage, props?: MetricOptions): Metric

Parameters

  • metricName string
  • stage IStage
  • props MetricOptions

Returns

  • Metric

Returns the given named metric for this API method.


metricCacheHitCount(stage, props?)

public metricCacheHitCount(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

Metric for the number of requests served from the API cache in a given period.


metricCacheMissCount(stage, props?)

public metricCacheMissCount(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

Metric for the number of requests served from the backend in a given period, when API caching is enabled.


metricClientError(stage, props?)

public metricClientError(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

Metric for the number of client-side errors captured in a given period.


metricCount(stage, props?)

public metricCount(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

Metric for the total number API requests in a given period.


metricIntegrationLatency(stage, props?)

public metricIntegrationLatency(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.


metricLatency(stage, props?)

public metricLatency(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

The time between when API Gateway receives a request from a client and when it returns a response to the client.

The latency includes the integration latency and other API Gateway overhead.


metricServerError(stage, props?)

public metricServerError(stage: IStage, props?: MetricOptions): Metric

Parameters

  • stage IStage
  • props MetricOptions

Returns

  • Metric

Metric for the number of server-side errors captured in a given period.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.