DEV Community

Cover image for Testing the new CDK Construct to deploy a Serverless NextJS application in CloudFront and Lambda@Edge
Ibrahim Cesar for AWS Community Builders

Posted on • Edited on • Originally published at ibrahimcesar.cloud

8 6

Testing the new CDK Construct to deploy a Serverless NextJS application in CloudFront and Lambda@Edge

In a previous article I shared my pursuit of my Infrastructure as Code to be as "AWS native" as possible. So Amplify, SAM and CDK are my arms of choice.

One tremendous gap, specially for me, was a good way to deploy React apps on AWS in a serverless mode without a lot of overhead. The closest I got was running Fargate. But in Serverless Framework community there was a zero-config constructor called Serverless Next which was great. AWS Amplify hinted we could do SSR soon this solution was the best in the community so far.

The overview of the architecture:

Serverless Nextjs Architecture

Source: Serverless Next.js Component GitHub repository

So when I heard the community was developing a CDK Constructor which I was thinking in build with help of others...

Excitement

... I was following closely and interested in the future developments of this release. So the release was published days ago, still labeled as experimental: Serverless Nextjs CDK Construct. Because of my... uh... interest as soon as possible I started testing, I got some problems here and there, asked for help and life found a way.

This live demo, the PokéServerless, is a minimal proof of concept of a NextJS application running on AWS with CloudFront and Lambda@Edge. I just fetch all Pokémons through the PokéAPI then I use a Ditto in pages/[ditto].js to Server Side Generate a page for each one of the Pokémons. Is simple as that.

scizor

Picture above: This badass Bug/Steel type, Scizor, was rendered with getServerSideProps

You can find the code behind this example in this repo.

Gotta Fetch'Em All!

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay