Skip to content

Commit

Permalink
TDR-3364 - Create API Gateway resource (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhz authored Sep 13, 2023
1 parent 7007b39 commit eccaa1a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
7 changes: 4 additions & 3 deletions terraform/root_locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ locals {
"Role" = "prvt"
}
)
dynamodb_hash_key = "v1"
reference_generator_function_name = "${var.project}-reference-generator-${local.hosting_environment}"
reference_counter_table_name = "${var.project}-reference-counter"
dynamodb_hash_key = "v1"
reference_generator_function_name = "${var.project}-reference-generator-${local.hosting_environment}"
reference_generator_api_gateway_name = "${upper(var.project)}ReferenceGenerator${local.hosting_environment}"
reference_counter_table_name = "${var.project}-reference-counter"
}
15 changes: 15 additions & 0 deletions terraform/root_main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,19 @@ module "reference_generator_lambda" {
timeout_seconds = 60
memory_size = 1024
tags = local.hosting_common_tags
lambda_invoke_permissions = {
"apigateway.amazonaws.com" = "${module.reference_generator_api_gateway.api_execution_arn}/*/GET/counter"
}
}

module "reference_generator_api_gateway" {
source = "./da-terraform-modules/apigateway"
api_definition = templatefile("./templates/api_gateway/reference_generator.json.tpl", {
environment = local.hosting_environment
title = local.reference_generator_api_gateway_name
lambda_arn = module.reference_generator_lambda.lambda_arn,
})
api_name = local.reference_generator_api_gateway_name
environment = local.hosting_environment
common_tags = local.hosting_common_tags
}
56 changes: 56 additions & 0 deletions terraform/templates/api_gateway/reference_generator.json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"swagger" : "2.0",
"info" : {
"description" : "API Gateway for Reference Generator",
"version" : "2023-09-11T11:10:51Z",
"title" : "${title}"
},
"basePath" : "/${environment}",
"schemes" : [ "https" ],
"paths" : {
"/counter" : {
"get" : {
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "numberofrefs",
"in" : "query",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "200 response",
"schema" : {
"$ref" : "#/definitions/Empty"
}
}
},
"x-amazon-apigateway-request-validator" : "Validate query string parameters and headers",
"x-amazon-apigateway-integration" : {
"type" : "aws_proxy",
"httpMethod" : "POST",
"uri" : "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/${lambda_arn}/invocations",
"responses" : {
"default" : {
"statusCode" : "200"
}
},
"passthroughBehavior" : "when_no_match",
"contentHandling" : "CONVERT_TO_TEXT"
}
}
}
},
"definitions" : {
"Empty" : {
"type" : "object",
"title" : "Empty Schema"
}
},
"x-amazon-apigateway-request-validators" : {
"Validate query string parameters and headers" : {
"validateRequestParameters" : true,
"validateRequestBody" : false
}
}
}

0 comments on commit eccaa1a

Please sign in to comment.