-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Docker image for the heartbeat hitting the lambda API. | ||
|
||
FROM public.ecr.aws/lambda/python:3.9 | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
|
||
# Install the function's dependencies | ||
COPY heartbeat/requirements_for_heartbeat.txt ${LAMBDA_TASK_ROOT} | ||
RUN python -m pip install -r requirements_for_heartbeat.txt | ||
|
||
# Copy function code | ||
COPY heartbeat/heartbeat.py ${LAMBDA_TASK_ROOT} | ||
|
||
CMD [ "heartbeat.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,33 @@ | ||
""" | ||
Code to keep the lambda API alive. | ||
""" | ||
import ast | ||
import os | ||
import uuid | ||
from typing import List | ||
|
||
from notifications_python_client.errors import HTTPError | ||
from notifications_python_client.notifications import NotificationsAPIClient | ||
|
||
API_KEY: str = os.getenv("heartbeat_api_key", "") | ||
# As we can't pass in a list to env var, we pass a str and convert it. | ||
BASE_URL: List[str] = ast.literal_eval(os.getenv("heartbeat_base_url")) # type: ignore | ||
EMAIL_ADDRESS = "success@simulator.amazonses.com" | ||
TEMPLATE_ID: uuid.UUID = os.getenv("heartbeat_template_id") # type: ignore | ||
|
||
|
||
def handler(event, context): | ||
if not BASE_URL: | ||
print("Variable BASE_URL is missing") | ||
if not API_KEY: | ||
print("Variable API_KEY is missing") | ||
if not TEMPLATE_ID: | ||
print("Variable TEMPLATE_ID is missing") | ||
for base_url in BASE_URL: | ||
notifications_client = NotificationsAPIClient(API_KEY, base_url=base_url) | ||
try: | ||
notifications_client.send_email_notification(email_address=EMAIL_ADDRESS, template_id=TEMPLATE_ID) | ||
print("Email has been sent by {}!".format(base_url)) | ||
except HTTPError as e: | ||
print(f"Could not send heartbeat: status={e.status_code}, msg={e.message}") | ||
raise |
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 @@ | ||
# pyup: ignore file | ||
# This file is autogenerated. Do not edit it manually. | ||
# Run `make freeze-requirements` to update requirements.txt | ||
# with package version changes made in requirements-app.txt | ||
|
||
notifications-python-client==6.0.2 |