S3 uploader with boto

If you look it up on Google, it will come out a lot. I'll upload the file to AWS with boto.

upload.py


#!/usr/bin/python 
# coding: utf8

import sys
from boto.s3.connection import S3Connection
from boto.s3.key import Key

AWS_ACCESS_KEY	= 'XXXXXXX'
AWS_SECRET_KEY	= 'YYYYYYY'
BUCKET_NAME		= 'mybucket'

conn = S3Connection(
	aws_access_key_id		= AWS_ACCESS_KEY,
	aws_secret_access_key	= AWS_SECRET_KEY)

bucket = conn.get_bucket(BUCKET_NAME)

print "connect:", bucket

if len(sys.argv) == 1:
    print "Error: no input file specified"
    sys.exit()


args = sys.argv
# arg[0]Is the execution script name, so skip it
args.pop(0)

for arg in args:
	upload_file = arg

	key		= Key(bucket)
	key.key	= upload_file
	key.set_contents_from_filename(upload_file)

	#Put into web public mode
	key.make_public()
	print "upload file:", key

Execution is from the root directory you want to upload

$ python path/to/upload.py file1 file2 ...

You can refer to the Manual for file permissions and option control.

In the end, I want to make it a rsync-like synchronization script, but for the time being, I'll draft it.

Recommended Posts

S3 uploader with boto
S3 operation with python boto3
Use boto3 to mess with S3
Generate S3 signed URL with boto
Try server-side encryption on S3 with boto3
[AWS] Link Lambda and S3 with boto3
S3 server-side encryption SSE with Python boto3
Tested with boto3 + mock
[Python] Summary of S3 file operations with boto3
Manipulate S3 objects with Boto3 (high-level API and low-level API)
Issue S3 time-limited URL with boto3 (with file existence confirmation)
[Memo] Load csv of s3 into pandas with boto3
Set connection timeout with boto3
[S3] CRUD with S3 using Python [Python]
Change retry settings with boto3
I wanted to delete multiple objects in s3 with boto3
Analyze S3 CloudTrail Log using Boto
Let's upload S3 files with CLI
Get AWS account ID with boto3
Mount S3 on Ubuntu with goofys
Easy AWS S3 testing with MinIO
Connect to Elastic MQ with boto
Create a file uploader with Django
How to deal with SSL error when connecting to S3 with boto of Python
Use Bucket (). Objects.filter instead of list_objects_v2 when outputting S3 list with Boto3
Copy data from Amazon S3 to Google Cloud Storage with Python (boto)
Comfortable document life with Sphinx + Drone + S3
Download the file from S3 using boto.
Getting started with Dynamo from Python boto
How to catch boto3 S3 NoSuchKey error
Connect to s3 with AWS Lambda Python
Quickly implement S3 compatible storage with python-flask
Use boto to upload / download files to s3.
[AWS] Do SSI-like things with S3 / Lambda