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

Commit ada5387

Browse files
committed
doc: improved description of the project
1 parent f4a79a7 commit ada5387

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ dist/**
55

66
# Temporary build folder.
77
nodejs/**
8-
.next/**
9-
next.out/**

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# NextJS Lambda Utils
22

3-
This is a set of utils needed for deploying NextJS into AWS Lambda.
4-
It includes a wrapper for `next/server/image-optimizer` allowing to use S3.
5-
And includes CLI and custom server handler to integrate with ApiGw.
3+
This is a project allowing to deploy Next applications (standalone options turned on) to AWS Lambda without hassle.
4+
5+
This is an alternative to existing Lambda@Edge implementation ([see](https://www.npmjs.com/package/@sls-next/lambda-at-edge)) as it has too many limitations (primarily inability to use env vars) and deployments take too long.
6+
7+
This library uses Cloudfront, S3, ApiGateway and Lambdas to deploy easily in seconds (hotswap supported).
8+
69

710
- [NextJS Lambda Utils](#nextjs-lambda-utils)
811
- [TL;DR](#tldr)
@@ -106,7 +109,7 @@ const sharpLayer = new LayerVersion(this, 'SharpDependenciesLayer', {
106109

107110
To provide both image and server handlers with all depdencies (next is using `require.resolve` inside, so it cannot be bundled standalone for now).
108111

109-
We pre-package this layer so it can be included in Lambda without hasle.
112+
We pre-package this layer so it can be included in Lambda without hassle.
110113
```
111114
import { nextLayerZipPath } from '@sladg/nextjs-lambda'
112115

lib/contruct.ts renamed to lib/construct.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Code, Function, LayerVersion, Runtime } from 'aws-cdk-lib/aws-lambda'
66
import { Bucket, BucketAccessControl } from 'aws-cdk-lib/aws-s3'
77
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment'
88
import { Construct } from 'constructs'
9+
import packageJson from '../package.json'
910

1011
import { imageHandlerZipPath, sharpLayerZipPath, nextLayerZipPath } from './consts'
1112

@@ -38,14 +39,21 @@ export class NextStandaloneStack extends Stack {
3839
})
3940

4041
const sharpLayer = new LayerVersion(this, 'SharpLayer', {
41-
code: Code.fromAsset(props.sharpLayerZipPath ?? sharpLayerZipPath, { assetHash: 'static', assetHashType: AssetHashType.CUSTOM }),
42+
code: Code.fromAsset(props.sharpLayerZipPath ?? sharpLayerZipPath, {
43+
assetHash: `static-sharp-${packageJson.version}`,
44+
assetHashType: AssetHashType.CUSTOM,
45+
}),
4246
})
4347

4448
const nextLayer = new LayerVersion(this, 'NextLayer', {
45-
code: Code.fromAsset(props.nextLayerZipPath ?? nextLayerZipPath, { assetHash: 'static-next', assetHashType: AssetHashType.CUSTOM }),
49+
code: Code.fromAsset(props.nextLayerZipPath ?? nextLayerZipPath, {
50+
assetHash: `static-next-${packageJson.version}`,
51+
assetHashType: AssetHashType.CUSTOM,
52+
}),
4653
})
4754

4855
const assetsBucket = new Bucket(this, 'NextAssetsBucket', {
56+
// @NOTE: Considering not having public ACL.
4957
publicReadAccess: true,
5058
autoDeleteObjects: true,
5159
removalPolicy: RemovalPolicy.DESTROY,
@@ -147,8 +155,8 @@ export class NextStandaloneStack extends Stack {
147155
sources: [Source.asset(props.assetsZipPath)],
148156
accessControl: BucketAccessControl.PUBLIC_READ,
149157
// Invalidate all paths after deployment.
150-
// distributionPaths: ['/*'],
151-
// distribution: this.cfnDistro,
158+
distributionPaths: ['/*'],
159+
distribution: this.cfnDistro,
152160
})
153161

154162
new CfnOutput(this, 'cfnDistroUrl', { value: this.cfnDistro.distributionDomainName })

lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { NextStandaloneStack } from './contruct'
1+
export { NextStandaloneStack } from './construct'
22
export { imageHandlerZipPath, serverHandlerZipPath, sharpLayerZipPath } from './consts'
33

44
export { handler as serverHandler } from './standalone/server-handler'

0 commit comments

Comments
 (0)