resource "aws_api_gateway_rest_api" "click_logger_api" { name = "${var.app_prefix}-api" description = "click logger api" } #create a resource with name 'resource' in the gateway api , many resources can be created like this resource "aws_api_gateway_resource" "resource" { path_part = "clicklogger" parent_id = "${aws_api_gateway_rest_api.click_logger_api.root_resource_id}" rest_api_id = "${aws_api_gateway_rest_api.click_logger_api.id}" depends_on = ["aws_api_gateway_rest_api.click_logger_api"] } resource "aws_api_gateway_account" "click_logger_api_gateway_account" { cloudwatch_role_arn = "${aws_iam_role.click_logger_api_gateway_cloudwatch_role.arn}" } resource "aws_cloudwatch_log_group" "clicklogger-api-log-group" { name = "/aws/apigateway/${var.app_prefix}-API-Gateway-Execution-Logs/${var.stage_name}" retention_in_days = 7 } resource "aws_api_gateway_method_settings" "general_settings" { rest_api_id = "${aws_api_gateway_rest_api.click_logger_api.id}" stage_name = "${aws_api_gateway_deployment.clicklogger_deployment.stage_name}" method_path = "*/*" settings { # Enable CloudWatch logging and metrics metrics_enabled = true data_trace_enabled = true logging_level = "INFO" # Limit the rate of calls to prevent abuse and unwanted charges throttling_rate_limit = 100 throttling_burst_limit = 50 } } resource "aws_api_gateway_authorizer" "clicklogger-authorizer" { name = "clicklogger-authorizer" rest_api_id = "${aws_api_gateway_rest_api.click_logger_api.id}" authorizer_uri = "${aws_lambda_function.lambda_clicklogger_authorizer.invoke_arn}" authorizer_credentials = "${aws_iam_role.click_logger_invocation_role.arn}" identity_source = "method.request.header.Authorization" type = "TOKEN" } resource "aws_api_gateway_request_validator" "clicklogger_validator" { name = "${var.app_prefix}-validator" rest_api_id = "${aws_api_gateway_rest_api.click_logger_api.id}" validate_request_body = true validate_request_parameters = true } resource "aws_api_gateway_model" "clicklogger_model" { rest_api_id = "${aws_api_gateway_rest_api.click_logger_api.id}" name = "${var.app_prefix}model" description = "${var.app_prefix}-JSON schema" content_type = "application/json" schema = <