Skip to content

Commit 4863474

Browse files
committed
Initial tf and setup boilerplate lambda function
1 parent c1932fd commit 4863474

File tree

11 files changed

+364
-0
lines changed

11 files changed

+364
-0
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ jobs:
4646
poetry run coverage run -m unittest discover || echo "filenameprocessor tests failed" >> ../failed_tests.txt
4747
poetry run coverage xml -o ../filenameprocessor-coverage.xml
4848
49+
- name: Run unittest with batchprocessorfilter-coverage
50+
working-directory: batch_processor_filter
51+
id: batchprocessorfilter
52+
continue-on-error: true
53+
run: |
54+
poetry install
55+
poetry run coverage run -m unittest discover || echo "batchprocessorfilter tests failed" >> ../failed_tests.txt
56+
poetry run coverage xml -o ../batchprocessorfilter-coverage.xml
57+
4958
- name: Run unittest with recordprocessor-coverage
5059
working-directory: recordprocessor
5160
id: recordprocessor

batch_processor_filter/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM public.ecr.aws/lambda/python:3.11 AS base
2+
3+
# Create non-root user
4+
RUN mkdir -p /home/appuser && \
5+
echo 'appuser:x:1001:1001::/home/appuser:/sbin/nologin' >> /etc/passwd && \
6+
echo 'appuser:x:1001:' >> /etc/group && \
7+
chown -R 1001:1001 /home/appuser && pip install "poetry~=2.1.4"
8+
9+
# Install Poetry as root
10+
COPY poetry.lock pyproject.toml ./
11+
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi --no-root --only main
12+
# -----------------------------
13+
FROM base AS test
14+
COPY src src
15+
COPY tests tests
16+
RUN poetry install --no-interaction --no-ansi --no-root && \
17+
pytest --disable-warnings tests
18+
19+
# -----------------------------
20+
FROM base AS build
21+
COPY src .
22+
RUN chmod 644 $(find . -type f) && chmod 755 $(find . -type d)
23+
# Build as non-root user
24+
USER 1001:1001
25+
CMD ["batch_processor_filter.lambda_handler"]

batch_processor_filter/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
build:
2+
docker build -t imms-lambda-build -f Dockerfile .
3+
4+
package: build
5+
mkdir -p build
6+
docker run --rm -v $(shell pwd)/build:/build imms-lambda-build
7+
8+
test:
9+
@PYTHONPATH=src:tests python -m unittest
10+
11+
coverage-run:
12+
@PYTHONPATH=src:tests coverage run -m unittest discover
13+
14+
coverage-report:
15+
coverage report -m
16+
17+
coverage-html:
18+
coverage html
19+
20+
.PHONY: build package test

batch_processor_filter/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
batch-processor-filter-lambda
2+
3+
TODO

batch_processor_filter/poetry.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[tool.poetry]
2+
name = "batch-processor-filter"
3+
version = "1.0.0"
4+
description = "Lambda function to filter incoming batch file creation events"
5+
authors = ["VED Team <[email protected]>"]
6+
readme = "README.md"
7+
packages = [{include = "src"}]
8+
9+
[tool.poetry.dependencies]
10+
python = "~3.11"
11+
12+
[build-system]
13+
requires = ["poetry-core ~= 1.5.0"]
14+
build-backend = "poetry.core.masonry.api"

batch_processor_filter/src/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def lambda_handler(event, _):
2+
print("hello world")
3+
print(event)
4+
return True

batch_processor_filter/test/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from unittest import TestCase
2+
3+
from lambda_handler import lambda_handler
4+
5+
class TestLambdaHandler(TestCase):
6+
def test_lambda_handler(self):
7+
result = lambda_handler({}, {})
8+
self.assertTrue(result)

0 commit comments

Comments
 (0)