Skip to content

Commit bc4c89f

Browse files
authored
Merge pull request #32 from ONS-Innovation/lambda-rework
KEH-511 | Data Logger Lambda Rework
2 parents 906a5e5 + dd8aeda commit bc4c89f

24 files changed

Lines changed: 3078 additions & 1970 deletions

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ override.tf.json
4949
terraform.rc
5050

5151
# Ignore the terraform/service prority calc
52-
terraform/service/highest_priority.txt
52+
terraform/service/highest_priority.txt
53+
54+
.terraform.lock.hcl
55+
56+
# Lambda Logs and Output
57+
debug.log
58+
output/

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1-
# GitHub Audit Dashboard
1+
# GitHub Policy Dashboard
22
A dashboard which uses organisation data from the GitHub API to monitor how well policy is adhered to in ONS.
33

4+
## Overview
5+
6+
This repository contains 2 main elements:
7+
8+
- A Streamlit Dashboard to visualise policy data from S3.
9+
- An AWS Lambda Data Logger to collect information from GitHub to be used by the dashboard.
10+
11+
## Table of Contents
12+
13+
- [GitHub Policy Dashboard](#github-policy-dashboard)
14+
- [Overview](#overview)
15+
- [Table of Contents](#table-of-contents)
16+
- [Prerequisites](#prerequisites)
17+
- [Documentation](#documentation)
18+
- [Setup - Run outside of Docker](#setup---run-outside-of-docker)
19+
- [Setup - Running in a container](#setup---running-in-a-container)
20+
- [Storing the container on AWS Elastic Container Registry (ECR)](#storing-the-container-on-aws-elastic-container-registry-ecr)
21+
- [Deployment to AWS](#deployment-to-aws)
22+
- [Deployment Prerequisites](#deployment-prerequisites)
23+
- [Underlying AWS Infrastructure](#underlying-aws-infrastructure)
24+
- [Bootstrap IAM User Groups, Users and an ECSTaskExecutionRole](#bootstrap-iam-user-groups-users-and-an-ecstaskexecutionrole)
25+
- [Bootstrap for Terraform](#bootstrap-for-terraform)
26+
- [Running the Terraform](#running-the-terraform)
27+
- [Provision Users](#provision-users)
28+
- [Updating the running service using Terraform](#updating-the-running-service-using-terraform)
29+
- [Destroy the Main Service Resources](#destroy-the-main-service-resources)
30+
- [Linting and Formatting](#linting-and-formatting)
31+
- [Future Development](#future-development)
32+
33+
434
## Prerequisites
535
This project uses poetry for package management and colima/docker for containerisation.
636

@@ -344,4 +374,13 @@ make pylint
344374
To run mypy (static type checking)
345375
```bash
346376
make mypy
347-
```
377+
```
378+
379+
## Future Development
380+
381+
This repository still needs the following implemented:
382+
383+
- Linting
384+
- Testing to a 95% coverage
385+
- MkDocs documentation refactor / rewrite
386+
- General repository clean up

data_logger/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Note:
2+
# Within docker, this container runs as root as no user is specified.
3+
# Due to the nature of the lambda function, this is acceptable as Lambda defines the default user
4+
# to have the least-privilege permissions rather than the root user.
5+
6+
# Therefore we can ignore the linting error for this Dockerfile
7+
# as it is not a security risk for this specific use case.
8+
9+
# Ignored in .trivyignore also.
10+
#kics-scan disable=fd54f200-402c-4333-a5a4-36ef6709af2f
11+
#checkov:skip=CKV_DOCKER_3:Lambda makes default user lowest privilege
12+
13+
FROM public.ecr.aws/lambda/python:3.12
14+
15+
# Install git using dnf (https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-base)
16+
# For python 3.12, dnf replaces yum for package management
17+
RUN dnf install -y git-2.40.1 && dnf clean all
18+
19+
# Copy the poetry.lock and pyproject.toml files
20+
COPY ./pyproject.toml ./poetry.lock ${LAMBDA_TASK_ROOT}/
21+
22+
# Install the dependencies
23+
WORKDIR ${LAMBDA_TASK_ROOT}
24+
RUN pip install --no-cache-dir poetry==1.8.3 &&\
25+
poetry config virtualenvs.create false &&\
26+
poetry install
27+
28+
# Copy config folder
29+
COPY config ${LAMBDA_TASK_ROOT}/config
30+
31+
# Copy function code
32+
COPY src/main.py src/logger.py src/policy_checks.py src/custom_threading.py ${LAMBDA_TASK_ROOT}/src/
33+
34+
HEALTHCHECK NONE
35+
36+
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
37+
CMD [ "src.main.handler" ]

0 commit comments

Comments
 (0)