Class Method
Inherited Members
Namespace: Amazon.CDK.AWS.APIGateway
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Method : Resource, IResource, IConstruct, IDependable, IEnvironmentAware
Syntax (vb)
Public Class Method Inherits Resource Implements IResource, IConstruct, IDependable, IEnvironmentAware
Remarks
ExampleMetadata: infused
Examples
LambdaIntegration integration;
var api = new RestApi(this, "hello-api");
var v1 = api.Root.AddResource("v1");
var echo = v1.AddResource("echo");
var echoMethod = echo.AddMethod("GET", integration, new MethodOptions { ApiKeyRequired = true });
var plan = api.AddUsagePlan("UsagePlan", new UsagePlanProps {
Name = "Easy",
Throttle = new ThrottleSettings {
RateLimit = 10,
BurstLimit = 2
}
});
var key = api.AddApiKey("ApiKey");
plan.AddApiKey(key);
Synopsis
Constructors
| Method(Construct, string, IMethodProps) |
Properties
| Api | The API Gateway RestApi associated with this method. |
| HttpMethod | |
| MethodArn | Returns an execute-api ARN for this method:. |
| MethodId | |
| PROPERTY_INJECTION_ID | Uniquely identifies this class. |
| Resource | |
| TestMethodArn | Returns an execute-api ARN for this method's "test-invoke-stage" stage. |
Methods
| AddMethodResponse(IMethodResponse) | Add a method response to this method. |
| GrantExecute(IGrantable) | Grants an IAM principal permission to invoke this method. |
| Metric(string, IStageRef, IMetricOptions?) | Returns the given named metric for this API method. |
| MetricCacheHitCount(IStageRef, IMetricOptions?) | Metric for the number of requests served from the API cache in a given period. |
| MetricCacheMissCount(IStageRef, IMetricOptions?) | Metric for the number of requests served from the backend in a given period, when API caching is enabled. |
| MetricClientError(IStageRef, IMetricOptions?) | Metric for the number of client-side errors captured in a given period. |
| MetricCount(IStageRef, IMetricOptions?) | Metric for the total number API requests in a given period. |
| MetricIntegrationLatency(IStageRef, IMetricOptions?) | Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend. |
| MetricLatency(IStageRef, IMetricOptions?) | The time between when API Gateway receives a request from a client and when it returns a response to the client. |
| MetricServerError(IStageRef, IMetricOptions?) | Metric for the number of server-side errors captured in a given period. |
Constructors
Method(Construct, string, IMethodProps)
public Method(Construct scope, string id, IMethodProps props)
Parameters
- scope Construct
- id string
- props IMethodProps
Remarks
ExampleMetadata: infused
Examples
LambdaIntegration integration;
var api = new RestApi(this, "hello-api");
var v1 = api.Root.AddResource("v1");
var echo = v1.AddResource("echo");
var echoMethod = echo.AddMethod("GET", integration, new MethodOptions { ApiKeyRequired = true });
var plan = api.AddUsagePlan("UsagePlan", new UsagePlanProps {
Name = "Easy",
Throttle = new ThrottleSettings {
RateLimit = 10,
BurstLimit = 2
}
});
var key = api.AddApiKey("ApiKey");
plan.AddApiKey(key);
Properties
Api
The API Gateway RestApi associated with this method.
public virtual IRestApi Api { get; }
Property Value
Remarks
ExampleMetadata: infused
HttpMethod
public virtual string HttpMethod { get; }
Property Value
Remarks
ExampleMetadata: infused
Examples
LambdaIntegration integration;
var api = new RestApi(this, "hello-api");
var v1 = api.Root.AddResource("v1");
var echo = v1.AddResource("echo");
var echoMethod = echo.AddMethod("GET", integration, new MethodOptions { ApiKeyRequired = true });
var plan = api.AddUsagePlan("UsagePlan", new UsagePlanProps {
Name = "Easy",
Throttle = new ThrottleSettings {
RateLimit = 10,
BurstLimit = 2
}
});
var key = api.AddApiKey("ApiKey");
plan.AddApiKey(key);
MethodArn
Returns an execute-api ARN for this method:.
public virtual string MethodArn { get; }
Property Value
Remarks
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
MethodId
PROPERTY_INJECTION_ID
Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
ExampleMetadata: infused
Resource
public virtual IResource Resource { get; }
Property Value
Remarks
ExampleMetadata: infused
Examples
LambdaIntegration integration;
var api = new RestApi(this, "hello-api");
var v1 = api.Root.AddResource("v1");
var echo = v1.AddResource("echo");
var echoMethod = echo.AddMethod("GET", integration, new MethodOptions { ApiKeyRequired = true });
var plan = api.AddUsagePlan("UsagePlan", new UsagePlanProps {
Name = "Easy",
Throttle = new ThrottleSettings {
RateLimit = 10,
BurstLimit = 2
}
});
var key = api.AddApiKey("ApiKey");
plan.AddApiKey(key);
TestMethodArn
Returns an execute-api ARN for this method's "test-invoke-stage" stage.
public virtual string TestMethodArn { get; }
Property Value
Remarks
This stage is used by the AWS Console UI when testing the method.
Methods
AddMethodResponse(IMethodResponse)
Add a method response to this method.
public virtual void AddMethodResponse(IMethodResponse methodResponse)
Parameters
- methodResponse IMethodResponse
Remarks
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.
GrantExecute(IGrantable)
Grants an IAM principal permission to invoke this method.
public virtual Grant GrantExecute(IGrantable grantee)
Parameters
- grantee IGrantable
the principal.
Returns
Remarks
ExampleMetadata: infused
Metric(string, IStageRef, IMetricOptions?)
Returns the given named metric for this API method.
public virtual Metric Metric(string metricName, IStageRef stage, IMetricOptions? props = null)
Parameters
- metricName string
- stage IStageRef
- props IMetricOptions
Returns
Remarks
ExampleMetadata: infused
MetricCacheHitCount(IStageRef, IMetricOptions?)
Metric for the number of requests served from the API cache in a given period.
public virtual Metric MetricCacheHitCount(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
Default: - sum over 5 minutes
MetricCacheMissCount(IStageRef, IMetricOptions?)
Metric for the number of requests served from the backend in a given period, when API caching is enabled.
public virtual Metric MetricCacheMissCount(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
Default: - sum over 5 minutes
MetricClientError(IStageRef, IMetricOptions?)
Metric for the number of client-side errors captured in a given period.
public virtual Metric MetricClientError(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
Default: - sum over 5 minutes
MetricCount(IStageRef, IMetricOptions?)
Metric for the total number API requests in a given period.
public virtual Metric MetricCount(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
Default: - sample count over 5 minutes
MetricIntegrationLatency(IStageRef, IMetricOptions?)
Metric for the time between when API Gateway relays a request to the backend and when it receives a response from the backend.
public virtual Metric MetricIntegrationLatency(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
Default: - average over 5 minutes.
MetricLatency(IStageRef, IMetricOptions?)
The time between when API Gateway receives a request from a client and when it returns a response to the client.
public virtual Metric MetricLatency(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
The latency includes the integration latency and other API Gateway overhead.
Default: - average over 5 minutes.
MetricServerError(IStageRef, IMetricOptions?)
Metric for the number of server-side errors captured in a given period.
public virtual Metric MetricServerError(IStageRef stage, IMetricOptions? props = null)
Parameters
- stage IStageRef
- props IMetricOptions
Returns
Remarks
Default: - sum over 5 minutes