Skip to content

Conversation

@maxn990
Copy link
Member

@maxn990 maxn990 commented Nov 3, 2025

ℹ️ Issue

Closes no ticket

📝 Description

I found that the cors error was not because cors was setup wrong on the aws side of things, but because the backend was crashing as soon as the website was accessed, and the error headers did not include cors. To fix this, I added cors to the response headers for errors, and I started looking into why the crash was happening. The primary cause seemed to be a difference in the version of the aws-sdk used by this project and what is included in Lambda by default.

Addressing this required us to change how Lambda accessed dependencies. To this end, I made a few changes.

  1. Explicitly referenced aws-sdk v2 in all service files
  2. Changed from esbuild to nest build, because we need greater control over which dependencies are included in the build
  3. Created two lambda layers to hold dependencies - one specifically for aws-sdk (you should never have to change this one) and one for holding the rest of the dependencies.

If you add new dependencies to the application, you'll have to make sure it is included in the lambda layers. There are two options for how to do this. You can either update the existing layer, or you can keep the two layers I have already added and put new dependencies into new layers. Either way, the steps will look something like the following:

cd backend
rm -rf deps-layer deps-layer.zip
mkdir -p deps-layer/nodejs
cp package.json deps-layer/nodejs/
cd deps-layer/nodejs
npm install --omit=dev --production
cd ../../deps-layer
zip -r ../deps-layer.zip .

You can then upload this zip file to lambda:

Go to Lambda on AWS, select Layers, and click on bcan-dependencies, or add a new layer if that is the approach you decide to go with.

Screenshot 2025-11-03 at 12 14 34 PM

Click create version.

Screenshot 2025-11-03 at 12 15 34 PM

Upload the zip file you generated above, then select node 22 as the runtime.

Screenshot 2025-11-03 at 12 16 27 PM

A secondary issue that I think was causing it to crash was there was no auth/session route, I added that too.

✔️ Verification

I ensued I could login from the deployed url

Screenshot 2025-11-03 at 12 19 49 PM

Test Changes

No test changes.

🏕️ (Optional) Future Work / Notes

I changed some of the deploy scripts, but you should still be able to deploy with npm run deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants