-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use OpenAPI schema to define REST API, then add logging and IAM execution permissions. Remove lambda function URLs. Test against REST API base URL. Fixes VEGA-2014 #minor
- Loading branch information
Showing
15 changed files
with
272 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
locals { | ||
stage_name = "current" | ||
template_file = templatefile("../../docs/openapi/openapi.yaml", { | ||
lambda_create_invoke_arn = module.lambda["create"].invoke_arn | ||
}) | ||
} | ||
|
||
resource "aws_api_gateway_rest_api" "lpa_store" { | ||
name = "lpa-store-${var.environment_name}" | ||
description = "API Gateway for LPA Store - ${var.environment_name}" | ||
body = local.template_file | ||
|
||
endpoint_configuration { | ||
types = ["REGIONAL"] | ||
} | ||
|
||
provider = aws.region | ||
} | ||
|
||
|
||
resource "aws_api_gateway_rest_api_policy" "lpa_store" { | ||
rest_api_id = aws_api_gateway_rest_api.lpa_store.id | ||
policy = data.aws_iam_policy_document.lpa_store.json | ||
|
||
provider = aws.region | ||
} | ||
|
||
|
||
resource "aws_api_gateway_deployment" "lpa_store" { | ||
rest_api_id = aws_api_gateway_rest_api.lpa_store.id | ||
|
||
triggers = { | ||
redeployment = sha1(jsonencode([ | ||
aws_api_gateway_rest_api.lpa_store.body, | ||
var.allowed_arns | ||
])) | ||
} | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
|
||
depends_on = [ | ||
aws_api_gateway_rest_api.lpa_store, | ||
aws_api_gateway_rest_api_policy.lpa_store | ||
] | ||
|
||
provider = aws.region | ||
} | ||
|
||
resource "aws_api_gateway_stage" "current" { | ||
depends_on = [aws_cloudwatch_log_group.lpa_store] | ||
deployment_id = aws_api_gateway_deployment.lpa_store.id | ||
rest_api_id = aws_api_gateway_rest_api.lpa_store.id | ||
stage_name = local.stage_name | ||
xray_tracing_enabled = true | ||
|
||
access_log_settings { | ||
destination_arn = aws_cloudwatch_log_group.lpa_store.arn | ||
format = join("", [ | ||
"{\"requestId\":\"$context.requestId\",", | ||
"\"ip\":\"$context.identity.sourceIp\",", | ||
"\"caller\":\"$context.identity.caller\",", | ||
"\"user\":\"$context.identity.user\",", | ||
"\"requestTime\":\"$context.requestTime\",", | ||
"\"httpMethod\":\"$context.httpMethod\"", | ||
"\"resourcePath\":\"$context.resourcePath\",", | ||
"\"status\":\"$context.status\",", | ||
"\"protocol\":\"$context.protocol\",", | ||
"\"responseLength\":\"$context.responseLength\"}" | ||
]) | ||
} | ||
|
||
provider = aws.region | ||
} | ||
|
||
resource "aws_cloudwatch_log_group" "lpa_store" { | ||
name = "API-Gateway-Execution-Logs-${aws_api_gateway_rest_api.lpa_store.name}-${local.stage_name}" | ||
kms_key_id = aws_kms_key.cloudwatch.arn | ||
retention_in_days = 400 | ||
|
||
provider = aws.region | ||
} | ||
|
||
resource "aws_api_gateway_method_settings" "lpa_store_gateway_settings" { | ||
rest_api_id = aws_api_gateway_rest_api.lpa_store.id | ||
stage_name = aws_api_gateway_stage.current.stage_name | ||
method_path = "*/*" | ||
|
||
settings { | ||
metrics_enabled = true | ||
logging_level = "INFO" | ||
} | ||
|
||
provider = aws.region | ||
} | ||
|
||
data "aws_iam_policy_document" "lpa_store" { | ||
policy_id = "lpa-store-${var.environment_name}-${data.aws_region.current.name}-resource-policy" | ||
|
||
statement { | ||
sid = "${local.policy_region_prefix}AllowExecutionFromAllowedARNs" | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = var.allowed_arns | ||
} | ||
|
||
actions = ["execute-api:Invoke"] | ||
resources = ["*"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters