Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 727bb8d

Browse files
docs(lambda-at-edge): add initial documentation
1 parent 454dda4 commit 727bb8d

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

packages/lambda-at-edge/README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1-
### AWS Lambda@Edge toolbox to help you deploy serverless next.js applications to CloudFront
1+
### AWS Lambda@Edge library to help you deploy serverless next.js applications to CloudFront
22

3-
TODO: Contents
3+
This library was created to decouple the core logic of creating serverless rendered next.js applications on the Cloud agnostic of a specific provider. In other words, this library could be used to deploy via serverles components, AWS CDK, or any other providers you'd like.
4+
5+
## Usage
6+
7+
```
8+
const path = require('path');
9+
const { Builder } = require("@sls-next/lambda-at-edge");
10+
11+
const nextConfigDir = '/dir/to/my/nextapp';
12+
const outputDir = path.join(nextConfigDir, ".serverless_nextjs"),
13+
14+
const builder = new Builder(
15+
nextConfigDir,
16+
outputDir,
17+
{
18+
cmd: './node_modules/.bin/next',
19+
cwd: process.cwd(),
20+
env: {},
21+
args: ['build']
22+
}
23+
);
24+
25+
await builder.build();
26+
```
27+
28+
After running the above, the output directory will contain the Lambda@Edge handlers necessary to server side render at the edge.
29+
30+
```
31+
/dir/to/my/next-app/.serverless_nextjs/
32+
33+
> default-lambda
34+
> manifest.json
35+
> pages/
36+
> node_modules/next-aws-cloudfront/index.js
37+
> index.js # handler
38+
39+
> api-lambda
40+
> manifest.json
41+
> pages/api/
42+
> node_modules/next-aws-cloudfront/index.js
43+
> index.js # handler
44+
```
45+
46+
The handlers need to be attached to the `origin-request` trigger of CloudFront. The `api-lambda` edge function should be attached to a CloudFront behaviour that only triggers in the event of `/api/*` requests.
47+
48+
### TODO:
49+
50+
- Provisioning and configuration of the CloudFront distribution
51+
- Create a separate utility to clean up unused Lambda@Edge functions that were previously attached to a CloudFront distribution

0 commit comments

Comments
 (0)