Boto3: [Question] - SyntaxError when using s3 client on aws-sam-local and Python3.7

Created on 16 Aug 2017  路  3Comments  路  Source: boto/boto3

_Original issue was created on https://github.com/awslabs/aws-sam-local/issues/59_

_Apologies in advance if this is not the right place to open this issue, I don't have an extensive experience with aws-sam-local or Python, so I may be missing something really stupid._

I am building a Python logic to run on AWS Lambda and chose aws-sam-local as framework.

I came up with a simple Python test file which works fine when executed with python2.7:

pip install boto3 -t .
python -c 'from test import test1; test1(None,None)'

However, when trying to use python3.6 as Runtime (as originally mentioned in template.yaml), I get a SyntaxError: invalid syntax on line client = boto3.client('s3'); the full history is on https://gist.github.com/maoo/2175a1c4b75a80c7271943591afb4920#file-error-log

Steps to reproduce the issue:

  1. install npm
  2. npm install -g aws-sam-local
  3. Download test.py and template.yaml locally, same folder
  4. echo '{}' | sam local invoke Test

Switching the Runtime to python2.7 fixes the issue; anyone else having the same problem? Any idea what the cause could be?

TIA

Most helpful comment

So this happens with the serverless framework too, if I use s3 = boto3.resource('s3') or s3 = boto3.client('s3') in my progrram and build with serverless env as python 3.6 , this pops up.

All 3 comments

Not sure why this would fail, but a SyntaxError is surely not related to boto3. For your sanity, I validated that your sample code is syntactically correct for both 2.7 and 3.6. The issue is in "/var/task/concurrent/futures/_base.py" which I'm going to assume is some kind of issue with the image being used to run the lambda function. That is, the environment is misconfigured.

So this happens with the serverless framework too, if I use s3 = boto3.resource('s3') or s3 = boto3.client('s3') in my progrram and build with serverless env as python 3.6 , this pops up.

I know this is an old thread, but in case anyone else finds this useful - I was having a similar issue when trying to use the AWS Toolkit Codelens functionality to debug a python lambda function locally for my SAM app. In the end it turned out that it didn't like that there was a dash in the file name that the handler was in, once I replaced the dash in the name with an underscore (remember to also change it in your template.yaml) I no longer got back the syntax error.

I found it really useful to go to the folder created by the Debug Locally functionality and look at the __vsctk__debug.py file in a text editor to find out what was the problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arnonki picture arnonki  路  3Comments

rabinnh picture rabinnh  路  3Comments

lewisd32 picture lewisd32  路  3Comments

yannbriancon picture yannbriancon  路  3Comments

jparismorgan picture jparismorgan  路  3Comments