From 7220682fef700d50e1a72f26fa693fcfc8a876d1 Mon Sep 17 00:00:00 2001 From: westonplatter Date: Sat, 8 Jun 2024 12:47:04 -0600 Subject: [PATCH 1/5] use dot syntax to refer to file path and handler --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 818dc03..46dc817 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,4 +16,4 @@ RUN cd ${LAMBDA_TASK_ROOT} && poetry install --no-interaction --no-ansi --no-roo COPY ./ ${LAMBDA_TASK_ROOT}/ -CMD ["src/main.handler"] \ No newline at end of file +CMD ["src.main.handler"] \ No newline at end of file From 69911a56cea4036171ec75f29e54879ab5e181bf Mon Sep 17 00:00:00 2001 From: westonplatter Date: Sat, 8 Jun 2024 12:47:38 -0600 Subject: [PATCH 2/5] add src folder to PYTHON PATH so src is a known module --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 46dc817..bec352b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,5 +15,6 @@ COPY poetry.lock pyproject.toml ${LAMBDA_TASK_ROOT}/ RUN cd ${LAMBDA_TASK_ROOT} && poetry install --no-interaction --no-ansi --no-root --only main COPY ./ ${LAMBDA_TASK_ROOT}/ +ENV PYTHONPATH "${PYTHONPATH}:${LAMBDA_TASK_ROOT}" CMD ["src.main.handler"] \ No newline at end of file From 104ec3d82d60706152deb59451e6be15e7058914 Mon Sep 17 00:00:00 2001 From: westonplatter Date: Sat, 8 Jun 2024 12:47:57 -0600 Subject: [PATCH 3/5] remove depricated param --- serverless.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/serverless.yml b/serverless.yml index 8c83a05..812ec61 100644 --- a/serverless.yml +++ b/serverless.yml @@ -43,7 +43,6 @@ provider: memorySize: 1024 # MB timeout: 30 endpointType: edge - lambdaHashingVersion: 20201221 # apiGateway: # metrics: true tracing: From bcb50e71fdec0fb37eacc2ae46836b26957a60bc Mon Sep 17 00:00:00 2001 From: westonplatter Date: Sat, 8 Jun 2024 12:51:05 -0600 Subject: [PATCH 4/5] docs: add note about architecture config setting --- README.md | 1 + serverless.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 05332db..c3a3d1e 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Test it
- Next time you will deploy the server will be exposed under your domain. 9. Deploy to AWS +Note - if you are building the docker image from a mac, change `architecture: x86_64` to `architecture: arm64` in the `serverless.yml` file. ``` ./scripts/deploy ``` diff --git a/serverless.yml b/serverless.yml index 812ec61..21a8d69 100644 --- a/serverless.yml +++ b/serverless.yml @@ -80,6 +80,8 @@ functions: app: image: name: fastapi-backend-server + architecture: x86_64 # default + # architecture: arm64 # works for docker images built on Mac M1/M2/M3/etc machines environment: STAGE: ${self:provider.stage} From b6d738a710adacc80fed5fd69de99e20eeeb379b Mon Sep 17 00:00:00 2001 From: westonplatter Date: Tue, 11 Jun 2024 10:32:00 -0600 Subject: [PATCH 5/5] build container to match x86 arch --- serverless.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/serverless.yml b/serverless.yml index 21a8d69..c254b0a 100644 --- a/serverless.yml +++ b/serverless.yml @@ -59,6 +59,8 @@ provider: cacheFrom: # This is the path where the serverless framework will put the image in ECR when created for the first time. - ${AWS::AccountId}.dkr.ecr.${self:provider.region}.amazonaws.com/serverless-fastapibackendservice-${self:provider.stage}:fastapi-backend-server + # build container to match the architecture: x86_64 param + platform: linux/amd64 iamRoleStatements: # handles the permissions of the lambda # XRay - Effect: Allow @@ -91,4 +93,4 @@ functions: path: / - http: method: any - path: /{proxy+} \ No newline at end of file + path: /{proxy+}