NextJS 13 hosting through CLI

2

I'm trying to migrate our mono repo that is a mixed tech set of MFEs to Amplify hosting. Using console and a custom amplify.yml file I managed to get one of the apps deployed and working with no issues but that console based git push CI/CD setup won't work for us and we will have to be in charge of CI/CD so we have to do this using the CLI. I have not been able to find many examples out there to host a modern (v12+) nextJS app using the cli and my own tries have all been unsuccessful. I'm starting to wonder if hosting a nextJS13 app through CLI is even possible. Has anyone had any experience with this?

Amir
asked a year ago550 views
1 Answer
0

To deploy a Next.js 13 app using CI/CD on AWS Amplify Hosting, you need to follow these steps:

  • Create a Next.js app using Create Next App [1].
  • Initialize Amplify in your project and add any backend features using Amplify CLI [1].
  • Add hosting to your project and choose Continuous deployment as the hosting type[2,1].
  • Connect your app to a Git provider such as GitHub, GitLab or Bitbucket using Amplify Console[2,3].
  • Configure your build settings and environment variables using amplify.yml file[1].
  • Push your code changes to your Git branch and watch Amplify Console build and deploy them to your web app[2,3].

Do you have any questions about these steps? A sample amplify.yml file for a Next.js 13 app is as follows:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

[1] https://docs.amplify.aws/guides/hosting/nextjs/q/platform/js/
[2]https://docs.amplify.aws/start/getting-started/hosting/q/integration/next/
[3]https://aws.amazon.com/blogs/mobile/host-a-next-js-ssr-app-with-real-time-data-on-aws-amplify/

profile pictureAWS
answered a year ago
  • Thanks Raheel for your response, Yes that flow already works just fine. No problems there. The issue we have is wanting to decouple from Amplify Console git push based builds and use 'amplify cli publish' to selectively build artefact and push to amplify. We already do this for none-nextjs apps with no problem but for nextjs 13 the only way to have success currently is the git based approach that we want to avoid, Our mono repo has many 10s of MFEs that we would not want to trigger a build/deploy for every single one of, with each PR merge plus more often than not our merge and release happen quite separately to each other.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions