Last active
August 6, 2020 12:41
-
-
Save snehamehrin/58467956ecfb0b980bb194adc50868bb to your computer and use it in GitHub Desktop.
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
def mount_s3_bucket(access_key, secret_key, bucket_name, mount_folder): | |
ACCESS_KEY_ID = access_key | |
SECRET_ACCESS_KEY = secret_key | |
ENCODED_SECRET_KEY = SECRET_ACCESS_KEY.replace("/", "%2F") | |
print ("Mounting", bucket_name) | |
try: | |
# Unmount the data in case it was already mounted. | |
dbutils.fs.unmount("/mnt/%s" % mount_folder) | |
except: | |
# If it fails to unmount it most likely wasn't mounted in the first place | |
print ("Directory not unmounted: ", mount_folder) | |
finally: | |
# Lastly, mount our bucket. | |
dbutils.fs.mount("s3a://%s:%s@%s" % (ACCESS_KEY_ID, ENCODED_SECRET_KEY, bucket_name), "/mnt/%s" % mount_folder) | |
#dbutils.fs.mount("s3a://"+ ACCESS_KEY_ID + ":" + ENCODED_SECRET_KEY + "@" + bucket_name, mount_folder) | |
print ("The bucket", bucket_name, "was mounted to", mount_folder, "\n") | |
# Set AWS programmatic access credentials | |
ACCESS_KEY = "" | |
SECRET_ACCESS_KEY = "" | |
mount_s3_bucket(ACCESS_KEY, SECRET_ACCESS_KEY, "stack-overflow-bucket", "/stack-overflow-bucket") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment