You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 1, 2025. It is now read-only.
In order to succefully deploy, you firstly need to include `target: 'standalone'` in your `next.config.js` setup.
59
+
Make sure to use NextJS in version 12 or above so this is properly supported.
60
+
61
+
Once target is set, you can go on and use your `next build` command as you normally would.
62
+
To package everything, make sure to be in your project root folder and next folder `.next` and `public` exist. Packaging is done via NPM CLI command of `@slack/nextjs-lambda package`.
63
+
64
+
It will create `next.out/` folder with 3 zip packages. One zip Lambda's code, one is dependencies layer and one is assets layer.
65
+
66
+
- code zip: include all files generated by next that are required to run on Lambda behind ApiGateway. Original handler as well as new server handler are included. Use `handler.handler` for custom one or `server.handler` for original one.
67
+
- dependencies layer: all transpilied `node_modules`. Next includes only used files, dramatically reducing overall size.
68
+
- assets layer: your public folder together with generated assets. Keep in mind that to public refer file, you need to include it in `public/assets/` folder, not just in public. This limitation dramatically simplifies whole setup. This zip file is uploaded to S3, it's not included in Lambda code.
69
+
70
+
### Server handler
71
+
72
+
Custom wrapper around NextServer to allow for passing ApiGateway events into Next server.
73
+
74
+
Cloudfront paths used:
75
+
76
+
-`default`
77
+
-`_next/data/*`
78
+
79
+
### Static assets
80
+
81
+
Next uses multiple directories to determine which file should be served. By default next provides us with list of routes for API/images/assets/pages. To simplify the process as much as possible, we are tapping into resulting paths.
82
+
83
+
We are packaging those assets to simulate output structure and we are using S3 behind CloudFront to serve those files.
84
+
Also, Image Handler is tapping into S3 to provide images, so correct folder structure is crucial.
85
+
86
+
Cloudfront paths used:
87
+
88
+
-`_next/*`
89
+
-`assets/*`
49
90
50
-
This is part of NextJS to Lambda deployment process. More info to follow.
91
+
# TODO
51
92
52
-
## @TODO: Add Server-handler description
93
+
- Explain script used for packaging Next app,
94
+
- Add CDK examples on how to set it up,
95
+
- Export CDK contruct for simple plug-n-play use,
96
+
- Use lib/index.ts as single entry and export all paths/functions from it (including zip paths).
0 commit comments