cdk-nextjs 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +13811 -0
- package/.prettierrc +0 -0
- package/API.md +9694 -0
- package/LICENSE +202 -0
- package/README.md +137 -0
- package/THIRD-PARTY-LICENSES.md +31 -0
- package/assets/lambdas/assets-deployment/assets-deployment.lambda/assets-deployment.Dockerfile +18 -0
- package/assets/lambdas/assets-deployment/assets-deployment.lambda/index.js +8831 -0
- package/assets/lambdas/revalidate/revalidate.lambda/index.js +67 -0
- package/assets/lambdas/sign-fn-url/sign-fn-url.lambda/index.js +2002 -0
- package/examples/README.md +14 -0
- package/lib/common.d.ts +23 -0
- package/lib/common.js +28 -0
- package/lib/generated-structs/OptionalApplicationLoadBalancedTaskImageOptions.d.ts +106 -0
- package/lib/generated-structs/OptionalApplicationLoadBalancedTaskImageOptions.js +3 -0
- package/lib/generated-structs/OptionalCloudFrontFunctionProps.d.ts +43 -0
- package/lib/generated-structs/OptionalCloudFrontFunctionProps.js +3 -0
- package/lib/generated-structs/OptionalClusterProps.d.ts +49 -0
- package/lib/generated-structs/OptionalClusterProps.js +3 -0
- package/lib/generated-structs/OptionalDistributionProps.d.ts +155 -0
- package/lib/generated-structs/OptionalDistributionProps.js +3 -0
- package/lib/generated-structs/OptionalDockerImageAssetProps.d.ts +124 -0
- package/lib/generated-structs/OptionalDockerImageAssetProps.js +3 -0
- package/lib/generated-structs/OptionalDockerImageFunctionProps.d.ts +399 -0
- package/lib/generated-structs/OptionalDockerImageFunctionProps.js +3 -0
- package/lib/generated-structs/OptionalEdgeFunctionProps.d.ts +428 -0
- package/lib/generated-structs/OptionalEdgeFunctionProps.js +3 -0
- package/lib/generated-structs/OptionalFunctionProps.d.ts +422 -0
- package/lib/generated-structs/OptionalFunctionProps.js +3 -0
- package/lib/generated-structs/OptionalFunctionUrlProps.d.ts +30 -0
- package/lib/generated-structs/OptionalFunctionUrlProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsAssetsDeploymentProps.d.ts +45 -0
- package/lib/generated-structs/OptionalNextjsAssetsDeploymentProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsBuildProps.d.ts +30 -0
- package/lib/generated-structs/OptionalNextjsBuildProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsContainersProps.d.ts +43 -0
- package/lib/generated-structs/OptionalNextjsContainersProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsDistributionProps.d.ts +50 -0
- package/lib/generated-structs/OptionalNextjsDistributionProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsFileSystemProps.d.ts +15 -0
- package/lib/generated-structs/OptionalNextjsFileSystemProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsInvalidationProps.d.ts +17 -0
- package/lib/generated-structs/OptionalNextjsInvalidationProps.js +3 -0
- package/lib/generated-structs/OptionalNextjsVpcProps.d.ts +21 -0
- package/lib/generated-structs/OptionalNextjsVpcProps.js +3 -0
- package/lib/generated-structs/OptionalS3OriginProps.d.ts +64 -0
- package/lib/generated-structs/OptionalS3OriginProps.js +3 -0
- package/lib/generated-structs/OptionalVpcProps.d.ts +224 -0
- package/lib/generated-structs/OptionalVpcProps.js +3 -0
- package/lib/index.d.ts +35 -0
- package/lib/index.js +32 -0
- package/lib/lambdas/assets-deployment/assets-deployment-function.d.ts +13 -0
- package/lib/lambdas/assets-deployment/assets-deployment-function.js +23 -0
- package/lib/lambdas/assets-deployment/assets-deployment.lambda.d.ts +2 -0
- package/lib/lambdas/assets-deployment/assets-deployment.lambda.js +62 -0
- package/lib/lambdas/assets-deployment/common.d.ts +8 -0
- package/lib/lambdas/assets-deployment/common.js +32 -0
- package/lib/lambdas/assets-deployment/fs-to-fs.d.ts +2 -0
- package/lib/lambdas/assets-deployment/fs-to-fs.js +9 -0
- package/lib/lambdas/assets-deployment/fs-to-s3.d.ts +2 -0
- package/lib/lambdas/assets-deployment/fs-to-s3.js +45 -0
- package/lib/lambdas/assets-deployment/prune-s3.d.ts +15 -0
- package/lib/lambdas/assets-deployment/prune-s3.js +42 -0
- package/lib/lambdas/assets-deployment/s3.d.ts +2 -0
- package/lib/lambdas/assets-deployment/s3.js +7 -0
- package/lib/lambdas/assets-deployment/utils.d.ts +18 -0
- package/lib/lambdas/assets-deployment/utils.js +35 -0
- package/lib/lambdas/revalidate/revalidate-function.d.ts +13 -0
- package/lib/lambdas/revalidate/revalidate-function.js +23 -0
- package/lib/lambdas/revalidate/revalidate.lambda.d.ts +2 -0
- package/lib/lambdas/revalidate/revalidate.lambda.js +53 -0
- package/lib/lambdas/sign-fn-url/sign-fn-url-function.d.ts +13 -0
- package/lib/lambdas/sign-fn-url/sign-fn-url-function.js +23 -0
- package/lib/lambdas/sign-fn-url/sign-fn-url.lambda.d.ts +9 -0
- package/lib/lambdas/sign-fn-url/sign-fn-url.lambda.js +35 -0
- package/lib/lambdas/sign-fn-url/sign-request.d.ts +28 -0
- package/lib/lambdas/sign-fn-url/sign-request.js +119 -0
- package/lib/lambdas/sign-fn-url/sign-request.test.d.ts +1 -0
- package/lib/lambdas/sign-fn-url/sign-request.test.js +129 -0
- package/lib/nextjs-assets-deployment.d.ts +116 -0
- package/lib/nextjs-assets-deployment.js +93 -0
- package/lib/nextjs-build/add-cache-handler.d.ts +1 -0
- package/lib/nextjs-build/add-cache-handler.js +23 -0
- package/lib/nextjs-build/add-cache-handler.mjs +18 -0
- package/lib/nextjs-build/builder.Dockerfile +29 -0
- package/lib/nextjs-build/cache-handler.cjs +21513 -0
- package/lib/nextjs-build/cache-handler.d.ts +6 -0
- package/lib/nextjs-build/cache-handler.js +22 -0
- package/lib/nextjs-build/global-containers.Dockerfile +45 -0
- package/lib/nextjs-build/global-functions.Dockerfile +46 -0
- package/lib/nextjs-build/nextjs-build.d.ts +150 -0
- package/lib/nextjs-build/nextjs-build.js +220 -0
- package/lib/nextjs-build/regional-containers.Dockerfile +45 -0
- package/lib/nextjs-build/symlink-full-route-cache.d.ts +1 -0
- package/lib/nextjs-build/symlink-full-route-cache.js +37 -0
- package/lib/nextjs-build/symlink-full-route-cache.mjs +23 -0
- package/lib/nextjs-compute/nextjs-compute-base-props.d.ts +8 -0
- package/lib/nextjs-compute/nextjs-compute-base-props.js +3 -0
- package/lib/nextjs-compute/nextjs-containers.d.ts +43 -0
- package/lib/nextjs-compute/nextjs-containers.js +149 -0
- package/lib/nextjs-compute/nextjs-functions.d.ts +23 -0
- package/lib/nextjs-compute/nextjs-functions.js +57 -0
- package/lib/nextjs-distribution.d.ts +120 -0
- package/lib/nextjs-distribution.js +362 -0
- package/lib/nextjs-file-system.d.ts +42 -0
- package/lib/nextjs-file-system.js +74 -0
- package/lib/nextjs-invalidation.d.ts +19 -0
- package/lib/nextjs-invalidation.js +52 -0
- package/lib/nextjs-revalidation.d.ts +30 -0
- package/lib/nextjs-revalidation.js +65 -0
- package/lib/nextjs-static-assets.d.ts +21 -0
- package/lib/nextjs-static-assets.js +32 -0
- package/lib/nextjs-vpc.d.ts +42 -0
- package/lib/nextjs-vpc.js +64 -0
- package/lib/root-constructs/nextjs-base-overrides.d.ts +26 -0
- package/lib/root-constructs/nextjs-base-overrides.js +3 -0
- package/lib/root-constructs/nextjs-base-props.d.ts +56 -0
- package/lib/root-constructs/nextjs-base-props.js +3 -0
- package/lib/root-constructs/nextjs-global-containers.d.ts +74 -0
- package/lib/root-constructs/nextjs-global-containers.js +125 -0
- package/lib/root-constructs/nextjs-global-functions.d.ts +76 -0
- package/lib/root-constructs/nextjs-global-functions.js +131 -0
- package/lib/root-constructs/nextjs-regional-containers.d.ts +43 -0
- package/lib/root-constructs/nextjs-regional-containers.js +92 -0
- package/package.json +165 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# CDK Next.js Construct Library
|
|
2
|
+
|
|
3
|
+
<!--BEGIN STABILITY BANNER-->
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
> The APIs of higher level constructs in this module are experimental and under active development.
|
|
10
|
+
> They are subject to non-backward compatible changes or removal in any future version. These are
|
|
11
|
+
> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
|
|
12
|
+
> announced in the release notes. This means that while you may use them, you may need to update
|
|
13
|
+
> your source code when upgrading to a newer version of this package.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<!--END STABILITY BANNER-->
|
|
18
|
+
|
|
19
|
+
Deploy [Next.js](https://nextjs.org/) apps on [AWS](https://aws.amazon.com/) with the [AWS CDK](https://aws.amazon.com/cdk/).
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- Supports all features of Next.js App and Pages Router for [Node.js Runtime](https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#nodejs-runtime)
|
|
24
|
+
- Choose your AWS architecture for Next.js with the supported constructs: `NextjsGlobalFunctions`, `NextjsGlobalContainers`, `NextjsRegionalContainers`.
|
|
25
|
+
- Global Content Delivery Network (CDN) built with [Amazon CloudFront](https://aws.amazon.com/cloudfront/) to deliver content with low latency and high transfer speeds.
|
|
26
|
+
- Serverless functions powered by [AWS Lambda](https://aws.amazon.com/lambda/) or serverless containers powered by [AWS Fargate](https://aws.amazon.com/fargate/).
|
|
27
|
+
- Static assets (JS, CSS, public folder) are stored and served from [Amazon Simple Storage Service (S3)](https://aws.amazon.com/s3/) for global constructs to decrease latency and reduce compute costs.
|
|
28
|
+
- [Optimized images](https://nextjs.org/docs/pages/building-your-application/optimizing/images), [data cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), and [full route cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache) are shared across compute with [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/).
|
|
29
|
+
- Customize every construct via `overrides`.
|
|
30
|
+
- When using AWS Lambda for compute, async revalidation is supported with [Amazon Simple Queue Service (SQS)](https://aws.amazon.com/sqs/).
|
|
31
|
+
- AWS security and operational best practices are utilized, guided by [cdk-nag](https://github.com/cdklabs/cdk-nag).
|
|
32
|
+
- First class support for [monorepos](https://monorepo.tools/).
|
|
33
|
+
- [AWS GovCloud (US)](https://aws.amazon.com/govcloud-us) compatible (with `NextjsRegionalContainers`).
|
|
34
|
+
|
|
35
|
+
## Getting Started
|
|
36
|
+
|
|
37
|
+
1. Install [Docker](https://www.docker.com/). We recommend [Rancher Desktop](https://rancherdesktop.io/) with dockerd (moby) container engine enabled.
|
|
38
|
+
1. Install [Node.js](https://nodejs.org/en). We recommend the long term support (LTS) version.
|
|
39
|
+
1. Set your [next.config.js](https://nextjs.org/docs/pages/api-reference/next-config-js) [output](https://nextjs.org/docs/pages/api-reference/next-config-js/output) key to `"standalone"`. Learn more here about [Standalone Output](https://nextjs.org/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files).
|
|
40
|
+
1. Setup [AWS Cloud Development Kit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) app.
|
|
41
|
+
1. Install the construct package: `npm install cdk-nextjs`
|
|
42
|
+
1. `cdk deploy`
|
|
43
|
+
1. Visit URL printed in terminal (CloudFormation Output) to view your Next.js app!
|
|
44
|
+
|
|
45
|
+
## Basic Example CDK App
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { App, Stack } from "aws-cdk-lib";
|
|
49
|
+
import { Construct } from "constructs";
|
|
50
|
+
import { fileURLToPath } from "node:url";
|
|
51
|
+
import { NextjsGlobalFunctions } from "cdk-nextjs";
|
|
52
|
+
|
|
53
|
+
class NextjsStack extends Stack {
|
|
54
|
+
constructor(scope: Construct, id: string) {
|
|
55
|
+
super(scope, id, props);
|
|
56
|
+
new NextjsGlobalFunctions(this, "Nextjs", {
|
|
57
|
+
healthCheckPath: "/api/health",
|
|
58
|
+
buildContext: fileURLToPath(new URL("..", import.meta.url)),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const app = new App();
|
|
64
|
+
|
|
65
|
+
new NextjsStack(app, "nextjs");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
See [examples/](./examples/) for more usage examples.
|
|
69
|
+
|
|
70
|
+
## Architecture
|
|
71
|
+
|
|
72
|
+
### `NextjsGlobalFunctions`
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
### `NextjsGlobalContainers`
|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
80
|
+
### `NextjsRegionalContainers`
|
|
81
|
+
|
|
82
|
+

|
|
83
|
+
|
|
84
|
+
## Why
|
|
85
|
+
|
|
86
|
+
The simplest path to deploy Next.js is on [Vercel](https://vercel.com/) - the Platform-as-a-Service company behind Next.js. However, deploying to Vercel can be expensive and some developers want all of their workloads running _directly_ on AWS. Developers can deploy Next.js on AWS through [AWS Amplify Hosting](https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplifysupport.html), but Amplify does not support all Next.js features and manages AWS resources for you so they cannot be customized. If Amplify meets your requirements we recommend you use it, but if you want to use all Next.js features or want more visibility into the AWS resources checkout cdk-nextjs.
|
|
87
|
+
|
|
88
|
+
## Design Principles
|
|
89
|
+
|
|
90
|
+
- Treat Next.js as black box. Minimize reliance on Next.js internal APIs to reduce chance of incompatibility between this construct and future versions of Next.js.
|
|
91
|
+
- Security first.
|
|
92
|
+
- One size does not fit all.
|
|
93
|
+
- Enable customization everywhere.
|
|
94
|
+
|
|
95
|
+
## Limitations
|
|
96
|
+
|
|
97
|
+
- If using `NextjsGlobalFunctions` or `NextjsGlobalContainers` (which use CloudFront), the number of top level files/directories cannot exceed 25, the max number of behaviors a CloudFront Distrubtion supports. We recommend you put all of your public assets into one top level directory (i.e. public/static) so you don't reach this limit. See [CloudFront Quotas](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html) for more information.
|
|
98
|
+
- If using `NextjsGlobalFunctions`, when [revalidating data in Next.js](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation) (i.e. [revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath)), the CloudFront Cache will still hold stale data. You'll need to use AWS SDK JS V3 [CreateInvalidationCommand](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-cloudfront/Class/CreateInvalidationCommand/) to manually invalidate the path in CloudFront. See more [here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html).
|
|
99
|
+
- If using `NextjsGlobalFunctions`, setting an Authorization header won't work by default because of Lambda Function URL with IAM Auth is already using the Authorization header. You can use the `AWS_LWA_AUTHORIZATION_SOURCE` environment variable of [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter) to set an alternative Authorization header in the client which will then be set to the Authorization header when it reaches your app.
|
|
100
|
+
|
|
101
|
+
## Additional Security Recommendations
|
|
102
|
+
|
|
103
|
+
This construct by default implements all AWS security best practices that a CDK construct library reasonably can considering cost and complexity. Below are additional security practices we recommend you implement within your CDK app. Please see them below:
|
|
104
|
+
|
|
105
|
+
- [VPC Flow Logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html). See [examples/](./examples) for sample implementation.
|
|
106
|
+
- [Scan ECR Images For Vulnerabilities](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html).
|
|
107
|
+
- For `NextjsGlobalFunctions` and `NextjsGlobalContainers`, [CloudFront Access Logs](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html). See [examples/](./examples) for sample implementation.
|
|
108
|
+
- For `NextjsGlobalContainers` and `NextjsRegionalContainers`, [ALB HTTPS Listener](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)
|
|
109
|
+
|
|
110
|
+
## Estimated Costs
|
|
111
|
+
|
|
112
|
+
WIP
|
|
113
|
+
|
|
114
|
+
## Acknowledgements
|
|
115
|
+
|
|
116
|
+
This construct was built on the shoulders of giants. Thank you to the contributors of [cdk-nextjs-standalone](https://github.com/jetbridge/cdk-nextjs) and [open-next](https://github.com/sst/open-next).
|
|
117
|
+
|
|
118
|
+
## Contributing
|
|
119
|
+
|
|
120
|
+
Steps to build locally:
|
|
121
|
+
|
|
122
|
+
1. `git clone https://github.com/cdklabs/cdk-nextjs.git`
|
|
123
|
+
2. `cd cdk-nextjs`
|
|
124
|
+
3. `pnpm i && pnpm compile && pnpm build`
|
|
125
|
+
|
|
126
|
+
This project uses Projen, so make sure to not edit [Projen](https://projen.io/) created files and only edit .projenrc.ts.
|
|
127
|
+
|
|
128
|
+
## FAQ
|
|
129
|
+
|
|
130
|
+
Q: How does this compare to [cdk-nextjs-standalone](https://github.com/jetbridge/cdk-nextjs)?
|
|
131
|
+
A: cdk-nextjs-standalone relies on [OpenNext](https://github.com/sst/open-next). OpenNext injects custom code to interact with private Next.js APIs. While OpenNext is able to make some optimizations that are great for serverless environments, this comes at an increase maintenance cost and increased chances for breaking changes. A goal of cdk-nextjs is to customize Next.js as little as possible to reduce the maintenance burden and decrease chances of breaking changes.
|
|
132
|
+
|
|
133
|
+
Q: Why not offer API Gateway version of construct?
|
|
134
|
+
A: API Gateway does not support streaming.
|
|
135
|
+
|
|
136
|
+
Q: Why EFS instead of S3?
|
|
137
|
+
A: Next.js has 3 types of server caching that are persisted to disk: [Data Cache](https://nextjs.org/docs/app/building-your-application/caching#data-cache), [Full Route Cache](https://nextjs.org/docs/app/building-your-application/caching#full-route-cache), and [Image Optimization](https://nextjs.org/docs/pages/building-your-application/optimizing/images). Cached data is persisted at .next/cache/fetch-cache, cached full routes are persisted at .next/server/app, and optimized images are persisted at .next/cache/images. Next.js provides a way to customize where cached data or cached full routes are persisted through the [Custom Next.js Cache Handler](https://nextjs.org/docs/app/api-reference/next-config-js/incrementalCacheHandlerPath), but there currently is no way to persist optimized images. Therefore, we need a way to persist cached data at the file system level which is transparent to Next.js. To do this, we use [Amazon Elastic File System (EFS)](https://aws.amazon.com/efs/). Benefits of EFS include being able to cache any Next.js data persisted to disk and therefore being flexible to adapt to Next.js as the framework evolves caching additional types of data. One exception to not using the Custom Next.js Cache Handler is to support [Data Cache Time-based Revalidation](https://nextjs.org/docs/app/building-your-application/caching#time-based-revalidation) when using AWS Lambda functions. Functions only run when they are responding to a request preventing time-based revalidation unlike containers with AWS Fargate which run continually. For functions, an [Amazon SQS Queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) and consuming function that will make a HEAD request with x-prerender-revalidate header needed for Next.js to update cache.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
The Amazon cdk-nextjs CDK Construct includes the following third-party software/licensing:
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
File: examples/app-playground/public/static/alexander-andrews-brAkTCdnhW8-unsplash.jpg
|
|
6
|
+
Original Photo: https://unsplash.com/photos/silver-slr-camera-on-teal-background-brAkTCdnhW8
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
File: examples/app-playground/public/static/eniko-kis-KsLPTsYaqIQ-unsplash.jpg
|
|
11
|
+
Original Photo: https://unsplash.com/photos/white-and-black-polaroid-one-step-2-instant-camera-on-white-board-KsLPTsYaqIQ
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
File: examples/app-playground/public/static/guillaume-coupy-6HuoHgK7FN8-unsplash.jpg
|
|
16
|
+
Original Photo: https://unsplash.com/photos/black-polaroid-instant-camera-on-white-surface-6HuoHgK7FN8
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
File: examples/app-playground/public/static/patrick-OIFgeLnjwrM-unsplash.jpg
|
|
21
|
+
Original Photo: https://unsplash.com/photos/white-and-black-polaroid-instant-camera-OIFgeLnjwrM
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
File: examples/app-playground/public/static/prince-akachi-LWkFHEGpleE-unsplash.jpg
|
|
26
|
+
Original Photo: https://unsplash.com/photos/woman-smiling-beside-red-wall-LWkFHEGpleE
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
File: examples/app-playground/public/static/yoann-siloine-\_T4w3JDm6ug-unsplash.jpg
|
|
31
|
+
Original Photo: https://unsplash.com/photos/black-and-gray-canon-camera-on-white-surface-_T4w3JDm6ug
|
package/assets/lambdas/assets-deployment/assets-deployment.lambda/assets-deployment.Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#checkov:skip=CKV_DOCKER_2: healthcheck not needed for Custom Resource
|
|
2
|
+
#checkov:skip=CKV_DOCKER_3: lambda container creates user by default
|
|
3
|
+
#checkov:skip=CKV_DOCKER_7: latest tag is ok to use for local builder container
|
|
4
|
+
ARG BUILDER_IMAGE_TAG
|
|
5
|
+
FROM $BUILDER_IMAGE_TAG as builder
|
|
6
|
+
FROM public.ecr.aws/lambda/nodejs:20 as runner
|
|
7
|
+
|
|
8
|
+
ARG RELATIVE_PATH_TO_WORKSPACE
|
|
9
|
+
COPY --from=builder --chown=nextjs:nodejs /app/$RELATIVE_PATH_TO_WORKSPACE/public /app/public
|
|
10
|
+
# see src/nextjs-assets-deployment.ts's #createCustomResource method to see what
|
|
11
|
+
# we copy from within this resulting image in /app/.next to S3 and EFS
|
|
12
|
+
COPY --from=builder --chown=nextjs:nodejs /app/$RELATIVE_PATH_TO_WORKSPACE/.next /app/.next
|
|
13
|
+
# create fetch-cache if not created by next build
|
|
14
|
+
RUN mkdir -p /app/.next/cache/fetch-cache
|
|
15
|
+
# copy bundled custom resource handler
|
|
16
|
+
COPY --chown=nextjs:nodejs ./index.js ./
|
|
17
|
+
|
|
18
|
+
CMD ["index.handler"]
|