class Method (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.APIGateway.Method |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#Method |
![]() | software.amazon.awscdk.services.apigateway.Method |
![]() | aws_cdk.aws_apigateway.Method |
![]() | 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
Method
Props
Construct Props
Name | Type | Description |
---|---|---|
http | string | The HTTP method ("GET", "POST", "PUT", ...) that clients use to call this method. |
resource | IResource | The resource this method is associated with. |
integration? | Integration | The backend system that the method calls when it receives a request. |
options? | Method | Method 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:
Method
(optional, default: No options.)
Method options.
Properties
Name | Type | Description |
---|---|---|
api | IRest | The API Gateway RestApi associated with this method. |
env | Resource | The environment this resource belongs to. |
http | string | |
method | string | Returns an execute-api ARN for this method:. |
method | string | |
node | Node | The tree node. |
resource | IResource | |
stack | Stack | The stack in which this resource is defined. |
test | string | Returns an execute-api ARN for this method's "test-invoke-stage" stage. |
api
Type:
IRest
The API Gateway RestApi associated with this method.
env
Type:
Resource
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
Name | Description |
---|---|
add | Add a method response to this method. |
apply | Apply the given removal policy to this resource. |
grant | Grants an IAM principal permission to invoke this method. |
metric(metricName, stage, props?) | Returns the given named metric for this API method. |
metric | Metric for the number of requests served from the API cache in a given period. |
metric | Metric for the number of requests served from the backend in a given period, when API caching is enabled. |
metric | Metric for the number of client-side errors captured in a given period. |
metric | Metric for the total number API requests in a given period. |
metric | Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend. |
metric | The time between when API Gateway receives a request from a client and when it returns a response to the client. |
metric | Metric for the number of server-side errors captured in a given period. |
to | Returns a string representation of this construct. |
addMethodResponse(methodResponse)
public addMethodResponse(methodResponse: MethodResponse): void
Parameters
- methodResponse
Method
Response
Add a method response to this method.
You should only add one method reponse for every status code. The API allows it for historical reasons, but will add a warning if this happens. If you do, your Method will nondeterministically use one of the responses, and ignore the rest.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
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
).
grantExecute(grantee)
public grantExecute(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— the principal.
Returns
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
Metric
Options
Returns
Returns the given named metric for this API method.
metricCacheHitCount(stage, props?)
public metricCacheHitCount(stage: IStage, props?: MetricOptions): Metric
Parameters
- stage
IStage
- props
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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
Metric
Options
Returns
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.