Skip to content

Commit

Permalink
Merge pull request #6 from becksteadn/build
Browse files Browse the repository at this point in the history
use bucket object to upload to s3
  • Loading branch information
scriptingislife authored Apr 7, 2019
2 parents 55aa5ab + 0a2809a commit 400ec7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ def lambda_handler(event, context):
url = 'http://' + url
check_connection(url)

STAR_LEN = 40
BUCKET_NAME = os.environ.get('GLIMPSE_BUCKET_NAME')
SCREENSHOT_DIR = os.environ.get('GLIMPSE_SCREENSHOT_DIR')
DB_TABLE = os.environ.get('GLIMPSE_DB_TABLE')
pp = pprint.PrettyPrinter(indent=4)

print('[!] Getting Environment Variables')
print(f'Using S3 bucket "{BUCKET_NAME}"')
print(f' with path "{SCREENSHOT_DIR}""')
print(f'Using DynamoDB table "{DB_TABLE}""')
print(f' with path "{SCREENSHOT_DIR}"')
print(f'Using DynamoDB table "{DB_TABLE}"')

now = datetime.now()
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
Expand All @@ -76,7 +75,6 @@ def lambda_handler(event, context):

# Don't update if update==false or the parameter doesn't exist
if 'update' not in event.keys() or str(event['update']).lower() != 'true':
# Don't force an update
if exists:
print('[!] Existing Data')
pp.pprint(return_data)
Expand All @@ -85,11 +83,11 @@ def lambda_handler(event, context):

glimpse = gd.GlimpseDriver()
try:
print('[!] Rendering Page')
glimpse.driver.get(url)
glimpse.screenshot(local_path)

s3 = S3(BUCKET_NAME)
#s3_key = s3.get_key(remote_path)
s3.upload_file(local_path, remote_path)

db_data['effectiveurl'] = glimpse.driver.current_url
Expand Down
5 changes: 4 additions & 1 deletion src/s3_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ class S3:
def __init__(self, bucket):
self.bucket_name = bucket
self.resource = boto3.resource('s3')
self.bucket = self.resource.Bucket(bucket)

def get_key(self, remote_path):
return self.resource.Object(bucket_name=self.bucket_name, key=remote_path)

def upload_file(self, local_path, remote_path):
self.resource.meta.client.upload_file(local_path,self.bucket_name, remote_path)
print(f'[!] Uploading {local_path} to s3://{self.bucket_name}/{remote_path}')
return self.bucket.upload_file(local_path, remote_path)
#return self.resource.meta.client.upload_file(local_path,self.bucket_name, remote_path)

0 comments on commit 400ec7c

Please sign in to comment.