This repository was archived by the owner on Jan 28, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 456
CDK Construct #878
Merged
Merged
CDK Construct #878
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
5f492b6
feat: add intial cdk component
kirkness 9c40bb4
fix: add @sls-next/lambda-at-edge dep link
kirkness 3799b10
fix: add cdk assert lib
kirkness b12f6db
fix: update failing snapshot
kirkness 50da04f
Merge branch 'master' into master
kirkness ed731a2
fix: updates cdk asset caches to match sls-component caches
kirkness 00e930d
Merge branch 'master' into master
danielcondemarin ea6cc16
refactor: run prettier on fixture files
kirkness 2a3ef61
docs: add intial cdk documentation
kirkness 2fd6258
test: update test snapshots
kirkness bdfcd5c
docs: add cdk info to readmes
kirkness b86e3c0
docs: fix syntax on docs
kirkness 9fe27fd
test: add unit tests for readDirectoryFiles
kirkness a9a2210
test: add tests to CDK construct
kirkness 156770c
fix: update snapshot with new res names
kirkness 21a78df
Merge branch 'master' into master
kirkness 578fe7b
fix: pass custom behaviours, fix image lambda policy and remove pruning
kirkness 1ceefdb
Merge branch 'master' of https://github.com/kirkness/serverless-next.js
kirkness a8dd7a1
fix: api should allow all methods
kirkness e649bfe
feat: add ability to override the deault behavior props
kirkness 3a3f345
fix: allo name overrides
kirkness 5b17e6f
fix: tests, update snapshots and construct tests using new lambda name
kirkness 6e0b091
Merge branch 'master' into master
kirkness 1538a8d
fix: revert to determining cache internally rather than using s3-stat…
kirkness 7ba318e
test: add test for readInvalidationPathsFromManifest
kirkness e5696c6
fix: include body in api origin request
kirkness 48bb3c4
Merge branch 'master' into master
dphang b918d1e
fix: remove unneeded async from test
kirkness b811058
fix: format all remaning fixture files
kirkness a2af6f7
test: update cdk snapshots
kirkness 7aeaec9
fix: reduce number of invalidations created by stripping duplicates,…
kirkness 19bf59c
Merge branch 'master' into master
kirkness 989c8a6
fix: typo
kirkness 5d0a370
Merge branch 'master' of https://github.com/kirkness/serverless-next.js
kirkness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ Please review [features](https://github.com/serverless-nextjs/serverless-next.js | |
| - [AWS Permissions](#aws-permissions) | ||
| - [Architecture](#architecture) | ||
| - [Inputs](#inputs) | ||
| - [CDK Construct](#cdk-construct) | ||
| - [FAQ](#faq) | ||
|
|
||
| > :warning: This README reflects the latest changes on the `master` branch. It may or may not yet be published to the `latest` (stable) or `alpha` release in npm. Please go to [Releases](https://github.com/serverless-nextjs/serverless-next.js/releases), find the correct `@sls-next/serverless-component` version you are using, and open the README for that release for more accurate information. If a feature is listed in this README but not working, please first try upgrading to the most recent `alpha` release in npm. | ||
|
|
@@ -525,6 +526,14 @@ myNextApp: | |
| bucketName: my-bucket | ||
| ``` | ||
|
|
||
| ### CDK Construct | ||
|
|
||
| > (experimental) - more work required to bring this construct up to speed and | ||
| > also to reuse some of the serverless logic. As a result the construct is | ||
| > likely to adapt/change accordingly. | ||
|
|
||
| [Documentation can be found here.](https://serverless-nextjs.com/docs/cdkconstruct) | ||
|
|
||
| ### FAQ | ||
|
|
||
| #### My component doesn't deploy | ||
|
|
@@ -681,10 +690,10 @@ It seems to be a bug in Serverless Components - it may be due to not using the l | |
| ```yml | ||
| stage: ${env.STAGE} | ||
| my-app: | ||
| component: '@sls-next/[email protected]' | ||
| component: "@sls-next/[email protected]" | ||
| inputs: | ||
| domain: | ||
| - '${stage}-front-end' | ||
| - "${stage}-front-end" | ||
| - mydomain.com | ||
| ``` | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| id: cdkconstruct | ||
| title: CDK Construct (experimental) | ||
| sidebar_label: CDK Construct | ||
| --- | ||
|
|
||
| AWS CDK (Cloud Development Kit) makes it possible to write infrastructure in | ||
| code using familiar languages such as JavaScript or Python, and provision via | ||
| Cloudformation. The tool is growing in popularity and so it seems fitting to | ||
| enable Next.js users to be able to deploy their apps using it. The | ||
| `NextJSLambdaEdge` construct will provision the same infrastructure as the | ||
| `serverless-component`. | ||
|
|
||
| It's simple to include the Next.js construct in your app, the following will | ||
| deploy your Next app using a Cloudfront domain: | ||
|
|
||
| ```ts | ||
| // stack.ts | ||
| import { NextJSLambdaEdge } from "@sls-next/cdk-construct"; | ||
| import * as cdk from "@aws-cdk/core"; | ||
|
|
||
| export class MyStack extends cdk.Stack { | ||
| constructor(scope: cdk.Construct, id: string, props: cdk.StackProps) { | ||
| super(scope, id, props); | ||
| new NextJSLambdaEdge(this, "NextJsApp", { | ||
| serverlessBuildOutDir: "./build" | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // bin.ts | ||
| import * as cdk from "@aws-cdk/core"; | ||
| import { Builder } from "@sls-next/lambda-at-edge"; | ||
| import { MyStack } from "./stack"; | ||
|
|
||
| // Run the serverless builder, this could be done elsewhere in your workflow | ||
| const builder = new Builder(".", "./build"); | ||
|
|
||
| builder | ||
| .build() | ||
| .then(() => { | ||
| const app = new cdk.App(); | ||
| new MyStack(app, `MyStack`); | ||
| }) | ||
| .catch((e) => { | ||
| console.log(e); | ||
| process.exit(1); | ||
| }); | ||
| ``` | ||
|
|
||
| To deploy your stack, use the `cdk` CLI as normal. | ||
|
|
||
| ## Adding a Custom Domain | ||
|
|
||
| Now you've deployed your app, you'll likely want to add a custom domain: | ||
|
|
||
| ```ts | ||
| new NextJSLambdaEdge(this, "NextJsApp", { | ||
| serverlessBuildOutDir: "./build", | ||
| // `Certificate.fromCertificateArn` & `HostedZone.fromHostedZoneAttributes` | ||
| // retrieve existing resources, however you could create a new ones in your | ||
| // stack via the relevant constructs | ||
| domain: { | ||
| domainName: "example.com", | ||
| hostedZone: HostedZone.fromHostedZoneAttributes(this, "Zone", { | ||
| hostedZoneId: "123ABC", | ||
| zoneName: "example.com" | ||
| }), | ||
| certificate: Certificate.fromCertificateArn(this, "Cert", "...arn...") | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| ## Available Props | ||
|
|
||
| - `serverlessBuildOutDir` - the output directory of the `Builder`. | ||
| - `domain?: Object` - if you'd like to add a custom domain, provide the | ||
| following three fields on the `domain` object. | ||
| - `hostedZone: IHostedZone;` | ||
| - `certificate: ICertificate;` | ||
| - `domainName: string;` | ||
| - `memory?: number | Record<string, number>` - configure memory on all lambdas | ||
| or individually. | ||
| - `timeout?: number | Record<string, number>` - configure timeout on all lambdas | ||
| or individually. | ||
| - `name?: string | Record<string, string>` - configure the name of all lambdas | ||
| or individually. | ||
| - `runtime?: lambda.Runtime | Record<string, lambda.Runtime>` - configure the runtime of all lambdas | ||
| or individually. | ||
| - `withLogging?: boolean` - set debug logging on the lambda. | ||
| - `whiteListedCookies?: string[]` - provide a list of cookies to forward to the | ||
| CloudFront origin. | ||
| - `defaultBehavior?: Partial<cloudfront.Behaviour>` - provide overrides for the | ||
| default behavior | ||
| - `behaviours?: Array<cloudfront.Behaviour>` - an array of Cloudfront | ||
| distribution behaviours. | ||
| - `invalidationPaths?: string[]` - an array of invalidation paths, by default we | ||
| invalidate all pages found in manifest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| module.exports = { | ||
| someSidebar: { | ||
| Introduction: ['basics', 'motivation', 'design', 'features', 'contributing'], | ||
| 'Getting Started': [ | ||
| 'installation', | ||
| 'customdomain', | ||
| 'customcloudfrontconfig', | ||
| 'staticpagecache', | ||
| 'publicdirectorycache', | ||
| 'awspermissions', | ||
| 'lambdaatedgeconfig', | ||
| 'architecture', | ||
| 'inputs', | ||
| 'faq', | ||
| 'examples' | ||
| Introduction: [ | ||
| "basics", | ||
| "motivation", | ||
| "design", | ||
| "features", | ||
| "contributing" | ||
| ], | ||
| "Getting Started": [ | ||
| "installation", | ||
| "customdomain", | ||
| "customcloudfrontconfig", | ||
| "staticpagecache", | ||
| "publicdirectorycache", | ||
| "awspermissions", | ||
| "lambdaatedgeconfig", | ||
| "architecture", | ||
| "inputs", | ||
| "faq", | ||
| "examples", | ||
| "cdkconstruct" | ||
| ] | ||
| }, | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.