serverless-next.js: `Invalid credentials or this AWS S3 bucket name may already be taken` error when trying to deploy

Describe the bug We first hit this issue today, when trying to deploy an update to a project. The project was last deployed (successfully) about 2 days ago. Nothing had changed in terms of serverless or nextjs configuration, and the build step is successful. I tried doing a clean clone of the repository and running it cleanly, and I also tried removing the bucketName configuration to allow for a generated name - the error persisted. Is anyone else encountering this?

To Reproduce Steps to reproduce the behavior:

  1. Create a project with this config:
demoproject:
  component: serverless-next.js
  inputs:
    domain:
      - demoproject
      - decimal.fm
    bucketName: demoprojectserverless
    build:
      enabled: true
      env:
        NEXT_TELEMETRY_DISABLED: 1
    memory:
      defaultLambda: 1024
      apiLambda: 2048
  1. Run serverless
  2. Observe the error:
 Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken      
at ensureBucket (/root/.serverless/components/registry/npm/serverless-next.js@1.8.0/node_modules/@serverless/aws-s3/utils.js:53:13)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Expected behavior Usual deployment.

Screenshots image

Desktop (please complete the following information):

  • OS: Alpine docker container
  • Version 3.10

Additional context I run the serverless command in an Alpine Docker container - but I have successfully deployed in this way before now, and don’t believe that to be related.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20

Most upvoted comments

Updated the docs with possible solutions for the env variable concatenation issue: https://github.com/serverless-nextjs/serverless-next.js/blob/master/README.md#concatenating-environment-variables-doesnt-seem-to-work

Let me know if that works.

@kylekirkby, I am not sure why it is breaking. Using the latest alpha version and the following serverless.yml works for the test next-app:

stage: ${env.STAGE}

next-app:
  component: "../../serverless-components/nextjs-component"
  inputs:
    build:
      postBuildCommands: ["node scripts/post-build-test.js"]
    cloudfront:
      defaults:
        forward:
          headers: [Authorization]
      api/*:
        forward:
          headers: [Authorization]

Ran into this as well, with a nextjs project that was deployed by another person using a different set of AWS credentials, and then I tried to deploy an update.

Unfortunately deleting the .serverless folder and then running serverless results in a brand new deployment (new s3 bucket, new cloudfront distribution).

Has anyone figured out how multiple sets of AWS credentials can be used to push updates to the same existing deployment (not generate a brand new one)?