Skip to content

Commit

Permalink
add an optional env var config for mosaic lambda that will override t… (
Browse files Browse the repository at this point in the history
#22)

* add an optional env var config for mosaic lambda that will override the host header in the event, so that responses crafted use the desired external-facing domain instead of internal API gateway
Co-authored-by: Phil Varner <pvarner@element84.com>
* Update deployment/aws/lambda/handler.py
  • Loading branch information
bick4ord authored Sep 12, 2023
1 parent 15563c9 commit 758720c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions deployment/aws/lambda/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""AWS Lambda handler."""

import logging
import os

from mangum import Mangum

Expand All @@ -9,5 +10,13 @@
logging.getLogger("mangum.lifespan").setLevel(logging.ERROR)
logging.getLogger("mangum.http").setLevel(logging.ERROR)

# mangum > 0.11.x removes the "log_level" parameter from the Mangum constructor
handler = Mangum(app, lifespan="auto")
REQUEST_HOST_HEADER_OVERRIDE_ENV_VAR = "REQUEST_HOST_HEADER_OVERRIDE"


def handler(event, context):
"""If env var is set, override the host header in the event passed to the lambda"""
if rhh := os.getenv(REQUEST_HOST_HEADER_OVERRIDE_ENV_VAR):
event["headers"]["host"] = rhh

asgi_handler = Mangum(app, lifespan="auto")
return asgi_handler(event, context)

0 comments on commit 758720c

Please sign in to comment.