Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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 Jan 18, 2021
9c40bb4
fix: add @sls-next/lambda-at-edge dep link
kirkness Jan 18, 2021
3799b10
fix: add cdk assert lib
kirkness Jan 18, 2021
b12f6db
fix: update failing snapshot
kirkness Jan 18, 2021
50da04f
Merge branch 'master' into master
kirkness Jan 19, 2021
ed731a2
fix: updates cdk asset caches to match sls-component caches
kirkness Jan 20, 2021
00e930d
Merge branch 'master' into master
danielcondemarin Jan 24, 2021
ea6cc16
refactor: run prettier on fixture files
kirkness Jan 24, 2021
2a3ef61
docs: add intial cdk documentation
kirkness Jan 24, 2021
2fd6258
test: update test snapshots
kirkness Jan 24, 2021
bdfcd5c
docs: add cdk info to readmes
kirkness Jan 24, 2021
b86e3c0
docs: fix syntax on docs
kirkness Jan 24, 2021
9fe27fd
test: add unit tests for readDirectoryFiles
kirkness Jan 24, 2021
a9a2210
test: add tests to CDK construct
kirkness Jan 25, 2021
156770c
fix: update snapshot with new res names
kirkness Jan 25, 2021
21a78df
Merge branch 'master' into master
kirkness Jan 25, 2021
578fe7b
fix: pass custom behaviours, fix image lambda policy and remove pruning
kirkness Jan 27, 2021
1ceefdb
Merge branch 'master' of https://github.com/kirkness/serverless-next.js
kirkness Jan 27, 2021
a8dd7a1
fix: api should allow all methods
kirkness Jan 27, 2021
e649bfe
feat: add ability to override the deault behavior props
kirkness Jan 29, 2021
3a3f345
fix: allo name overrides
kirkness Jan 29, 2021
5b17e6f
fix: tests, update snapshots and construct tests using new lambda name
kirkness Jan 29, 2021
6e0b091
Merge branch 'master' into master
kirkness Jan 29, 2021
1538a8d
fix: revert to determining cache internally rather than using s3-stat…
kirkness Jan 30, 2021
7ba318e
test: add test for readInvalidationPathsFromManifest
kirkness Jan 30, 2021
e5696c6
fix: include body in api origin request
kirkness Feb 2, 2021
48bb3c4
Merge branch 'master' into master
dphang Feb 9, 2021
b918d1e
fix: remove unneeded async from test
kirkness Feb 10, 2021
b811058
fix: format all remaning fixture files
kirkness Feb 10, 2021
a2af6f7
test: update cdk snapshots
kirkness Feb 11, 2021
7aeaec9
fix: reduce number of invalidations created by stripping duplicates,…
kirkness Feb 13, 2021
19bf59c
Merge branch 'master' into master
kirkness Feb 13, 2021
989c8a6
fix: typo
kirkness Feb 13, 2021
5d0a370
Merge branch 'master' of https://github.com/kirkness/serverless-next.js
kirkness Feb 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```

Expand Down
98 changes: 98 additions & 0 deletions documentation/docs/cdkconstruct.md
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
35 changes: 21 additions & 14 deletions documentation/sidebars.js
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"
]
},
}
};
3 changes: 1 addition & 2 deletions packages/libs/s3-static-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
"homepage": "https://github.com/serverless-nextjs/serverless-next.js#readme",
"dependencies": {
"aws-sdk": "2.728.0",
"fast-glob": "^3.2.5",
"fs-extra": "^9.0.1",
"klaw": "^3.0.0",
"mime-types": "^2.1.27",
"regex-parser": "^2.2.10"
},
"devDependencies": {
"@types/klaw": "^3.0.1",
"@types/mime-types": "^2.1.0",
"typescript": "^3.9.6"
}
Expand Down
Loading