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

NoSuchBucket when BucketName doesn't have capital letter...? #86

Open
mikestopcontinues opened this issue Dec 18, 2019 · 5 comments
Open

Comments

@mikestopcontinues
Copy link
Contributor

Hi. I've come across a very weird error. It seems that I can use s3-local just fine with BucketName: dev-apacBucket, but I get 'NoSuchBucket' with dev-apac-bucket. I suspect the error might be with this plugin rather than s3rver because when I access it directly, it seems to correctly read both bucket variants.

Perhaps it's a version issue? Here's what I'm running:

  "dependencies": {
    "aws-sdk": "2.592.0",
    "serverless": "1.60.0",
    "serverless-offline": "5.12.1",
    "serverless-s3-local": "0.5.4",
  }

Any help would be greatly appreciated!

@ar90n
Copy link
Owner

ar90n commented Dec 23, 2019

Hi @mikestopcontinues
Thanks for your report. I tried to reproduce your issue but I couldn't. I tried the following steps.

  1. modify handler.js and serverlss.yml in simple_put example as following
$ git diff handler.js  serverless.yml
diff --git a/example/simple_put/handler.js b/example/simple_put/handler.js
index 9320526..57903d7 100644
--- a/example/simple_put/handler.js
+++ b/example/simple_put/handler.js
@@ -8,7 +8,7 @@ module.exports.webhook = (event, context, callback) => {
     secretAccessKey: 'S3RVER',
   });
   S3.putObject({
-    Bucket: 'local-bucket',
+    Bucket: 'dev-apac-bucket',
     Key: '1234',
     Body: Buffer.from('abcd'),
   }, () => { callback(null, 'ok'); });
diff --git a/example/simple_put/serverless.yml b/example/simple_put/serverless.yml
index 55881ac..e0e64a1 100644
--- a/example/simple_put/serverless.yml
+++ b/example/simple_put/serverless.yml
@@ -30,7 +30,7 @@ resources:
     NewResource:
       Type: AWS::S3::Bucket
       Properties:
-        BucketName: local-bucket
+        BucketName: dev-apac-bucket
 functions:
   webhook:
     handler: handler.webhook
  1. launch serverless offline
$ sls offline start
[ { name: 'dev-apac-bucket', configs: [] } ]
starting handler
warn: the bucket "dev-apac-bucket" already exists
S3 local started ( port:8000, family: IPv4, address: 127.0.0.1 )
Serverless: creating bucket: dev-apac-bucket
Serverless: Starting Offline: dev/us-east-1.

Serverless: Routes for webhook:
Serverless: GET /
Serverless: POST /{apiVersion}/functions/serverless-s3-local-example-dev-webhook/invocations

Serverless: Offline [HTTP] listening on http://localhost:3000
Serverless: Enter "rp" to replay the last request
  1. send a GET request with the curl in another terminal
$ curl localhost:3000

I got the following in serverless terminal

Serverless: GET / (λ: webhook)
info: Stored object "1234" in bucket "dev-apac-bucket" successfully
info: PUT /dev-apac-bucket/1234 200 23ms 0b
  1. run a put-object command with aws cli int anot her terminal
$ aws --endpoint http://localhost:8000 s3api put-object --bucket dev-apac-bucket --key test --body test

$ aws --endpoint http://localhost:8000 s3api put-object --bucket dev-apac-bucket --key test --body test

{
    "ETag": "\"f42338037fa7d90fdb8b91e592287384\""
}

I got the following in serverless terimnal

info: Stored object "test" in bucket "dev-apac-bucket" successfully
info: PUT /dev-apac-bucket/test 200 6ms 0b

I think that it works correctly. If you don't mind, could you share a project which reproduces your issue?

@Panzki
Copy link

Panzki commented Feb 28, 2020

I encountered the same problem and I was able to at least find a workaround. It seems that the AWS S3 client uses virtual hosted style requests if the name of your bucket looks like my-bucket instead of myBucket. Since the requested url will be different s3erver can not resolve the bucket.

To work around this issue, when testing with the local s3, you can set the s3ForcePathStyle option to true when creating you S3 client. See the AWS docs here.

If anyone comes up with a more detailed explanation (or maybe even a fix in s3ver?!), I'd be really interested in the details.

@mikestopcontinues
Copy link
Contributor Author

Thanks, @Panzki. That's a good find.

@ar90n
Copy link
Owner

ar90n commented Mar 6, 2020

@Panzki
Thanks for your great work!

@mikestopcontinues
I'm so sorry. I misunderstood the detail of your issue.

@icysharp
Copy link

icysharp commented Apr 2, 2021

For anyone using AWS SDK V3 (@aws-sdk/client-s3), this option s3ForcePathStyle seems to have been renamed to forcePathStyle

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/bucketendpointresolvedconfig.html#forcepathstyle

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

4 participants