Last week I was playing around with AWS App runner which is a new and exciting offering by AWS. So, In this article we'll be deploying our Next.js app on AWS App Runner
What is AWS App runner?
AWS App runner is a fully managed service that makes it easy to deploy containerized web applications, APIs at scale without any prior infrastructure experience or knowledge.
Here are some features:
- Automatic builds and deploys
- Out of the box load balancing
- Simple Auto scaling
- SSL enabled by default!
Best thing is we can just start with your source code (on Github) without even writing a
Dockerfile using automatic builds!
Note: I will also add that the AWS App Runner is still a relatively new service when compared to AWS ECS or AWS EKS
I've initialized a new next project using
next-app and committed it to a github repository
yarn create next-app --typescript
Let's deploy it!
Find our AWS App Runner service
Login into AWS console and let's search for
AWS App Runner
Create an App Runner service
Here i'll add a connection with my github account to keep things simple.
But you can also build and push your docker image to AWS ECR and use that as well.
It'll now create a connection with github using AWS CodeStar
In this step we need to tell App Runner how to build and start our application.
We can either configure it from the console or you can also add a
apprunner.yaml to root of your repository as below
version: 1.0 runtime: nodejs12 build: commands: build: - yarn --production - yarn build run: command: yarn start network: port: 3000
To keep things simple, let's add config directly from the console.
Note: at the time of writing this article, AWS App Runner only supports python 3 and nodejs 12 environment
We're almost there! In this step we can configure things like compute CPU and memory, environment variables, autoscaling, health checks and tags.
Auto scaling (optional)
As App Runner supports autoscaling by default we can just tweak the config to fit our needs
We can add a custom auto scaling config if required!
Health checks (optional)
It's always good to have health check setup, currently App Runner only supports TCP based health checks
Here, we can configure an IAM role for our instance. This is required if you are using
aws-sdk to integrate with other AWS services.
Example: Nodejs server using AWS S3 to store images
It's never a bad idea to tag your AWS resources!
Review and Deploy!
At last, let's review our setup and deploy!
Okay, now our deploy has been created.
Note: this usually takes 2-3 minutes as App Runner dockerize's our app and starts it. If you're using already built docker image available on AWS ECR, then deploys would be instant!
Our deployment was a success and we can access our service via the
default domain url given by the App Runner
We might want to add a custom domain to our AWS App Runner service, this can be done by going to the
Custom domains tab
Thanks for Reading, I hope that it was exciting for you as well as it was for me. As always feel free to reach out to me on Twitter if you face any issues!
Top comments (7)
Hey Karan, awesome post!
For folks coming across the post, I justed wanted to share that Next.js apps can also be deployed to Lambda@Edge and hosted in the serverless architecture. Here's an example of deploying using CDK with the SST framework - serverless-stack.com/examples/how-...
SST framework looks amazing, thanks for sharing
SST looks awesome. Is it possible to deploy to standard Lambda by any chance, Both Serverless framework and SST deploy to edge, is there a reason behind this?
All works fine but my NextJS app doesnt recognize any of the environment variables I give it through the config service although I use NEXT_PUBLIC prefix for SSR. Does anyone know what else I could do?
We were using this until our client asked for http to https redirection, which AppRunner doesn't offer. Sadly had to move away from AppRunner
Now it is supporting
Yeah it’s still quite new, I’m excited to see how