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

Permission denied on Windows when template > TEMPLATE_BODY_SIZE_LIMIT #93

Closed
alytle opened this issue Jul 7, 2020 · 3 comments
Closed

Comments

@alytle
Copy link

alytle commented Jul 7, 2020

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:

with tempfile.NamedTemporaryFile(mode='wb') as fp:
# write template body to local temp file
fp.write(template_data)
fp.flush()
# upload to s3
template_location = s3_uploader.upload_with_dedup(
fp.name,
extension='template.json')
ppt.secho('Template uploaded to %s' % template_location)
# get s3 object key ...upload_with_dedup() returns s3://bucket/key
template_key = template_location.replace('s3://%s/' % bucket_name, '')
# generate a pre-signed url for CloudFormation as the object in S3
# is private by default
template_url = s3_client.generate_presigned_url(
ClientMethod='get_object',
Params={'Bucket': bucket_name, 'Key': template_key},
ExpiresIn=3600
)

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 bravoserver/bravo#111 for another example of this issue.

See also bravoserver/bravo#111 (comment) for a suggestion on a Windows alternative.

Another suggestion (from deepchem/deepchem#707 (comment)) 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
Copy link
Owner

Kotaimen commented Jul 8, 2020

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
Copy link
Collaborator

@Kotaimen Sure, will take look

@GlieseRay
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants