15
15
import botocore
16
16
import pip
17
17
import yaml
18
+ import md5
18
19
19
20
from .helpers import archive
20
21
from .helpers import mkdir
@@ -457,15 +458,20 @@ def upload_s3(cfg, path_to_zip_file):
457
458
"""Upload a function to AWS S3."""
458
459
459
460
print ('Uploading your new Lambda function' )
460
- byte_stream = read (path_to_zip_file , binary_file = True )
461
461
aws_access_key_id = cfg .get ('aws_access_key_id' )
462
462
aws_secret_access_key = cfg .get ('aws_secret_access_key' )
463
-
464
463
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
-
467
464
client = get_client ('s3' , aws_access_key_id , aws_secret_access_key ,
468
465
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 )
469
475
470
476
# Do we prefer development variable over config?
471
477
buck_name = (
@@ -476,7 +482,7 @@ def upload_s3(cfg, path_to_zip_file):
476
482
)
477
483
kwargs = {
478
484
'Bucket' : '{}' .format (buck_name ),
479
- 'Key' : cfg . get ( 's3_key' , '{}.zip ' .format (func_name ) ),
485
+ 'Key' : '{} ' .format (filename ),
480
486
'Body' : byte_stream
481
487
}
482
488
0 commit comments