-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amazon API Gateway Access Logging Support #2406
Comments
The aws api should already support this with a patch operation on http://docs.aws.amazon.com/cli/latest/reference/apigateway/update-stage.html In the interim Im using a null resource to accomplish this. resource "null_resource" "access-logging" {
depends_on = ["aws_cloudwatch_log_group.cloudwatch_access_log_group"]
count = "${var.access_logs_enabled == "true" ? 1 : 0}"
triggers {
log_format = "${file("log_format.json")}"
log_group = "${local.cloudwatch_access_log_group_arn}"
}
provisioner "local-exec" {
command = "aws apigateway update-stage --rest-api-id ${aws_api_gateway_deployment.deployment.rest_api_id} --stage-name ${aws_api_gateway_deployment.deployment.stage_name} --patch-operations op=replace,path=/accessLogSettings/destinationArn,value='${local.cloudwatch_access_log_group_arn}'"
}
provisioner "local-exec" {
command = "aws apigateway update-stage --rest-api-id ${aws_api_gateway_deployment.deployment.rest_api_id} --stage-name ${aws_api_gateway_deployment.deployment.stage_name} --patch-operations 'op=replace,path=/accessLogSettings/format,value=${jsonencode(replace(file("log_format.json"), "\n", ""))}'"
}
provisioner "local-exec" {
when = "destroy"
command = "aws apigateway update-stage --rest-api-id ${aws_api_gateway_deployment.deployment.rest_api_id} --stage-name ${aws_api_gateway_deployment.deployment.stage_name} --patch-operations op=remove,path=/accessLogSettings,value="
}
} I have not looked at the code but I assume the https://www.terraform.io/docs/providers/aws/r/api_gateway_method_settings.html uses the same patch operation on metrics and logging level |
Hello @roberthutto Thanks for the code. UPD: Information about |
Is there an ETA on when this functionality will be ready? |
Any news ? 😃 |
This has been released in version 1.17.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
How could I set my custom cloud-watch-log-arn in "aws_api_gateway_deployment"? The "aws_api_gateway_method_settings" has no way to set it. The "aws_api_gateway_stage" create new stage, no update to the existing one which is already deployed using "aws_api_gateway_deployment". I would greatly appreciate it if someone kindly give me some advise on this |
@phuonghuynh The CloudWatch ARN setting applies to your whole account rather than a specific API or endpoint. You’ll find it at https://www.terraform.io/docs/providers/aws/r/api_gateway_account.html |
@tdmalone Thanks for getting back so fast. I really appreciate it. Do you mean the attribute I am finding a way to set CloudWatchLogGroupARN to GatewayAPI settings, like api_gateway_stage does. But it create new stage rather than update the existing one which was created by using "aws_api_gateway_deployment". |
Ah, sorry - I misinterpreted what you were asking. Yeah, this is a pain, but the workaround I've come across so far is to leave the stage name blank - see #2918 (comment) |
For anyone coming here wondering how to enable logging at the global level, but override the logging for a specific endpoint, I found that this was the only way that worked for me is the way below. Note that in my example I tried using
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
AWS has announced an enhancement to API Gateway to write access logs in CloudWatch: https://aws.amazon.com/about-aws/whats-new/2017/11/amazon-api-gateway-supports-access-logging/
Prerequisite: #2403
Terraform Version
Affected Resource(s)
Expected Behavior
References
Still waiting on the aws-sdk-go API documentation to update, but appears to be new
AccessLogSettings
struct insideStage
.The text was updated successfully, but these errors were encountered: