Next.js Static Export S3 Site with Dynamic Routing
Have a more complex use case for Next.js 13? Perhaps check out cdk-nextjs-standalone.
Deploy a static export Next.js site to Cloudfront and S3 while maintaining the ability to use dynamic routes.
This effectively takes all of the benefits of Next.js, including routing, code-splitting, static HTML exporting, and also gives you the benefits of a SPA (single page application). This will be mostly useful for client-generated pages, but you can also partially server side generate some data should you choose.
This may also be useful if you use Next.js SSR in other frontends, and just want to keep a consistent experience for your developers.
Getting Started
You can use this construct effectively with no props, but here is a minimal example with a custom domain:
export class MyStaticSiteStack extends cdk.Stack {
private readonly hostedZone: route53.IHostedZone;
private readonly customDomainName: string;
private readonly site: NextjsExportS3DynamicRoutingSite;
constructor(scope: sst.App, id: string, props?: sst.StackProps) {
super(scope, id, props);
this.hostedZone = this.findHostedZone();
this.customDomainName = "yourdomain.com";
this.site = this.createNextJsSite();
this.createDnsRecord();
}
private findHostedZone(): route53.IHostedZone {
return route53.HostedZone.fromLookup(this, "HostedZone", {
domainName: this.customDomainName,
});
}
private createNextJsSite(): NextjsExportS3DynamicRoutingSite {
const certificate = new acm.Certificate(
this,
"Certificate",
{
domainName: this.customDomainName,
validation: acm.CertificateValidation.fromDns(this.hostedZone),
}
);
return new NextjsExportS3DynamicRoutingSite(this, "NextJsSite", {
distributionProps: {
certificate,
domainNames: [this.customDomainName],
}
});
}
private createDnsRecord = (): route53.ARecord => {
return new route53.ARecord(this, `AliasRecord`, {
recordName: this.customDomainName,
target: route53.RecordTarget.fromAlias(
new r53Targets.CloudFrontTarget(
this.site.cloudfrontDistribution
)
),
zone: this.hostedZone,
});
};
}
There are no outside requirements for this construct, and it will delete all of its resources when the stack is deleted.
Metadata
Release files for cdk-nextjs-export-s3-dynamic-routing 1.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cdk-nextjs-export-s3-dynamic-routing-1.2.6.tar.gz | 312.7 kB | Without provenance | Details for cdk-nextjs-export-s3-dynamic-routing-1.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cdk_nextjs_export_s3_dynamic_routing-1.2.6-py3-none-any.whl | Python 3 | none | any | Details for cdk_nextjs_export_s3_dynamic_routing-1.2.6-py3-none-any.whl |
Total release size: 623.6 kB
Release files / cdk-nextjs-export-s3-dynamic-routing-1.2.6.tar.gz
| Download URL | cdk-nextjs-export-s3-dynamic-routing-1.2.6.tar.gz |
|---|---|
| Size | 312.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
082e1ee4c9afa3d73054b65de1ea0f734ac378b64dcc01e0362c717508821014
|
|
BLAKE2b-256 checksum How to use checksums |
6e74cba01718dc07fa4e8b813de357386ec6bfe48e8c83e2e6e374d101be7b96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.1
|
Release files / cdk_nextjs_export_s3_dynamic_routing-1.2.6-py3-none-any.whl
| Download URL | cdk_nextjs_export_s3_dynamic_routing-1.2.6-py3-none-any.whl |
|---|---|
| Size | 310.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aeb6980edca0f108ad3f86cbbcfcfd0f90621e33a6c76c345eaf96ef824f47f3
|
|
BLAKE2b-256 checksum How to use checksums |
9e76e28f4a24434a0ac9dff4a01845ab75adff8cd52325ebc247374701dca355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.1
|
Security for cdk-nextjs-export-s3-dynamic-routing 1.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.