Resource: awsApiGatewayMethodSettings
Manages API Gateway Stage Method Settings. For example, CloudWatch logging and metrics.
\~> NOTE: We recommend using this resource in conjunction with the awsApiGatewayStage
resource instead of a stage managed by the awsApiGatewayDeployment
resource optional stageName
argument. Stages managed by the awsApiGatewayDeployment
resource are recreated on redeployment and this resource will require a second apply to recreate the method settings.
Example Usage
An end-to-end example of a REST API configured with OpenAPI can be found in the /examples/apiGatewayRestApiOpenapi
directory within the GitHub repository.
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsApiGatewayRestApiExample = new aws.apiGatewayRestApi.ApiGatewayRestApi(
this,
"example",
{
body: '${jsonencode({\n openapi = "3.0.1"\n info = {\n title = "example"\n version = "1.0"\n }\n paths = {\n "/path1" = {\n get = {\n x-amazon-apigateway-integration = {\n httpMethod = "GET"\n payloadFormatVersion = "1.0"\n type = "HTTP_PROXY"\n uri = "https://ip-ranges.amazonaws.com/ip-ranges.json"\n }\n }\n }\n }\n })}',
name: "example",
}
);
const awsApiGatewayDeploymentExample =
new aws.apiGatewayDeployment.ApiGatewayDeployment(this, "example_1", {
restApiId: awsApiGatewayRestApiExample.id,
triggers: {
redeployment: `\${sha1(jsonencode(${awsApiGatewayRestApiExample.body}))}`,
},
});
awsApiGatewayDeploymentExample.addOverride("lifecycle", [
{
create_before_destroy: true,
},
]);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayDeploymentExample.overrideLogicalId("example");
const awsApiGatewayStageExample = new aws.apiGatewayStage.ApiGatewayStage(
this,
"example_2",
{
deploymentId: awsApiGatewayDeploymentExample.id,
restApiId: awsApiGatewayRestApiExample.id,
stageName: "example",
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsApiGatewayStageExample.overrideLogicalId("example");
new aws.apiGatewayMethodSettings.ApiGatewayMethodSettings(this, "all", {
methodPath: "*/*",
restApiId: awsApiGatewayRestApiExample.id,
settings: {
loggingLevel: "ERROR",
metricsEnabled: true,
},
stageName: awsApiGatewayStageExample.stageName,
});
new aws.apiGatewayMethodSettings.ApiGatewayMethodSettings(
this,
"path_specific",
{
methodPath: "path1/GET",
restApiId: awsApiGatewayRestApiExample.id,
settings: {
loggingLevel: "INFO",
metricsEnabled: true,
},
stageName: awsApiGatewayStageExample.stageName,
}
);
Argument Reference
The following arguments are supported:
restApiId
- (Required) ID of the REST APIstageName
- (Required) Name of the stagemethodPath
- (Required) Method path defined as{resourcePath}/{httpMethod}
for an individual method override, or*/*
for overriding all methods in the stage. Ensure to trim any leading forward slashes in the path (e.g.,trimprefix(awsApiGatewayResourceExamplePath, "/")
).settings
- (Required) Settings block, see below.
settings
metricsEnabled
- (Optional) Whether Amazon CloudWatch metrics are enabled for this method.loggingLevel
- (Optional) Logging level for this method, which effects the log entries pushed to Amazon CloudWatch Logs. The available levels areoff
,error
, andinfo
.dataTraceEnabled
- (Optional) Whether data trace logging is enabled for this method, which effects the log entries pushed to Amazon CloudWatch Logs.throttlingBurstLimit
- (Optional) Throttling burst limit. Default:1
(throttling disabled).throttlingRateLimit
- (Optional) Throttling rate limit. Default:1
(throttling disabled).cachingEnabled
- (Optional) Whether responses should be cached and returned for requests. A cache cluster must be enabled on the stage for responses to be cached.cacheTtlInSeconds
- (Optional) Time to live (TTL), in seconds, for cached responses. The higher the TTL, the longer the response will be cached.cacheDataEncrypted
- (Optional) Whether the cached responses are encrypted.requireAuthorizationForCacheControl
- (Optional) Whether authorization is required for a cache invalidation request.unauthorizedCacheControlHeaderStrategy
- (Optional) How to handle unauthorized requests for cache invalidation. The available values areFAIL_WITH_403
,SUCCEED_WITH_RESPONSE_HEADER
,SUCCEED_WITHOUT_RESPONSE_HEADER
.
Attributes Reference
No additional attributes are exported.
Import
awsApiGatewayMethodSettings
can be imported using restApiId/stageName/methodPath
, e.g.,