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

Boto3 can't connect to S3 but has no problems with other services #604

Closed
zachschultz opened this issue Feb 8, 2018 · 3 comments
Closed
Labels
area: configuration Configuring LocalStack type: bug Bug report

Comments

@zachschultz
Copy link

I am running localstack through docker and have enabled SQS and S3 for this test. Additionally, I am invoking my Lambda through AWS SAM local, in a docker container. The following Python code to access localstack SQS through Boto3 works perfectly:

import boto3
sqs = boto3.client('sqs',
                      endpoint_url="http://docker.for.mac.localhost:4576",
                      use_ssl=False,
                      aws_access_key_id=ACCESS_KEY,
                      aws_secret_access_key=SECRET_KEY) 
print sqs.list_queues()

However, when I try to use S3 instead, like so:

s3 = boto3.client('s3',
                  endpoint_url="http://docker.for.mac.localhost:4572",
                  use_ssl=False,
                  aws_access_key_id=ACCESS_KEY,
                  aws_secret_access_key=SECRET_KEY,
                  region_name='us-east-1')
print s3.list_buckets()

I get the error: An error occurred (NoSuchBucket) when calling the ListBuckets operation: The specified bucket does not exist: NoSuchBucket. I've made sure that the ports are correct and that through the normal aws local CLI I can manage S3 in localstack, so I have absolutely no idea as to what would be causing this. If anyone knowledgeable with AWS SAM/localstack S3/boto3 could give me some insight I would greatly appreciate it.

@whummer
Copy link
Member

whummer commented Feb 12, 2018

Thanks for reporting @zachschultz . My assumption would be that this is related to the difference between domain-style addressing and path-style addressing in S3. See also the note in the Troubleshooting section of the README.

Can you try changing the configuration to use path-style addressing: http://boto3.readthedocs.io/en/latest/guide/s3.html#changing-the-addressing-style

Hope that helps.

@whummer whummer added type: bug Bug report area: configuration Configuring LocalStack labels Feb 12, 2018
@phrohdoh
Copy link

Hey @zachschultz, are you sure that there is a bucket in your localstack's S3 instance?

I ask because I had this same issue before I created any buckets.

Here are the steps I took:

$ aws configure set default.s3.addressing_style path

$ aws --endpoint-url=http://localhost:4572 s3api create-bucket --bucket mybucket --region us-west-1

$ aws --endpoint-url=http://localhost:4572 s3api put-object --bucket mybucket --key foobar123 --body bin/myscript.bash

Resources:

aws configure
aws s3api create-bucket
aws s3api put-object

@zachschultz
Copy link
Author

@whummer and @phrohdoh thank you both! That did it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: configuration Configuring LocalStack type: bug Bug report
Projects
None yet
Development

No branches or pull requests

3 participants