Commit 054af246 authored by Christian Salzmann-Jaeckel's avatar Christian Salzmann-Jaeckel
Browse files

add s3-public-download.py

parent 25623a09
#!/usr/bin/python3
import os
import logging
import boto3
radosgw_access_key = os.environ['AWS_ACCESS_KEY_ID']
radosgw_secret_key = os.environ['AWS_SECRET_ACCESS_KEY']
radosgw_endpoint_url = 'https://rise-s3.zib.de'
radosgw_bucket_name = 'k8s-doc-bucket'
radosgw_key_name = 'Using_Kubernetes_Secrets.pdf'
radosgw_file_name = 'talk.pdf'
# generate s3 client
s3_client = boto3.client('s3',
endpoint_url=radosgw_endpoint_url,
aws_access_key_id=radosgw_access_key,
aws_secret_access_key=radosgw_secret_key
)
################################################################################
# check if bucket exists
bucket_exists = False
# Retrieve the list of existing buckets
response = s3_client.list_buckets()
for bucket in response['Buckets']:
bucket_name = bucket["Name"]
if (bucket_name == radosgw_bucket_name):
bucket_exists = True
# create bucket if not found
if bucket_exists == False:
print(f"creating bucket '{radosgw_bucket_name}' …")
response = s3_client.create_bucket(Bucket=radosgw_bucket_name, ACL='public-read')
# upload file
response = s3_client.upload_file(
radosgw_file_name, radosgw_bucket_name, radosgw_key_name,
ExtraArgs={'ACL': 'public-read'}
)
print(f"uploaded file to '{radosgw_endpoint_url}/{radosgw_bucket_name}/{radosgw_key_name}'.")
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment