Skip to content

Commit 732e9d1

Browse files
CCM-10591: Lambda Boilerplate
1 parent 1ccef7c commit 732e9d1

File tree

5 files changed

+74
-7
lines changed

5 files changed

+74
-7
lines changed

infrastructure/terraform/components/examplecomponent/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ No requirements.
1313
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"examplecomponent"` | no |
1414
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
1515
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
16+
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
1617
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
1718
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
1819
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# module "example_lambda" {
2+
# source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda?ref=v2.0.10"
3+
4+
# function_name = "example-lambda"
5+
# description = "An example lambda function"
6+
7+
# aws_account_id = var.aws_account_id
8+
# component = var.component
9+
# environment = var.environment
10+
# project = var.project
11+
# region = var.region
12+
# group = var.group
13+
14+
# log_retention_in_days = var.log_retention_in_days
15+
# kms_key_arn = module.kms.key_arn ## Requires shared kms module
16+
17+
# iam_policy_document = {
18+
# body = data.aws_iam_policy_document.example_lambda.json
19+
# }
20+
21+
# function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
22+
# function_code_base_path = local.aws_lambda_functions_dir_path
23+
# function_code_dir = "example-lambda/dist"
24+
# function_include_common = true
25+
# handler_function_name = "handler"
26+
# runtime = "nodejs22.x"
27+
# memory = 128
28+
# timeout = 5
29+
# log_level = var.log_level
30+
31+
# force_lambda_code_deploy = var.force_lambda_code_deploy
32+
# enable_lambda_insights = false
33+
34+
# lambda_env_vars = {
35+
# }
36+
# }
37+
38+
# data "aws_iam_policy_document" "example_lambda" {
39+
# statement {
40+
# sid = "KMSPermissions"
41+
# effect = "Allow"
42+
43+
# actions = [
44+
# "kms:Decrypt",
45+
# "kms:GenerateDataKey",
46+
# ]
47+
48+
# resources = [
49+
# module.kms.key_arn, ## Requires shared kms module
50+
# ]
51+
# }
52+
# }
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# This script is run before the Terraform apply command.
2-
# It ensures all Node.js dependencies are installed, generates any required dependencies,
3-
# and builds all Lambda functions in the workspace before Terraform provisions infrastructure.
1+
# # This script is run before the Terraform apply command.
2+
# # It ensures all Node.js dependencies are installed, generates any required dependencies,
3+
# # and builds all Lambda functions in the workspace before Terraform provisions infrastructure.
44

5-
npm ci
5+
# npm ci
66

7-
npm run generate-dependencies --workspaces --if-present
7+
# npm run generate-dependencies --workspaces --if-present
88

9-
npm run lambda-build --workspaces --if-present
9+
# npm run lambda-build --workspaces --if-present

infrastructure/terraform/components/examplecomponent/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ variable "log_retention_in_days" {
5656
description = "The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite"
5757
default = 0
5858
}
59+
60+
variable "force_lambda_code_deploy" {
61+
type = bool
62+
description = "If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development"
63+
default = false
64+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
// Replace me with the actual code for your Lambda function
1+
import { Handler } from 'aws-lambda';
2+
3+
export const handler: Handler = async (event) => {
4+
console.log('Received event:', event);
5+
return {
6+
statusCode: 200,
7+
body: 'Event logged',
8+
};
9+
};

0 commit comments

Comments
 (0)