Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Implement a local mode #541

Open
conico974 opened this issue Oct 10, 2024 · 2 comments
Open

[Feature] Implement a local mode #541

conico974 opened this issue Oct 10, 2024 · 2 comments

Comments

@conico974
Copy link
Contributor

conico974 commented Oct 10, 2024

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

@thirdender
Copy link

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.

@conico974
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants