-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding new lambda function, new tests and updated builds
- Loading branch information
1 parent
ac5d00b
commit 634a050
Showing
11 changed files
with
665 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,21 @@ jobs: | |
working-directory: ./entity-counter-recalculator | ||
run: python -m unittest test_main.py | ||
|
||
test-customer-storage-recalculator: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: 3.11 | ||
cache: 'pip' # caching pip dependencies | ||
- name: Install dependencies | ||
run: python -m pip install -r requirements.txt | ||
- name: Run python tests | ||
working-directory: ./customer-storage-recalculator | ||
run: python -m unittest test_main.py | ||
|
||
build-push-dlcs-entity-counter-recalculator: | ||
runs-on: ubuntu-latest | ||
needs: test-entity-counter-recalculator | ||
|
@@ -36,4 +51,16 @@ jobs: | |
image-name: "entity-counter-recalculator" | ||
dockerfile: "entity-counter-recalculator/Dockerfile" | ||
context: "./entity-counter-recalculator" | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
build-push-dlcs-customer-storage-recalculator: | ||
runs-on: ubuntu-latest | ||
needs: test-entity-counter-recalculator | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/docker-build-and-push | ||
with: | ||
image-name: "customer-storage-recalculator" | ||
dockerfile: "customer-storage-recalculator/Dockerfile" | ||
context: "./customer-storage-recalculator" | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Stage 1 - grab the image | ||
|
||
FROM python:3.11 | ||
LABEL authors="JackLewis" | ||
|
||
RUN apt-get update | ||
|
||
# Stage 2 - build function and dependencies | ||
FROM python AS build-image | ||
|
||
# Create function directory | ||
RUN mkdir -p /home/app/ | ||
# Copy handler function | ||
COPY main.py /home/app/ | ||
COPY /app /home/app/app | ||
|
||
# Install Lambda Runtime Interface Client for Python | ||
RUN pip install awslambdaric --target /home/app/ | ||
|
||
# Copy and install other requirements | ||
COPY minimalRequirements.txt ./ | ||
RUN pip install --no-cache-dir --upgrade pip \ | ||
&& pip install --no-cache-dir -r minimalRequirements.txt --target /home/app/ | ||
|
||
# Stage 3 - final runtime image | ||
# Grab a fresh copy of the Python image | ||
FROM python | ||
# Set working directory to function root directory | ||
WORKDIR /home/app | ||
# Copy in the built dependencies | ||
COPY --from=build-image /home/app /home/app | ||
# (Optional) Add Lambda Runtime Interface Emulator and use a script in the ENTRYPOINT for simpler local runs | ||
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie | ||
COPY entry.sh / | ||
RUN chmod 755 /usr/bin/aws-lambda-rie /entry.sh | ||
ENTRYPOINT [ "/entry.sh" ] | ||
CMD [ "main.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import boto3 | ||
|
||
from app.settings import LOCALSTACK, REGION, LOCALSTACK_ADDRESS | ||
from logzero import logger | ||
|
||
|
||
def get_aws_client(resource_type: str): | ||
"""Get an aws resource configured to use LocalStack if env var is set""" | ||
if LOCALSTACK: | ||
logger.warn(f"Using localstack for {resource_type} resource") | ||
return boto3.client( | ||
resource_type, | ||
region_name=REGION, | ||
endpoint_url=LOCALSTACK_ADDRESS, | ||
aws_access_key_id="foo", | ||
aws_secret_access_key="bar", # pragma: allowlist secret | ||
) | ||
else: | ||
return boto3.client(resource_type, REGION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
|
||
|
||
def _get_boolean(env_name: str, fallback: str) -> bool: | ||
return os.environ.get(env_name, fallback).lower() in ("true", "t", "1") | ||
|
||
|
||
# AWS | ||
REGION = os.environ.get("AWS_REGION", "eu-west-1") | ||
ENABLE_CLOUDWATCH_INTEGRATION = _get_boolean("ENABLE_CLOUDWATCH_INTEGRATION", "True") | ||
CLOUDWATCH_CUSTOMER_IMAGE_SIZE_DIFFERENCE_METRIC_NAME = os.environ.get("CLOUDWATCH_CUSTOMER_IMAGE_SIZE_DIFFERENCE_METRIC_NAME") | ||
CLOUDWATCH_CUSTOMER_IMAGE_NUMBER_DIFFERENCE_METRIC_NAME = os.environ.get("CLOUDWATCH_CUSTOMER_IMAGE_NUMBER_DIFFERENCE_METRIC_NAME") | ||
CLOUDWATCH_CUSTOMER_THUMBNAIL_SIZE_DIFFERENCE_METRIC_NAME = os.environ.get("CLOUDWATCH_CUSTOMER_THUMBNAIL_SIZE_DIFFERENCE_METRIC_NAME") | ||
CLOUDWATCH_SPACE_IMAGE_SIZE_DIFFERENCE_METRIC_NAME = os.environ.get("CLOUDWATCH_SPACE_IMAGE_SIZE_DIFFERENCE_METRIC_NAME") | ||
CLOUDWATCH_SPACE_IMAGE_NUMBER_DIFFERENCE_METRIC_NAME = os.environ.get("CLOUDWATCH_SPACE_IMAGE_NUMBER_DIFFERENCE_METRIC_NAME") | ||
CLOUDWATCH_SPACE_THUMBNAIL_SIZE_DIFFERENCE_METRIC_NAME = os.environ.get("CLOUDWATCH_SPACE_THUMBNAIL_SIZE_DIFFERENCE_METRIC_NAME") | ||
APP_VERSION = os.environ.get('APP_VERSION', "1.0") | ||
AWS_CONNECTION_STRING_LOCATION = os.environ.get("AWS_CONNECTION_STRING_LOCATION") | ||
|
||
# LocalStack | ||
LOCALSTACK = _get_boolean("LOCALSTACK", "False") | ||
LOCALSTACK_ADDRESS = os.environ.get("LOCALSTACK_ADDRESS", "http://localhost:4566") | ||
|
||
# Postgres | ||
CONNECTION_STRING = os.environ.get("CONNECTION_STRING") | ||
CONNECTION_TIMEOUT = os.environ.get("CONNECTION_TIMEOUT") | ||
DRY_RUN = os.environ.get("DRY_RUN", False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then | ||
exec /usr/bin/aws-lambda-rie /usr/local/bin/python -m awslambdaric $1 | ||
else | ||
exec /usr/local/bin/python -m awslambdaric $1 | ||
fi |
Oops, something went wrong.