Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created September 7, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjurney/034843ca36e01c00d56cdecd2f77a1d1 to your computer and use it in GitHub Desktop.
Save rjurney/034843ca36e01c00d56cdecd2f77a1d1 to your computer and use it in GitHub Desktop.
How to securely or insecurely get your code from Amazon S3 in Colab
#!/bin/bash
# Copy files to S3
aws s3 cp myfile.py s3://mybucket/
aws s3 cp config.py s3://mybucket/
import boto3
import getpass
#
# Note: you can use passlib to get these securely without putting them in the notebook:
#
os.environ['AWS_ACCESS_KEY_ID'] = getpass.getpass(prompt='AWS_ACCESS_KEY_ID: ', stream=None)
os.environ['AWS_SECRET_ACCESS_KEY'] = getpass.getpass(prompt='AWS_SECRET_ACCESS_KEY: ', stream=None)
# Otherwise you can encode them yourself
os.environ['AWS_ACCESS_KEY_ID'] = 'MY_AWS_ACCESS_KEY_ID'
os.environ['AWS_SECRET_ACCESS_KEY'] = 'MY_AWS_SECRET_ACCESS_KEY'
s3 = boto3.client('s3')
s3.download_file('mybucket', 'myfile.py', 'myfile.py')
s3.download_file('mybucket', 'config.py', 'config.py')
# Import our configuration
from config import PARAMETERS
# Import our utilities that we downloaded
import myfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment