walln / nextjs-vercel-aws-cdk-example

Example Next.js project deployed on Vercel with AWS services for database, cron jobs and asynchronous jobs

Home Page:https://nextjs-vercel-aws-cdk-example.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nextjs-vercel-aws-cdk-example Mentioned in Awesome CDK

Companion project of the article at https://dev.to/vvo/coding-the-jamstack-missing-parts-databases-crons-background-jobs-1bpj

This is a Next.js example coupled with AWS services to provide:

The goal is to have Next.js being deployed on Vercel, with resources being deployed on AWS via AWS Cloud Development Kit. The AWS stack is described and deployed via a single JavaScript file (infra/ExampleStack.js) thanks to AWS CDK's infrastructure as code (IaC) features.

This example provides local tools to replicate the AWS services in development mode.

Requirements

How to use

  1. Fork this repository, add it to your Vercel projects, deploy it
  2. Clone the repository locally and run
yarn
yarn cdk deploy # first run can be long

This will deploy the services to AWS.

  1. Add necessary env variables to your Vercel project:

You need to add SECRET_AWS_ACCESS_KEY_ID, SECRET_AWS_SECRET_ACCESS_KEY and SECRET_AWS_REGION to Vercel, see https://vercel.com/blog/environment-variables-ui on how to do it.

  1. Verify it's working:

You can check in CloudWatch logs at https://console.aws.amazon.com/cloudwatch/home that your functions are called:

  • every 5 minutes for jobs/checkTwitter.js
  • when you click on the "Generate Pdf" button in your production Vercel application for jobs/generatePdf.js.

Local development

In local development, all you have to do is:

overmind start

By reading the Procfile This will start:

  • The Next.js app in development mode
  • The PostgreSQL database via Docker
  • The cron jobs defined in cron-jobs.js

Tips and docs

About

Example Next.js project deployed on Vercel with AWS services for database, cron jobs and asynchronous jobs

https://nextjs-vercel-aws-cdk-example.vercel.app


Languages

Language:JavaScript 100.0%