Install boto3 with pip or something. Install using conda.
$ conda install -c anaconda boto3=1.3.1
Register your credential information and default region using aws cli
$ aws configure
aws_access_key_id = ACCESS_KEY_ID
aws_secret_access_key = SECRET_ACCESS_KEY
region = ap-northeast-1
output = json
In addition, it is ok even if you add it directly to the file as shown below
$ vim ~/.aws/credentials
[default]
aws_access_key_id = ACCESS_KEY_ID
aws_secret_access_key = SECRET_ACCESS_KEY
$ vim ~/.aws/config:
[default]
region = ap-norteast-1
output = json
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
import boto3
s3 = boto3.resource('s3')
data = open('test.jpg', 'rb')
s3.Bucket('my-bucket').put_object(Key='test.jpg', Body=data)
Below, reference http://boto3.readthedocs.io/en/latest/index.html
Recommended Posts