Skip to content

Commit d73d6fd

Browse files
committed
basic lambda
1 parent 41be795 commit d73d6fd

25 files changed

+1489
-30
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ updates:
5858
- "/mesh_processor"
5959
- "/recordprocessor"
6060
- "/redis_sync"
61+
- "/id_sync"
6162
schedule:
6263
interval: "daily"
6364
open-pull-requests-limit: 1

.github/workflows/sonarcloud.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ jobs:
124124
poetry run coverage run -m unittest discover || echo "redis_sync tests failed" >> ../failed_tests.txt
125125
poetry run coverage xml -o ../redis_sync-coverage.xml
126126
127+
- name: Run unittest with id_sync
128+
working-directory: id_sync
129+
id: id_sync
130+
env:
131+
PYTHONPATH: ${{ github.workspace }}/id_sync/src:${{ github.workspace }}/id_sync/tests
132+
continue-on-error: true
133+
run: |
134+
poetry env use 3.11
135+
poetry install
136+
poetry run coverage run -m unittest discover || echo "id_sync tests failed" >> ../failed_tests.txt
137+
poetry run coverage xml -o ../id_sync-coverage.xml
138+
127139
- name: Run Test Failure Summary
128140
id: check_failure
129141
run: |

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ build-proxy:
3838
scripts/build_proxy.sh
3939

4040
#Files to loop over in release
41-
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. e2e e2e_batch specification sandbox terraform scripts backend delta_backend ack_backend filenameprocessor recordprocessor mesh_processor redis_sync"
41+
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. e2e e2e_batch specification sandbox terraform scripts backend delta_backend ack_backend filenameprocessor recordprocessor mesh_processor redis_sync id_sync"
4242

4343

4444
#Create /dist/ sub-directory and copy files into directory

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ See https://nhsd-confluence.digital.nhs.uk/display/APM/Glossary.
2424
| `mesh_processor` | **Imms Batch** – MESH-specific batch processing functionality. |
2525
| `recordprocessor` | **Imms Batch** – Handles batch record processing. |
2626
| `redis_sync` | **Imms Redis** – Handles sync s3 to REDIS. |
27+
| `id_sync` | **Imms Redis** – Handles sync SQS to IEDS. |
2728
---
2829

2930
### Pipelines

id_sync/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~=1.5.0"
8+
9+
# Install Poetry as root
10+
COPY poetry.lock pyproject.toml README.md ./
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 ["id_sync.handler"]

id_sync/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
test:
3+
@PYTHONPATH=src:tests python -m unittest
4+
5+
coverage-run:
6+
coverage run -m unittest discover -v
7+
8+
coverage-report:
9+
coverage report -m
10+
11+
coverage-html:
12+
coverage html
13+
14+
.PHONY: build package

id_sync/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Redis Sync Lambda
2+
3+
## Overview
4+
5+
**Redis Sync** is an AWS Lambda function designed to monitor a configuration S3 bucket and synchronize its contents with an ElastiCache Redis instance. Whenever a new configuration file is uploaded or updated in the S3 bucket, the Lambda function processes the file, applies any required transformations, and uploads the result to the Redis cache.
6+
7+
## Features
8+
9+
- **S3 Event Driven:** Automatically triggered by S3 events (e.g., file uploads or updates) in the config bucket.
10+
- **Transformation Support:** Applies custom transformation logic to configuration files before caching.
11+
- **Redis Integration:** Uploads processed configuration data to ElastiCache Redis for fast, centralized access.
12+
- **Logging:** Provides detailed logging for monitoring and troubleshooting.
13+
14+
## How It Works
15+
16+
1. **S3 Event Trigger:** The Lambda is triggered by S3 events on the config bucket.
17+
2. **File Processing:** The Lambda reads the new or updated file from S3.
18+
3. **Transformation:** If required, the file content is transformed to the appropriate format.
19+
4. **Redis Upload:** The transformed data is uploaded to the Redis cache under a key corresponding to the file.
20+
5. **Monitoring:** Logs are generated for each step, aiding in monitoring and debugging.
21+
22+
## Configuration
23+
24+
- **Environment Variables:**
25+
- `CONFIG_BUCKET_NAME`: Name of the S3 bucket to monitor.
26+
- `AWS_REGION`: AWS region for S3 and Redis.
27+
- `REDIS_HOST`: Redis endpoint.
28+
- `REDIS_PORT`: Redis port (default: 6379).
29+
30+
## Usage
31+
32+
1. **Deploy the Lambda** using your preferred IaC tool (e.g., Terraform, AWS SAM).
33+
2. **Configure S3 event notifications** to trigger the Lambda on object creation or update.
34+
3. **Ensure Redis and S3 permissions** are set for the Lambda execution role.
35+
36+
## Development
37+
38+
- Code is located in the `src/` directory.
39+
- Unit tests are in the `tests/` directory.
40+
- Use the provided Makefile and Dockerfile for building, testing, and packaging.
41+
42+
## License
43+
44+
This project is maintained by NHS. See [LICENSE](../LICENSE) for details.

0 commit comments

Comments
 (0)