I want to use localstack with ruby aws-sdk
. It seems the aws sdk miss some configuration or has a bug, it raises error:
After a
Aws::S3::Resource.new.bucket('mybucket').exists?
it raises a:
/usr/local/lib/ruby/2.2.0/net/http.rb:879:in `initialize': unable to connect to
`mybucket.localstack`; SocketError: getaddrinfo: Name or service not known
(Seahorse::Client::NetworkingError)
On the same container, if I use awscli
no problem at all:
root@35afc611394b:/app/user# aws --endpoint-url=http://localstack:4572 s3 mb s3://test1
make_bucket: test1
root@35afc611394b:/app/user# aws --endpoint-url=http://localstack:4572 s3 ls
2006-02-03 16:45:09 test1
I created a docker-compose.yml to help following the problem:
https://github.com/ook/localstack-s3-problem
I noticed in the readme what I tried for now.
Please advice :)
Thanks for providing the detailed repo to reproduce your issue.
I was able to resolve this by forcing Aws configuration to
force_path_style
(based off of this).TLDR:
So the config ended up looking like this:
The next problem was due to the fact that the bucket didn't exist yet (at least on my machine). So, I had to run this command once
Aws::S3::Resource.new.create_bucket(bucket: 'mybucket')
After that your script worked as expected: