@@ -194,7 +194,8 @@ def _head_object(s3_conn, bucket, key):
194
194
raise
195
195
196
196
197
- def _upload_code (s3_conn , bucket , prefix , name , contents , content_hash ):
197
+ def _upload_code (s3_conn , bucket , prefix , name , contents , content_hash ,
198
+ payload_acl ):
198
199
"""Upload a ZIP file to S3 for use by Lambda.
199
200
200
201
The key used for the upload will be unique based on the checksum of the
@@ -210,6 +211,8 @@ def _upload_code(s3_conn, bucket, prefix, name, contents, content_hash):
210
211
construct a key name for the uploaded file.
211
212
contents (str): byte string with the content of the file upload.
212
213
content_hash (str): md5 hash of the contents to be uploaded.
214
+ payload_acl (str): The canned S3 object ACL to be applied to the
215
+ uploaded payload
213
216
214
217
Returns:
215
218
troposphere.awslambda.Code: CloudFormation Lambda Code object,
@@ -229,7 +232,7 @@ def _upload_code(s3_conn, bucket, prefix, name, contents, content_hash):
229
232
logger .info ('lambda: uploading object %s' , key )
230
233
s3_conn .put_object (Bucket = bucket , Key = key , Body = contents ,
231
234
ContentType = 'application/zip' ,
232
- ACL = 'authenticated-read' )
235
+ ACL = payload_acl )
233
236
234
237
return Code (S3Bucket = bucket , S3Key = key )
235
238
@@ -269,7 +272,8 @@ def _check_pattern_list(patterns, key, default=None):
269
272
'list of strings' .format (key ))
270
273
271
274
272
- def _upload_function (s3_conn , bucket , prefix , name , options , follow_symlinks ):
275
+ def _upload_function (s3_conn , bucket , prefix , name , options , follow_symlinks ,
276
+ payload_acl ):
273
277
"""Builds a Lambda payload from user configuration and uploads it to S3.
274
278
275
279
Args:
@@ -292,6 +296,8 @@ def _upload_function(s3_conn, bucket, prefix, name, options, follow_symlinks):
292
296
file patterns to exclude from the payload (optional).
293
297
follow_symlinks (bool): If true, symlinks will be included in the
294
298
resulting zip file
299
+ payload_acl (str): The canned S3 object ACL to be applied to the
300
+ uploaded payload
295
301
296
302
Returns:
297
303
troposphere.awslambda.Code: CloudFormation AWS Lambda Code object,
@@ -326,7 +332,7 @@ def _upload_function(s3_conn, bucket, prefix, name, options, follow_symlinks):
326
332
follow_symlinks )
327
333
328
334
return _upload_code (s3_conn , bucket , prefix , name , zip_contents ,
329
- content_hash )
335
+ content_hash , payload_acl )
330
336
331
337
332
338
def select_bucket_region (custom_bucket , hook_region , stacker_bucket_region ,
@@ -385,6 +391,8 @@ def upload_lambda_functions(context, provider, **kwargs):
385
391
zip name.
386
392
follow_symlinks (bool, optional): Will determine if symlinks should
387
393
be followed and included with the zip artifact. Default: False
394
+ payload_acl (str, optional): The canned S3 object ACL to be applied to
395
+ the uploaded payload. Default: private
388
396
functions (dict):
389
397
Configurations of desired payloads to build. Keys correspond to
390
398
function names, used to derive key names for the payload. Each
@@ -438,6 +446,7 @@ def upload_lambda_functions(context, provider, **kwargs):
438
446
bucket: custom-bucket
439
447
follow_symlinks: true
440
448
prefix: cloudformation-custom-resources/
449
+ payload_acl: authenticated-read
441
450
functions:
442
451
MyFunction:
443
452
path: ./lambda_functions
@@ -494,6 +503,10 @@ def create_template(self):
494
503
if not isinstance (follow_symlinks , bool ):
495
504
raise ValueError ('follow_symlinks option must be a boolean' )
496
505
506
+ # Check for S3 object acl. Valid values from:
507
+ # https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
508
+ payload_acl = kwargs .get ('payload_acl' , 'private' )
509
+
497
510
# Always use the global client for s3
498
511
session = get_session (bucket_region )
499
512
s3_client = session .client ('s3' )
@@ -505,6 +518,6 @@ def create_template(self):
505
518
results = {}
506
519
for name , options in kwargs ['functions' ].items ():
507
520
results [name ] = _upload_function (s3_client , bucket_name , prefix , name ,
508
- options , follow_symlinks )
521
+ options , follow_symlinks , payload_acl )
509
522
510
523
return results
0 commit comments