Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically check if zip_file exceeds 4096 chars #537

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions troposphere/awslambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def validate(self):
raise ValueError(
"You can't specify both 'S3ObjectVersion' and 'ZipFile'"
)
if zip_file and len(zip_file) > 4096:
Copy link
Contributor

@benbridts benbridts Aug 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you think about how this would work if you write this with a Join? I'll give an example below. I think this check is great if zip_file is a string, but we shouldn't assume it is.

ZipFile=Join('', [
    "var x = '", Ref(InputXParam), "';\n",
    "var y = '", Ref(InputYParam), "';\n",
    rest_of_code_var,
])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. In this case there is not way to check it locally as there could be any Ref, or GetAttr etc. So what if we run this check on strings only?

Maybe also on simple cases like Join('', [ ...]) where all elements are strings and we can actually calculate the size. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think running on strings only is a good solution for this problem. I like the iteration over the join to see if they are strings too.

raise ValueError(
"ZipFile length cannot exceed 4096 characters. For larger source use S3Bucket/S3Key properties instead. Current length: %d" % len(zip_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI build fails on this line because it's to long.

)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI Build fails on this line because there is trailing whitespace

if not zip_file and not (s3_bucket and s3_key):
raise ValueError(
"You must specify a bucket location (both the 'S3Bucket' and "
Expand Down