serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.42k stars 449 forks source link

Is there a way to switch between multiple AWS accounts? #361

Open maddoxnelson opened 4 years ago

maddoxnelson commented 4 years ago

I have a dev and prod version of a site, split up by AWS accounts. I typically run a script such as npm run deploy:dev or npm run deploy:prod to deploy. When that happens, my serverless file was able to deploy to the AWS account I had configured, like so:

provider: name: aws runtime: nodejs10.x stage: dev profile: ${self:custom.myProfile.${self:custom.myStage}}

Is there a way to do this? I can sort of get it to work by renaming the .serverless and .serverless-nextjs files when I need to switch to the other one, but obviously this isn't ideal.

Describe the solution you'd like I'd like to be able to specify a set of credentials to use that would generate and keep track of the stacks used to deploy to a specific account.

Describe alternatives you've considered Right now, the only workaround is to comment out the credentials in the .env file and the dev portion in the serverless.yml file. Following that, I also have to rename the .serverless and .serverless-nextjs files (so I typically have .serverless and .serverless-dev, for example).

I could be missing something really obvious, apologies if it's something straightforward!

wabi91 commented 4 years ago

I think that i have a similar issue, my github aciton workflow show errors like this

error:
  NoSuchDistribution: The specified distribution does not exist.
    at Request.extractError (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/protocol/rest_xml.js:53:29)
    at Request.callListeners (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/runner/.serverless/components/registry/npm/serverless-next.js@1.12.0-alpha.0/node_modules/aws-sdk/lib/sequential_executor.js:116:18)

...

48s › myNextApplication › NoSuchDistribution: The specified distribution does not exist.

But, it's okay with staging .env file becuz i already deployed once then it has made a .serverless file, that's why workflow with production env makes trouble.

Is there any way to seperate staging dev and prod?

tonestrike commented 3 years ago

@wabi91 did you ever figure out a solution to this?

BrunoBernardino commented 3 years ago

I would love to have a solution for this, even if it's an environment variable (but ideally would be a variable like awsProfile in serverless.yml). I'm happy to help with a PR if I can get a pointer on this.

wabi91 commented 3 years ago

@tonestrike Not yet. :( It is remembered that the logic was changed so that distribution could be divided into two units instead of switching logic. I want to check it again now, but I am sorry that I couldn't check it because I don't have permission to read because it's a previous workplace project.