Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Library not working when included with AWS Layers #49

Closed
himanshu219 opened this issue Aug 27, 2019 · 2 comments · Fixed by #52
Closed

Library not working when included with AWS Layers #49

himanshu219 opened this issue Aug 27, 2019 · 2 comments · Fixed by #52

Comments

@himanshu219
Copy link

himanshu219 commented Aug 27, 2019

Reproduction Steps

1> Create a Lambda Function(https://docs.aws.amazon.com/lambda/latest/dg/getting-started-create-function.html)
2> Create a layer and associate it with your lambda created in Step 1(https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html). The purpose of layers is to have a shared library across multiple AWS Lambda functions. So here I am putting the future-fstrings library as a part of my zip file which is uploaded as AWS layer.

When I run the function I get the following error
[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'main': unknown encoding for '/var/task/main.py': future_fstrings Traceback (most recent call last): File "None" Line None None

Assuming main.py contains my lambda function code
If I include the future_strings in same folder as my code then it works.
AWS Lambda puts the shared libraries in /opt/ folder and I am dynamically adding opt directory to sys path sys.path.insert(0, '/opt') Doing this way it throws error.

I do not know the internals how the library converts and when does the conversion code triggers but my hunch is I am doing something wrong here.

@asottile
Copy link
Member

you're going to have to provide a reproduction, I have no idea what "AWS Layers" is

@asottile
Copy link
Member

asottile commented Sep 6, 2019

ah, since lambda doesn't work with site packages, you'll need to manually initialize future-fstrings in a wrapper script

you can do so via import future_fstrings; future_fstrings.register() -- I'll add something to the README

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

Successfully merging a pull request may close this issue.

2 participants