serverless-s3-local
serverless-s3-local copied to clipboard
NoSuchBucket when BucketName doesn't have capital letter...?
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!
Hi @mikestopcontinues Thanks for your report. I tried to reproduce your issue but I couldn't. I tried the following steps.
- 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
- 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
- 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
- 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?
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.
Thanks, @Panzki. That's a good find.
@Panzki Thanks for your great work!
@mikestopcontinues I'm so sorry. I misunderstood the detail of your issue.
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