Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

Invalid credentials or this AWS S3 bucket name may already be taken error when trying to deploy #289

Closed
chrsgrrtt opened this issue Jan 30, 2020 · 20 comments

Comments

@chrsgrrtt
Copy link

chrsgrrtt commented Jan 30, 2020

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/[email protected]/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.

@chrsgrrtt
Copy link
Author

One other thing to note, I created a new, clean IAM role and have it full admin permissions, but according to the AWS console it's not being used:

image

I checked process.env and the and the credentials are correct.

I also removed the old S3 bucket, and tried using different names, etc. Despite the error, I don't believe this is related to S3.

@chrsgrrtt
Copy link
Author

Bizarrely; this issue has "gone away" this morning - nothing was touched/changed overnight. Based on some of the contents of this discussion serverless-components/website#16 - I suspect it could have been an intermittent AWS issue.

@chrsgrrtt
Copy link
Author

This issue has come back - is anyone else experiencing it?

@chrsgrrtt chrsgrrtt reopened this Feb 3, 2020
@Evanht
Copy link

Evanht commented Mar 15, 2020

Hi @chrsgrrtt, Yeh I'm experiencing this too. Did you manage to get to the bottom of it?

@Evanht
Copy link

Evanht commented Mar 15, 2020

Ah so for me the issue was that I had made the initial deploy using AWS credentials for a different account by accident. So when I then updated the credentials and tried to deploy again it failed because the bucketName was already taken (as bucketName has to be unique globally on AWS).

Fix for me was to just delete the .serverless and .serverless_nextjs directories and run serverless again.

@SpicyPete
Copy link

made the initial deploy using AWS credentials for a different account by accident
Does this mean we need to use the same AWS credentials for all developers doing deployments?

@hoonio
Copy link

hoonio commented Jun 26, 2020

I had the same issue too. The fix for me was to serverless logout. I attempted to deploy using serverless cli before to another app created via Serverless dashboard (which is tied to a different IAM user I presume)

@YuK1Game
Copy link

YuK1Game commented Oct 5, 2020

same issue too.

$ serverless

response

Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken

Has been occurring all the time.

IAM not activiry.
WS000000

.env

AWS_ACCESS_KEY_ID=MyAccessKey
AWS_SECRET_ACCESS_KEY=MySecretKey

@C6H6
Copy link

C6H6 commented Oct 12, 2020

I also had Invalid credentials or this AWS S3 bucket name may already be taken error, but removing .serverless catalog worked for me.

@sometimescasey
Copy link

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)?

@kylekirkby
Copy link

I've also just hit this error. I'm also using full admin credentials. The error appears to be due to including an environment variable in the bucketName input. I also cannot use an environment variable in domain input. Any ideas @dphang ? Would be greatly appreciated!

  error:
  Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken
    at ensureBucket (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/@serverless/aws-s3/utils.js:53:13)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

  14s › myNextApp › Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken

The environment variables in the inputs section below fails to be parsed.

myNextApp:
    component: '@sls-next/[email protected]'
    build:
        env:
            BUILD_ENV: ${env.BUILD_ENV}
    inputs:
        domain: ${env.DOMAIN}
        bucketName: ${env.BUILD_ENV}-hub-hosting-files
        timeout: 30
        build:
            env:
                BUILD_ENV: ${env.BUILD_ENV}
            postBuildCommands: ['node serverless-post-build.js', 'node sitemap.xml.js']
    memory: 1024

This config will work fine, however.

myNextApp:
    component: '@sls-next/[email protected]'
    build:
        env:
            BUILD_ENV: ${env.BUILD_ENV}
    inputs:
        domain: ["sub-domain", "domain.com"]
        bucketName: develop-hub-hosting-files
        timeout: 30
        build:
            env:
                BUILD_ENV: ${env.BUILD_ENV}
            postBuildCommands: ['node serverless-post-build.js', 'node sitemap.xml.js']
    memory: 1024

@dphang
Copy link
Collaborator

dphang commented Jan 5, 2021

@kylekirkby I am not quite sure how the env variable substitution works in Serverless Components when you are concatenating like that. Most likely it seems that it might be a bug in Serverless where it's just taking ${env.BUILD_ENV} instead of ${env.BUILD_ENV}-hub-hosting-files which would just be develop, which is likely taken.

It seems someone was facing similar issue like here, seems there is a workaround here: #530 (comment), it might be a bug in serverless framework.

You could also try to console log what the bucket name is before this line:

(i.e inputs.bucketName)

@dphang
Copy link
Collaborator

dphang commented Jan 5, 2021

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
Copy link

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.

Thank you @dphang for adding this! I'm now getting a different problem, however.

  error:
  BadRequest: null
    at Request.extractError (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/services/s3.js:680:35)
    at Request.callListeners (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'BadRequest',
  region: null,
  time: 2021-01-06T09:23:33.810Z,
  requestId: 'BB91A82F780BB367',
  extendedRequestId: '+JBc6veL9u3nn4MA9R9D+/yEIxJZpJWHX1QSs5pdScKNIZXPHi9Rtg+qFcXiTPmi+PcOGSPbGSc=',
  cfId: undefined,
  statusCode: 400,
  retryable: false,
  retryDelay: 79.33691711341662
}

  15s › myNextApp › BadRequest: null

I'll keep digging, could be unrelated...

@kylekirkby
Copy link

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.

Thank you @dphang for adding this! I'm now getting a different problem, however.

  error:
  BadRequest: null
    at Request.extractError (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/services/s3.js:680:35)
    at Request.callListeners (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/request.js:690:12)
    at Request.callListeners (/home/god/.serverless/components/registry/npm/@sls-next/[email protected]/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'BadRequest',
  region: null,
  time: 2021-01-06T09:23:33.810Z,
  requestId: 'BB91A82F780BB367',
  extendedRequestId: '+JBc6veL9u3nn4MA9R9D+/yEIxJZpJWHX1QSs5pdScKNIZXPHi9Rtg+qFcXiTPmi+PcOGSPbGSc=',
  cfId: undefined,
  statusCode: 400,
  retryable: false,
  retryDelay: 79.33691711341662
}

  15s › myNextApp › BadRequest: null

I'll keep digging, could be unrelated...

@dphang, after further testing by commenting out different sections, it appears the problematic line that throws the bad request error was the stage: variable line. If I commented this out, the infrastructure was created successfully. Any ideas why everything breaks when using a serverless stage variable?

@dphang
Copy link
Collaborator

dphang commented Jan 6, 2021

@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]

@kylekirkby
Copy link

Hi @dphang, I should have updated sooner but I’ve come down with the dreaded COVID19. It turns out that I needed to use the STAGE environment variable name and can’t use BUIlD_ENV. All is working now. Thank you for your support.

@dphang
Copy link
Collaborator

dphang commented Apr 15, 2021

Closing old issue, if there are still other problems, please open a new one

@rizaldirnm
Copy link

Any update here? I have same issue

@Sultsina
Copy link

Sultsina commented Jun 11, 2022

Any update here? I have same issue

I had this issue and figured I'd create the bucket manually as it seems serverless nextjs is fine with it as long as you have access to the bucket.

Turns out the region where I tried to create the bucket was disabled for some reason.

This pattern could help you verify you can actually create the bucket. The (--debug) output you get is a little bit lacking at times so stuff like this can happen I guess.

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

No branches or pull requests