Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Boto to connect to S3 with Python

I'm trying to access AWS using Boto, and it's not working. I've installed Boto, and the boto.cfg in /etc. Here's my code:

import requests, json
import datetime
import hashlib
import boto

conn = boto.connect_s3()

Here's the error:

Traceback (most recent call last):
  File "boto.py", line 4, in <module>
    import boto
  File "/home/mydir/public_html/boto.py", line 6, in <module>
    conn = boto.connect_s3()
AttributeError: 'module' object has no attribute 'connect_s3'

What the hell? This isn't complicated.

like image 842
Randall Pinkston Avatar asked Dec 13 '12 21:12

Randall Pinkston


People also ask

How do I connect my S3 to Python?

For example, To access “S3” services, define the connection as “boto3. client('s3')”, To access “cloudwatch” services, define the connection as “boto3. client('cloudwatch'), similarly to access “EC2” services, use “boto3. client('ec2')”.

What is S3 Boto?

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers scalability, data availability, security, and performance. This section demonstrates how to use the AWS SDK for Python to access Amazon S3 services.


2 Answers

It looks like the file you're working on is called boto.py. I think what's happening here is that your file is importing itself--Python looks for modules in the directory containing the file doing the import before it looks on your PYTHONPATH. Try changing the name to something else.

like image 71
khagler Avatar answered Sep 25 '22 23:09

khagler


Use the Connection classes.

e.g.

from boto.s3.connection import S3Connection
from boto.sns.connection import SNSConnection
from boto.ses.connection import SESConnection

def connect_s3(self):
  return S3Connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)

def connect_sns(self):
  return SNSConnection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)

def connect_ses(self):
  return SESConnection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)
like image 45
Amit Talmor Avatar answered Sep 23 '22 23:09

Amit Talmor