class Method (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.APIGateway.Method |
![]() | software.amazon.awscdk.services.apigateway.Method |
![]() | aws_cdk.aws_apigateway.Method |
![]() | @aws-cdk/aws-apigateway » Method |
Implements
IConstruct
, 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 | Construct | The construct tree node associated with this construct. |
resource | IResource | |
rest | Rest | The RestApi associated with this Method. |
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:
Construct
The construct tree node associated with this construct.
resource
Type:
IResource
restApi
⚠️ Deprecated: - Throws an error if this Resource is not associated with an instance of RestApi
. Use api
instead.
Type:
Rest
The RestApi associated with this Method.
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. |
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.
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
).
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.