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
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!
I've initialized a new next project using
next-app and committed it to a github repository
yarn create next-app --typescript
Login into AWS console and let's search for
AWS App Runner
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
Health checks (optional)
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!
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!