open-next icon indicating copy to clipboard operation
open-next copied to clipboard

[Feature] Implement a local mode

Open conico974 opened this issue 2 years ago • 4 comments

Allow to run OpenNext (not Next) locally for testing/debugging purposes with a simple command like @opennextjs/aws local or @opennextjs/aws dev

It should be relatively easy, as everything is already in the doc

conico974 avatar Oct 10 '24 11:10 conico974

Are you talking about running the Next.js server locally and also deploying? That should be possible with SST v3. Alternatively, there are instructions for running OpenNext locally in the README. To set up an existing Next.js project with SST, deploy, and run locally:

  1. From inside your Next.js project directory, run npx sst@latest init. This will set up the basic SST config files.
  2. Run npm install (or yarn install depending on which package manager you're using) to install the new dependencies.
  3. Add the following AWS profile to your ~/.aws/config file. Make sure to enter the correct value for your AWS SSO login url and AWS account ID.
    [profile YOUR_AWS_PROFILE_NAME]
    region=us-east-1
    output=json
    sso_start_url=https://X-XXXXXXXXXX.awsapps.com/start
    sso_region=us-east-1
    sso_role_name=AdministratorAccess
    sso_account_id=XXXXXXXXXXXX
    
  4. Modify your package.json file with the following scripts. Replace YOUR_AWS_PROFILE_NAME with the AWS profile
    ...
      "scripts": {
        "start": "AWS_PROFILE=YOUR_AWS_PROFILE_NAME sst dev --stage local",
        "dev": "next dev --experimental-https",
        "build": "next build",
        "deploy": "AWS_PROFILE=YOUR_AWS_PROFILE_NAME sst deploy --stage dev",
        "destroy": "AWS_PROFILE=YOUR_AWS_PROFILE_NAME sst remove --stage dev",
        "lint": "next lint"
      },
    ...
    
  5. Prior to running any SST commands, make sure you are logged into your AWS SSO with the command:
    aws sso login --profile=YOUR_AWS_PROFILE_NAME
    
  6. Make any appropriate modifications to your sst.config.ts file. In my case, I added a Custom Domain
  7. For local development work, run npm run start. This will initiate the SST tooling and then start the Next.js server in dev mode.
  8. For deployment, run npm run deploy. This uses a different SST stage than the local to avoid creating/destroying the CloudFront CDN each time you run the project locally.

Does that fit your needs? If you give it a try and run into any issues, feel free to reach out, I'm not 100% sure I got the instructions right from memory and I'm willing to tweak them as needed for clarity or to fix mistakes.

thirdender avatar Oct 12 '24 03:10 thirdender

Thanks, but this issue is more a reminder of what i need to do as a PR. Right now it's a hassle to run OpenNext (not Next) locally, you have to manually create a bunch of wrapper converter and other stuff. Implementing a @opennextjs/aws local or @opennextjs/aws dev command would be great and helpful for people contributing

conico974 avatar Oct 12 '24 07:10 conico974

@conico974 how exactly would @opennextjs/aws local / dev work?

gavinlynch avatar May 04 '25 13:05 gavinlynch

Basically it would do this https://opennext.js.org/aws/contribute/local_run, but in one command

conico974 avatar May 04 '25 18:05 conico974