Skip to content

Instantly share code, notes, and snippets.

@brienna
Created October 9, 2018 01:55
Show Gist options
  • Save brienna/9ed46c5164f71997c1fcfcd0af58fcce to your computer and use it in GitHub Desktop.
Save brienna/9ed46c5164f71997c1fcfcd0af58fcce to your computer and use it in GitHub Desktop.
Create S3 resource and set configs
import boto3, configparser
s3resource = None
def setup():
"""Creates S3 resource & sets configs to enable download."""
print('Connecting to Amazon S3...')
# Securely import configs from private config file
configs = configparser.SafeConfigParser()
configs.read('config.ini')
# Create S3 resource & set configs
global s3resource
s3resource = boto3.resource(
's3', # the AWS resource we want to use
aws_access_key_id=configs['DEFAULT']['ACCESS_KEY'],
aws_secret_access_key=configs['DEFAULT']['SECRET_KEY'],
region_name='us-east-1' # same region arxiv bucket is in
)
if __name__ == '__main__':
"""Runs if script is called on command line"""
# Create S3 resource & set configs
setup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment