From c1047bf95b9ec4428fab264cb0a1ff8310050cad Mon Sep 17 00:00:00 2001 From: Allen Annom <49309320+allenannom@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:47:52 +0000 Subject: [PATCH] Uml 3723 golang lambda to run in localstack (#3003) * UML-3619 Convert incoming LPAs to combined format (repository layer) * UML-3723 running event receiver in localstack with the use of make up --- docker-compose.yml | 14 ++++++++++--- lambda-functions/event-receiver/Dockerfile | 7 ++++--- lambda-functions/event-receiver/README.md | 22 ++++++++++++++++++++ lambda-functions/event-receiver/app/main.go | 0 lambda-functions/upload-statistics/README.md | 2 +- 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 lambda-functions/event-receiver/README.md mode change 100644 => 100755 lambda-functions/event-receiver/app/main.go diff --git a/docker-compose.yml b/docker-compose.yml index 93a3d828b7..ab22779ffc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -257,6 +257,8 @@ services: REGION: eu-west-1 AWS_ACCESS_KEY_ID: 'devkey' AWS_SECRET_ACCESS_KEY: 'secretdevkey' + depends_on: + - localstack volumes: - ./lambda-functions/upload-statistics/app:/function/app - ./lambda-functions/.aws-lambda-rie:/aws-lambda @@ -267,19 +269,25 @@ services: # --------------------------- # Lambda for ingestion from MLPA - event-reciever-lambda: - container_name: event-reciever + event-receiver-lambda: + container_name: event-receiver build: context: ./lambda-functions/event-receiver dockerfile: Dockerfile environment: + AWS_LAMBDA_SERVER_PORT: '8080' + AWS_LAMBDA_RUNTIME_API: 'localhost:8080' ENVIRONMENT: local REGION: eu-west-1 AWS_ACCESS_KEY_ID: 'devkey' AWS_SECRET_ACCESS_KEY: 'secretdevkey' volumes: - - ./lambda-functions/event-reciever/app:/function/app + - ./lambda-functions/event-receiver/app:/function/app - ./lambda-functions/.aws-lambda-rie:/aws-lambda + entrypoint: + - /aws-lambda/aws-lambda-rie + command: + - ./main ports: - 9008:8080 diff --git a/lambda-functions/event-receiver/Dockerfile b/lambda-functions/event-receiver/Dockerfile index e065e01c3b..da12438023 100644 --- a/lambda-functions/event-receiver/Dockerfile +++ b/lambda-functions/event-receiver/Dockerfile @@ -7,11 +7,12 @@ COPY go.mod go.sum ./ RUN go mod download COPY app/ ./ - RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o /go/bin/ingestion ./ FROM scratch AS production -COPY --from=base /go/bin/ingestion ingestion +WORKDIR /var/task + +COPY --from=base /go/bin/ingestion ./main -ENTRYPOINT ["./ingestion"] +ENTRYPOINT ["./main"] diff --git a/lambda-functions/event-receiver/README.md b/lambda-functions/event-receiver/README.md new file mode 100644 index 0000000000..7ad1fa19db --- /dev/null +++ b/lambda-functions/event-receiver/README.md @@ -0,0 +1,22 @@ +# Event Receiver + +The stats table is uploaded with historical stats from csv by a one time run script. + +This uploads to the stats table, the Cloudwatch Metric Statistics about the use of the Use a Lasting Power of Attorney service. + +### Testing the lambda image locally + +As the lambda is built from an image, this can be spun up to test in dev environment. + +Bring up the lambda locally + +``` +make build +``` + +# To test lambda +The curl follows a set command to invoke lambda functions as below + +``` +curl -XPOST "http://localhost:9008/2015-03-31/functions/function/invocations" -d '{}' +``` \ No newline at end of file diff --git a/lambda-functions/event-receiver/app/main.go b/lambda-functions/event-receiver/app/main.go old mode 100644 new mode 100755 diff --git a/lambda-functions/upload-statistics/README.md b/lambda-functions/upload-statistics/README.md index 085d35cd3b..ec7b6a042c 100644 --- a/lambda-functions/upload-statistics/README.md +++ b/lambda-functions/upload-statistics/README.md @@ -13,7 +13,7 @@ By default the script uses a mock JSON response object instead of pulling from a Bring up the lambda locally ``` -make build_all +make build ``` # To test lambda