S3 operation with python boto3

Installation

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

Get bucket list

import boto3

s3 = boto3.resource('s3')

for bucket in s3.buckets.all():
    print(bucket.name)

upload

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

S3 operation with python boto3
S3 uploader with boto
S3 server-side encryption SSE with Python boto3
[Python] Summary of S3 file operations with boto3
[S3] CRUD with S3 using Python [Python]
[Automation with python! ] Part 2: File operation
Use boto3 to mess with S3
Generate S3 signed URL with boto
FizzBuzz with Python3
Scraping with Python
Statistics with python
[python] vector operation
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
Python OS operation
Try server-side encryption on S3 with boto3
python starts with ()
with syntax (Python)
Getting started with Dynamo from Python boto
[AWS] Link Lambda and S3 with boto3
Bingo with python
[Python] Matrix operation
Zundokokiyoshi with python
Connect to s3 with AWS Lambda Python
Excel with Python
Microcomputer with Python
Cast with python
How to deal with SSL error when connecting to S3 with boto of Python
Copy data from Amazon S3 to Google Cloud Storage with Python (boto)
Automatic operation of Chrome with Python + Selenium + pandas
Manage AWS nicely with the Python library Boto
Export RDS snapshot to S3 with Lambda (Python)
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
[Python] Operation of enumerate
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
[Python] 2's complement conversion
1.1 Getting Started with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python