craftship / codebox-npm

Serverless private npm registry using https://serverless.com/

Home Page:http://codebox.sh/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The specified bucket is not valid.

tvb opened this issue · comments

Its seems I cannot run serverless remove --stage prod. I am sure the correct bucket has been exported:

Serverless: Could not remove AWS package storage: The specified bucket is not valid.

  Invalid Bucket Name ------------------------------------

  The specified bucket is not valid.

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.1.4
     Serverless Version:     1.25.0

And same for applying a custom domain name:

$ serverless codebox domain --stage staging  --host mydomainname.com
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: WARNING: Plugin EnvironmentVariablesCheck uses deprecated hook before:deploy:initialize,
                     use package:initialize hook instead
Serverless: Load command webpack
Serverless: Load command webpack:invoke
Serverless: Load command webpack:watch
Serverless: Load command webpack:serve
Serverless: WARNING: Plugin ServerlessWebpack uses deprecated hook before:deploy:createDeploymentArtifacts,
                     use package:createDeploymentArtifacts hook instead
Serverless: WARNING: Plugin ServerlessWebpack uses deprecated hook after:deploy:createDeploymentArtifacts,
                     use package:createDeploymentArtifacts hook instead
Serverless: Load command codebox
Serverless: Load command codebox:domain
Serverless: Load command codebox:encrypt
Serverless: Load command codebox:index

 Serverless Warning --------------------------------------

  A valid environment variable to satisfy the declaration 'env:CODEBOX_RESTRICTED_ORGS' could not be found.


 Serverless Warning --------------------------------------

  A valid environment variable to satisfy the declaration 'env:CODEBOX_INSIGHTS_CLIENT_ID' could not be found.


 Serverless Warning --------------------------------------

  A valid environment variable to satisfy the declaration 'env:CODEBOX_INSIGHTS_SECRET' could not be found.

Serverless: Invoke codebox:domain
Serverless: Domain update failed for mydomainname.com
Serverless: The specified bucket is not valid.

It seems to be the way the bucket is referenced in the codebox-tools. See these lines:

this.bucket = this.serverless.service.resources
.Resources
.PackageStorage
.Properties
.BucketName;

They are returning ${self:provider.environment.bucket} which is what is actually specified in the serverless.yml.

It seems serverless only has these values populated inside the handlers, so each handler should look it up itself, instead of doing it in the constructor. Like so:

  migrate() {
    this.bucket = this.serverless.service.resources
      .Resources
      .PackageStorage
      .Properties
      .BucketName;

Making this change in the migrate function has it working, but I'm now getting Access Denied errors, which are probably on my end.

Access Denied seems to be related to missing Encryption on the S3-Put

I was having exactly the same issue with host migration....

$ serverless codebox domain --stage prod --host npm.mydomain.com
...
Serverless: Domain update failed for npm.mydomain.com
Serverless: The specified bucket is not valid.

A bit of an ugly workaround (OK a very ugly workaround) but... temporarily hard-coding the bucket into serverless.yaml worked for me...

resources:
  Resources:
    PackageStorage:
      Type: AWS::S3::Bucket
      Properties:
        AccessControl: Private
        BucketName: "npm.mydomain.com-prod"
        # ORIGIAL CODE --- BucketName: ${self:provider.environment.bucket}

Any update on this? I set up a custom domain in API gateway, but when I run serverless codebox domain --stage prod --host xxxx I get

Serverless: Domain update failed for xxxx
Serverless: The specified bucket is not valid.

Hard-coding the bucket the BucketName, as @mcroker suggests, yields me

Serverless: Domain update failed for xxxx
Serverless: Access Denied

SLS_DEBUG=* gives me no extra information:

[cut off]
Serverless: Load command webpack:serve
Serverless: WARNING: Plugin ServerlessWebpack uses deprecated hook before:deploy:createDeploymentArtifacts,
                     use package:createDeploymentArtifacts hook instead
Serverless: WARNING: Plugin ServerlessWebpack uses deprecated hook after:deploy:createDeploymentArtifacts,
                     use package:createDeploymentArtifacts hook instead
Serverless: Load command codebox
Serverless: Load command codebox:domain
Serverless: Load command codebox:encrypt
Serverless: Load command codebox:index
Serverless: Invoke codebox:domain
Serverless: Domain update failed for xxxx
Serverless: Access Denied

@thomastoye to fix this issue just add ServerSideEncryption: 'AES256' to the migrate() function in the putObject call.

putPromises.push(
          this.s3.putObject({
            Bucket: this.bucket,
            Key: newItem.key,
            Body: JSON.stringify(json),
            ServerSideEncryption: 'AES256',
          }).promise() )