Kotaimen / awscfncli

Friendly AWS CloudFormation CLI
MIT License
59 stars 12 forks source link

Permission denied on Windows when template > TEMPLATE_BODY_SIZE_LIMIT #93

Closed alytle closed 4 years ago

alytle commented 4 years ago

When a template file size is greater than TEMPLATE_BODY_SIZE_LIMIT on Windows, we see this error:

Successfully packaged artifacts and uploaded to s3://awscfncli-853215655166-us-east-1.
Template body is too large, uploading as artifact.
Template uploaded to s3://awscfncli-<account>-us-east-1/stack/<guid>.template.json
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\USER~1\\AppData\\Local\\Temp\\1\\tmpldldvc8h'

The problem is here:

https://github.com/Kotaimen/awscfncli/blob/42297e66e91ef7f9d204115f0d3c44cd3ee75dad/awscfncli2/runner/runbook/package.py#L112-L130

Referring to a NamedTemporaryFile by name after instantiation is not cross platform, and fails on Windows. From http://docs.python.org/library/tempfile.html#tempfile.NamedTemporaryFile:

Whether the name can be used to open the file a second time, while
the named temporary file is still open, varies across platforms (it can
be so used on Unix; it cannot on Windows NT or later)

See https://github.com/bravoserver/bravo/issues/111 for another example of this issue.

See also https://github.com/bravoserver/bravo/issues/111#issuecomment-826990 for a suggestion on a Windows alternative.

Another suggestion (from https://github.com/deepchem/deepchem/issues/707#issuecomment-556002823) is to stop using NamedTemporaryFile entirely:

Consider using os.path.join(tempfile.gettempdir(), os.urandom(24).hex()) instead. It's reliable, cross-platform, and the only caveat is that it doesn't work on FAT partitions.

Kotaimen commented 4 years ago

Hi @GlieseRay:

Do you still have that Surface laptop to reproduce this? It may be a bit late but considering adding a test? (and figure out how to run windows tests on CodeBuild)

Kotaimen

GlieseRay commented 4 years ago

@Kotaimen Sure, will take look

GlieseRay commented 4 years ago

Tested on local windows machine. Seems OK now. Close this ticket.