-
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.
- Loading branch information
1 parent
fb7d58c
commit 372f13b
Showing
11 changed files
with
157 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,5 +116,6 @@ terraform.rc | |
node_modules/ | ||
|
||
# Build | ||
dist | ||
import-from-s3 | ||
dist/ | ||
api-keys-authorizer/ | ||
import-from-s3/ |
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,84 @@ | ||
resource "aws_dynamodb_table" "api_keys_table" { | ||
name = "${local.product_information.context.project}.api-keys" | ||
billing_mode = "PAY_PER_REQUEST" | ||
hash_key = "name" | ||
|
||
attribute { | ||
name = "name" | ||
type = "S" | ||
} | ||
|
||
tags = local.tags | ||
} | ||
|
||
data "aws_iam_policy_document" "api_keys_table_policy_document" { | ||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"dynamodb:GetItem", | ||
"dynamodb:Query", | ||
"dynamodb:Scan" | ||
] | ||
resources = [aws_dynamodb_table.api_keys_table.arn] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "api_keys_table_policy" { | ||
name = "${local.name_prefix}.keys-table-policy" | ||
description = "IAM policy to allow DynamoDB Table api-keys access" | ||
policy = data.aws_iam_policy_document.api_keys_table_policy_document.json | ||
} | ||
|
||
data "aws_s3_object" "api_keys_authorizer_archive" { | ||
count = fileexists("${path.module}/api-keys-authorizer/index.mjs") ? 0 : 1 | ||
bucket = aws_s3_bucket.api.id | ||
key = "utilities/api-keys-authorizer.zip" | ||
} | ||
|
||
data "archive_file" "api_keys_authorizer_archive" { | ||
count = fileexists("${path.module}/api-keys-authorizer/index.mjs") ? 1 : 0 | ||
type = "zip" | ||
source_dir = "${path.module}/api-keys-authorizer" | ||
output_path = "${path.module}/api-keys-authorizer.zip" | ||
} | ||
|
||
resource "aws_lambda_function" "api_keys_authorizer" { | ||
filename = fileexists("${path.module}/api-keys-authorizer/index.mjs") ? "api-keys-authorizer.zip" : null | ||
s3_bucket = fileexists("${path.module}/api-keys-authorizer/index.mjs") ? null : aws_s3_bucket.api.id | ||
s3_key = fileexists("${path.module}/api-keys-authorizer/index.mjs") ? null : "utilities/api-keys-authorizer.zip" | ||
function_name = "api-keys-authorizer" | ||
role = aws_iam_role.api_keys_authorizer_execution_role.arn | ||
handler = "index.handler" | ||
runtime = "nodejs18.x" | ||
source_code_hash = fileexists("${path.module}/api-keys-authorizer/index.mjs") ? data.archive_file.import_from_s3_archive[0].output_base64sha256 : null | ||
} | ||
|
||
resource "aws_cloudwatch_log_group" "api_keys_authorizer_cloudwatch_log_group" { | ||
name = "/aws/lambda/${aws_lambda_function.api_keys_authorizer.function_name}" | ||
retention_in_days = 14 | ||
} | ||
|
||
data "aws_iam_policy_document" "api_keys_authorizer_execution_policy" { | ||
statement { | ||
effect = "Allow" | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
identifiers = ["lambda.amazonaws.com"] | ||
type = "Service" | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "api_keys_authorizer_execution_role" { | ||
name = "${local.name_prefix}.keys-authorizer-execution-role" | ||
description = "Authentication iam role references a policy document that can assume role for api keys authorizer execution" | ||
tags = local.tags | ||
assume_role_policy = data.aws_iam_policy_document.api_keys_authorizer_execution_policy.json | ||
} | ||
|
||
resource "aws_iam_role_policy" "api_keys_table_role_policy" { | ||
name = "${local.name_prefix}.keys-table-role-policy" | ||
role = aws_iam_role.api_keys_authorizer_execution_role.id | ||
policy = data.aws_iam_policy_document.api_keys_table_policy_document.json | ||
} |
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,17 @@ | ||
data "aws_iam_policy_document" "cloud_watch_role_policy_document" { | ||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
] | ||
resources = ["arn:aws:logs:*:*:*"] | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy" "cloud_watch_role_policy" { | ||
name = "${local.name_prefix}.cloud-watch-role-policy" | ||
role = aws_iam_role.api_keys_authorizer_execution_role.id | ||
policy = data.aws_iam_policy_document.cloud_watch_role_policy_document.json | ||
} |
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,9 @@ | ||
import { APIGatewayProxyResultV2 } from 'aws-lambda'; | ||
|
||
export const handler = async (): Promise<APIGatewayProxyResultV2<boolean>> => { | ||
try { | ||
return false; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; |
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