Created
January 3, 2022 01:32
-
-
Save dheerajinampudi/0fbad09163bea651171d98e8562cc0a4 to your computer and use it in GitHub Desktop.
upload all files and folders of build folder to s3 for static website hosting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import os | |
key_id = '' | |
secret_key = '' | |
region = '' | |
bucket_name = '' | |
def upload_files(path,bucket_name): | |
session = boto3.Session( | |
aws_access_key_id=key_id, | |
aws_secret_access_key=secret_key, | |
region_name=region | |
) | |
s3 = session.resource('s3') | |
bucket = s3.Bucket(bucket_name) | |
for subdir, dirs, files in os.walk(path): | |
for file in files: | |
full_path = os.path.join(subdir, file) | |
with open(full_path, 'rb') as data: | |
bucket.put_object(Key=full_path[len(path)+1:], Body=data) | |
print(f'{full_path} uploaded successfully') | |
## Upload folder | |
upload_files('build',bucket_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment