Skip to content

Commit 8dddd7c

Browse files
committed
add lambda
1 parent 373d5db commit 8dddd7c

File tree

12 files changed

+717
-16
lines changed

12 files changed

+717
-16
lines changed

VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

infrastructure/terraform/components/app/cloudfront_distribution_cdn.tf

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ resource "aws_cloudfront_distribution" "main" {
2929
domain_name = module.backend_api.download_bucket_regional_domain_name
3030
origin_access_control_id = aws_cloudfront_origin_access_control.main.id
3131
origin_id = "S3-${local.csi}-download"
32+
33+
custom_header {
34+
name = "x-user-pool-id"
35+
value = jsondecode(aws_ssm_parameter.cognito_config.value)["USER_POOL_ID"]
36+
}
37+
38+
custom_header {
39+
name = "x-user-pool-client-id"
40+
value = jsondecode(aws_ssm_parameter.cognito_config.value)["USER_POOL_CLIENT_ID"]
41+
}
3242
}
3343

3444
default_cache_behavior {
@@ -43,20 +53,31 @@ resource "aws_cloudfront_distribution" "main" {
4353
]
4454
target_origin_id = "S3-${local.csi}-download"
4555

46-
forwarded_values {
47-
query_string = true
48-
headers = ["Origin"]
49-
50-
cookies {
51-
forward = "all"
52-
}
53-
}
56+
cache_policy_id = aws_cloudfront_cache_policy.no_cache.id
57+
origin_request_policy_id = aws_cloudfront_origin_request_policy.forward_cookies.id
5458

5559
viewer_protocol_policy = "redirect-to-https"
56-
min_ttl = 0
57-
default_ttl = 3600
58-
max_ttl = 86400
5960
compress = true
6061
}
6162
}
6263

64+
resource "aws_cloudfront_cache_policy" "no_cache" {
65+
name = "no-cache-policy"
66+
67+
default_ttl = 0
68+
max_ttl = 0
69+
min_ttl = 0
70+
71+
parameters_in_cache_key_and_forwarded_to_origin {
72+
cookies_config { cookie_behavior = "none" }
73+
headers_config { header_behavior = "none" }
74+
query_strings_config { query_string_behavior = "none" }
75+
}
76+
}
77+
78+
resource "aws_cloudfront_origin_request_policy" "forward_cookies" {
79+
name = "forward-cookies"
80+
cookies_config { cookie_behavior = "all" }
81+
headers_config { header_behavior = "none" }
82+
query_strings_config { query_string_behavior = "none" }
83+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
locals {
22
cloudfront_domain_name = "files.${local.root_domain_name}"
33
root_domain_name = "${var.environment}.${local.acct.dns_zone["name"]}"
4+
5+
repo_root = abspath("${path.module}/../../../..")
6+
lambdas_source_code_dir = abspath("${local.repo_root}/lambdas")
47
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module "download_authorizer_lambda" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda?ref=v2.0.2"
3+
4+
providers = {
5+
aws = aws.us-east-1
6+
}
7+
8+
function_name = "download-authorizer"
9+
description = "Download authorizer for s3 origin"
10+
11+
aws_account_id = var.aws_account_id
12+
component = var.component
13+
environment = var.environment
14+
project = var.project
15+
region = "us-east-1"
16+
group = var.group
17+
18+
log_retention_in_days = var.log_retention_in_days
19+
kms_key_arn = module.kms.key_arn
20+
21+
iam_policy_document = {
22+
body = data.aws_iam_policy_document.authorizer.json
23+
}
24+
25+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
26+
function_code_base_path = local.aws_lambda_functions_dir_path
27+
function_code_dir = "${lambdas_source_code_dir}/download-authorizer/dist"
28+
function_include_common = true
29+
function_module_name = "handler"
30+
runtime = "nodejs20.x"
31+
memory = 128
32+
timeout = 5
33+
log_level = var.log_level
34+
lambda_at_edge = true
35+
36+
force_lambda_code_deploy = var.force_lambda_code_deploy
37+
enable_lambda_insights = false
38+
}
39+
40+
data "aws_iam_policy_document" "authorizer" {
41+
statement {
42+
sid = "KMSPermissions"
43+
effect = "Allow"
44+
45+
actions = [
46+
"kms:Decrypt",
47+
"kms:GenerateDataKey",
48+
]
49+
50+
resources = [
51+
module.kms.key_arn,
52+
]
53+
}
54+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.build
2+
coverage
3+
node_modules
4+
dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { baseJestConfig as default } from 'nhs-notify-web-template-management-utils'; // eslint-disable-line no-restricted-exports
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "nhs-notify-download-authorizer",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"test:unit": "jest",
7+
"lint": "eslint .",
8+
"lint:fix": "eslint . --fix",
9+
"typecheck": "tsc --noEmit"
10+
},
11+
"devDependencies": {
12+
"@swc/core": "^1.11.13",
13+
"@swc/jest": "^0.2.37",
14+
"@tsconfig/node20": "^20.1.5",
15+
"@types/aws-lambda": "^8.10.148",
16+
"@types/jest": "^29.5.14",
17+
"@types/jsonwebtoken": "^9.0.9",
18+
"esbuild": "^0.24.0",
19+
"jest": "^29.7.0",
20+
"jest-mock-extended": "^3.0.7",
21+
"typescript": "^5.8.2"
22+
},
23+
"dependencies": {
24+
"@aws-sdk/client-cognito-identity-provider": "3.775.0",
25+
"jsonwebtoken": "^9.0.2",
26+
"jwks-rsa": "^3.2.0",
27+
"jwt-decode": "^4.0.0",
28+
"nhs-notify-web-template-management-utils": "^0.0.1",
29+
"zod": "^3.24.2"
30+
}
31+
}
32+
s

0 commit comments

Comments
 (0)