diff --git a/Pipfile b/Pipfile index 1bd335c..82df944 100644 --- a/Pipfile +++ b/Pipfile @@ -26,6 +26,7 @@ djangorestframework = "*" certifi = ">2022.9.24" django-cors-headers = "*" typing-extensions = ">=3.7.4" +dc-logging-utils = {file = "https://github.com/DemocracyClub/dc_logging/archive/refs/heads/lambda-ingest.zip"} [dev-packages] pre-commit = "*" @@ -50,7 +51,6 @@ python_version = "3.10" allow_prereleases = true [scripts] - collectstatic = "python manage.py collectstatic -c --noinput" pytest = "pytest" coveralls = "coveralls" diff --git a/Pipfile.lock b/Pipfile.lock index e82439d..94a9e8f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e60827fbd05293d39cd361c1155ca5f036bc1391e75c43367cf37fc59140e7fa" + "sha256": "4b3ceb7c5fcc92904f2795a123925c36de4fd5c2e6e8690ce44966813d10c249" }, "pipfile-spec": 6, "requires": { @@ -30,19 +30,27 @@ }, "boto3": { "hashes": [ - "sha256:98b01bbea27740720a06f7c7bc0132ae4ce902e640aab090cfb99ad3278449c3", - "sha256:adfb915958d7b54d876891ea1599dd83189e35a2442eb41ca52b04ea716180b6" + "sha256:1fb7e7ba32a6701990168eb7a08e1fb624ae48130784dfab25904ed47deabb31", + "sha256:96b4cb2708933cef7dbe1177df37ef0593839942978784147aade0e49511eb2b" ], "markers": "python_version >= '3.7'", - "version": "==1.28.84" + "version": "==1.28.85" }, "botocore": { "hashes": [ - "sha256:8913bedb96ad0427660dee083aeaa675466eb662bbf1a47781956b5882aadcc5", - "sha256:d65bc05793d1a8a8c191a739f742876b4b403c5c713dc76beef262d18f7984a2" + "sha256:b8f35d65f2b45af50c36fc25cc1844d6bd61d38d2148b2ef133b8f10e198555d", + "sha256:ce58e688222df73ec5691f934be1a2122a52c9d11d3037b586b3fff16ed6d25f" ], "markers": "python_version >= '3.7'", - "version": "==1.31.84" + "version": "==1.31.85" + }, + "cachetools": { + "hashes": [ + "sha256:086ee420196f7b2ab9ca2db2520aca326318b68fe5ba8bc4d49cca91add450f2", + "sha256:861f35a13a451f94e301ce2bec7cac63e881232ccce7ed67fab9b5df4d3beaa1" + ], + "markers": "python_version >= '3.7'", + "version": "==5.3.2" }, "certifi": { "hashes": [ @@ -211,6 +219,9 @@ "git": "https://github.com/DemocracyClub/design-system.git", "ref": "09bcc3eb4eccc189b3a19d91dae5b777be52f253" }, + "dc-logging-utils": { + "file": "https://github.com/DemocracyClub/dc_logging/archive/refs/heads/lambda-ingest.zip" + }, "django": { "hashes": [ "sha256:8e0f1c2c2786b5c0e39fe1afce24c926040fad47c8ea8ad30aaf1188df29fc41", @@ -232,12 +243,12 @@ }, "django-cors-headers": { "hashes": [ - "sha256:25aabc94d4837678c1edf442c7f68a5f5fd151f6767b0e0b01c61a2179d02711", - "sha256:bd36c7aea0d070e462f3383f0dc9ef717e5fdc2b10a99c98c285f16da84ffba2" + "sha256:0b1fd19297e37417fc9f835d39e45c8c642938ddba1acce0c1753d3edef04f36", + "sha256:0bf65ef45e606aff1994d35503e6b677c0b26cafff6506f8fd7187f3be840207" ], "index": "pypi", "markers": "python_version >= '3.8'", - "version": "==4.3.0" + "version": "==4.3.1" }, "django-debug-toolbar": { "hashes": [ @@ -525,7 +536,7 @@ "sha256:c97dfde1f7bd43a71c8d2a58e369e9b2bf692d1334ea9f9cae55add7d0dd0f84", "sha256:fdb6d215c776278489906c2f8916e6e7d4f5a9b602ccbcfdf7f016fc8da0596e" ], - "markers": "python_version >= '3.6'", + "markers": "python_version >= '3.7'", "version": "==2.0.7" }, "whitenoise": { @@ -733,7 +744,7 @@ "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330", "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186" ], - "markers": "python_version < '3.11' and python_version >= '3.7'", + "markers": "python_version >= '3.5'", "version": "==5.1.1" }, "distlib": { @@ -908,11 +919,11 @@ }, "prompt-toolkit": { "hashes": [ - "sha256:99ba3dfb23d5b5af89712f89e60a5f3d9b8b67a9482ca377c5771d0e9047a34b", - "sha256:a371c06bb1d66cd499fecd708e50c0b6ae00acba9822ba33c586e2f16d1b739e" + "sha256:941367d97fc815548822aa26c2a269fdc4eb21e9ec05fc5d447cf09bad5d75f0", + "sha256:f36fe301fafb7470e86aaf90f036eef600a3210be4decf461a5b1ca8403d3cb2" ], "markers": "python_full_version >= '3.7.0'", - "version": "==3.0.40" + "version": "==3.0.41" }, "ptyprocess": { "hashes": [ @@ -1124,7 +1135,7 @@ "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" ], - "markers": "python_version < '3.11' and python_version >= '3.7'", + "markers": "python_version < '3.11'", "version": "==2.0.1" }, "traitlets": { @@ -1140,7 +1151,7 @@ "sha256:c97dfde1f7bd43a71c8d2a58e369e9b2bf692d1334ea9f9cae55add7d0dd0f84", "sha256:fdb6d215c776278489906c2f8916e6e7d4f5a9b602ccbcfdf7f016fc8da0596e" ], - "markers": "python_version >= '3.6'", + "markers": "python_version >= '3.7'", "version": "==2.0.7" }, "virtualenv": { @@ -1153,10 +1164,10 @@ }, "wcwidth": { "hashes": [ - "sha256:9a929bd8380f6cd9571a968a9c8f4353ca58d7cd812a4822bba831f8d685b223", - "sha256:a675d1a4a2d24ef67096a04b85b02deeecd8e226f57b5e3a72dbb9ed99d27da8" + "sha256:390c7454101092a6a5e43baad8f83de615463af459201709556b6e4b1c861f97", + "sha256:aec5179002dd0f0d40c456026e74a729661c9d468e1ed64405e3a6c2176ca36f" ], - "version": "==0.2.9" + "version": "==0.2.10" }, "wheel": { "hashes": [ diff --git a/api_endpoints/v1_postcode_lookup/app.py b/api_endpoints/v1_postcode_lookup/app.py index 7dd5540..7d12ec0 100644 --- a/api_endpoints/v1_postcode_lookup/app.py +++ b/api_endpoints/v1_postcode_lookup/app.py @@ -1,5 +1,6 @@ import os +from dc_logging_client import DCWidePostcodeLoggingClient from mangum import Mangum from middleware import MIDDLEWARE from starlette.applications import Starlette @@ -13,9 +14,24 @@ init_sentry() +if logger_arn := os.environ.get("LOGGER_ARN"): + POSTCODE_LOGGER = DCWidePostcodeLoggingClient(function_arn=logger_arn) +else: + POSTCODE_LOGGER = DCWidePostcodeLoggingClient( + function_arn="fake", fake=True + ) + def get_postcode_response(request: Request): postcode = request.path_params["postcode"] + + # Log this request + POSTCODE_LOGGER.entry_class( + postcode=postcode, + dc_product=POSTCODE_LOGGER.dc_product.ec_api, + calls_devs_dc_api=True, + ) + try: response = client.get_postcode_response(request, postcode) except DevsDCException as error: diff --git a/template.yaml b/template.yaml index 005967e..c31d3e1 100644 --- a/template.yaml +++ b/template.yaml @@ -75,6 +75,11 @@ Parameters: Description: "The domain the app is on." Type: String + AppLoggerArn: + Default: AppLoggerArn + Description: "The ARN of the Lambda function to log to" + Type: AWS::SSM::Parameter::Value + Resources: DependenciesLayer: Type: AWS::Serverless::LayerVersion @@ -110,6 +115,7 @@ Resources: DC_API_TOKEN: !Ref AppDCAPIToken SAM_LAMBDA_CONFIG_ENV: !Ref AppSamLambdaConfigEnv APP_DOMAIN: !Ref AppDomain + LOGGER_ARN: !Ref AppLoggerArn Events: HTTPRequests: Type: Api