1515import botocore
1616import pip
1717import yaml
18+ import md5
1819
1920from .helpers import archive
2021from .helpers import mkdir
@@ -457,15 +458,20 @@ def upload_s3(cfg, path_to_zip_file):
457458 """Upload a function to AWS S3."""
458459
459460 print ('Uploading your new Lambda function' )
460- byte_stream = read (path_to_zip_file , binary_file = True )
461461 aws_access_key_id = cfg .get ('aws_access_key_id' )
462462 aws_secret_access_key = cfg .get ('aws_secret_access_key' )
463-
464463 account_id = get_account_id (aws_access_key_id , aws_secret_access_key )
465- role = get_role_name (account_id , cfg .get ('role' , 'lambda_basic_execution' ))
466-
467464 client = get_client ('s3' , aws_access_key_id , aws_secret_access_key ,
468465 cfg .get ('region' ))
466+ role = get_role_name (account_id , cfg .get ('role' , 'basic_s3_upload' ))
467+ byte_stream = b''
468+ with open (path_to_zip_file , mode = 'rb' ) as fh :
469+ byte_stream = fh .read ()
470+ s3_key_prefix = cfg .get ('s3_key_prefix' , '/dist' )
471+ checksum = md5 .new (byte_stream ).hexdigest ()
472+ timestamp = str (time .time ())
473+ filename = '{prefix}{checksum}-{ts}.zip' .format (prefix = s3_key_prefix , checksum = checksum , ts = timestamp )
474+ print (filename )
469475
470476 # Do we prefer development variable over config?
471477 buck_name = (
@@ -476,7 +482,7 @@ def upload_s3(cfg, path_to_zip_file):
476482 )
477483 kwargs = {
478484 'Bucket' : '{}' .format (buck_name ),
479- 'Key' : cfg . get ( 's3_key' , '{}.zip ' .format (func_name ) ),
485+ 'Key' : '{} ' .format (filename ),
480486 'Body' : byte_stream
481487 }
482488
0 commit comments