Skip to content

Commit 0da3abd

Browse files
committed
CCM-12616: Replaced mesh-poll Lambda with a skeleton Python version
1 parent 2562437 commit 0da3abd

19 files changed

Lines changed: 1442 additions & 110 deletions

infrastructure/terraform/components/dl/module_lambda_mesh_poll.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ module "mesh_poll" {
2020

2121
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
2222
function_code_base_path = local.aws_lambda_functions_dir_path
23-
function_code_dir = "mesh-poll/dist"
23+
function_code_dir = "mesh-poll/target/dist"
2424
function_include_common = true
25-
handler_function_name = "handler"
26-
runtime = "nodejs22.x"
25+
handler_function_name = "mesh_poll.handler.handler"
26+
runtime = "python3.9"
2727
memory = 128
2828
timeout = 5
2929
log_level = var.log_level

lambdas/mesh-poll/.eslintignore

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

lambdas/mesh-poll/.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
coverage
2-
node_modules
3-
dist
4-
.reports
1+
__pycache__
2+
.venv

lambdas/mesh-poll/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
PACKAGE=mesh_poll
2+
VERSION=0.1.0
3+
4+
audit:
5+
poetry run python -m jake.app ddt -t POETRY -f poetry.lock
6+
7+
install:
8+
poetry install
9+
10+
test:
11+
poetry run pytest
12+
13+
test-coverage:
14+
poetry run pytest --cov --cov-report xml:target/coverage/@comms/mesh-poll-lambda/cobertura-coverage.xml
15+
16+
lint:
17+
poetry run pylint mesh_poll
18+
19+
format:
20+
poetry run autopep8 -ri .
21+
22+
package:
23+
./package_python_lambda.sh meshpolllambda
24+
25+
clean:
26+
rm -rf target
27+
28+
.PHONY: install test test-coverage lint format package clean

lambdas/mesh-poll/jest.config.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Mesh Poll"""
2+
3+
__version__ = '0.1.0'
4+
from .config import *
5+
from .handler import *
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Module for configuring Mesh Poll application
3+
"""
4+
import structlog
5+
6+
structlog.configure(processors=[structlog.processors.JSONRenderer()])
7+
log = structlog.get_logger()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""lambda handler for mesh poll application"""
2+
3+
from .config import log
4+
5+
6+
def handler(_, __):
7+
"""lambda handler for mesh poll application"""
8+
log.info('Polling for new messages from MESH...')

lambdas/mesh-poll/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
"name": "nhs-notify-digital-letters-mesh-poll",
1515
"private": true,
1616
"scripts": {
17-
"lambda-build": "rm -rf dist && npx esbuild --bundle --minify --sourcemap --target=es2020 --platform=node --loader:.node=file --entry-names=[name] --outdir=dist src/index.ts",
18-
"lint": "eslint .",
19-
"lint:fix": "eslint . --fix",
20-
"test:unit": "jest",
21-
"typecheck": "tsc --noEmit"
17+
"audit": "make audit",
18+
"lambda-build": "make package",
19+
"lint": "make lint",
20+
"lint:fmt": "make format",
21+
"python-install": "make install",
22+
"test:unit": "make test",
23+
"test:unit:coverage": "make test-coverage",
24+
"typecheck": "echo this package contains no typescript"
2225
},
2326
"version": "0.0.1"
2427
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
component_name="$1"
5+
6+
rootdir=$(realpath "$(dirname "$0")/../..")
7+
source ${rootdir}/utils/get_version.sh
8+
9+
VERSIONED_ZIP_NAME="NHSD.comms."${component_name}-"${point_version}"".zip"
10+
11+
dist_dir="${PWD}/target/dist"
12+
build_dir="${PWD}/target/python-build"
13+
mkdir -p "${dist_dir}"
14+
rm -rf "${build_dir}"
15+
mkdir -p "${build_dir}"
16+
rm -rf "${dist_dir}/${VERSIONED_ZIP_NAME}"
17+
18+
# poetry config virtualenvs.in-project true
19+
20+
# this asserts we are using the right pip+python
21+
poetry install --only-root
22+
source .venv/bin/activate
23+
24+
# now bundle dependencies from lock file
25+
poetry export -f requirements.txt --output target/all_requirements.txt --without dev
26+
grep -v file:// target/all_requirements.txt > target/external_requirements.txt
27+
grep file:// target/all_requirements.txt > target/internal_requirements.txt
28+
pip install --platform manylinux2014_x86_64 --only-binary=:all: -r target/external_requirements.txt --target ${build_dir} --no-deps
29+
pip install -r target/internal_requirements.txt --target ${build_dir} --no-deps
30+
31+
# now bundle application code
32+
pip install . --no-deps --target ${build_dir}
33+
34+
# and construct the build artefact
35+
cd ${build_dir} && zip -r "${dist_dir}/${VERSIONED_ZIP_NAME}" .

0 commit comments

Comments
 (0)