Aws-cli: Invalid Syntax Error when running any AWS command.

Created on 20 Sep 2017  ·  9Comments  ·  Source: aws/aws-cli

After installing with awscli with pip and running aws --version, or any other aws command, I receive this error:

/Users//anaconda/lib/python3.6/site-packages/aws/main.py", line 23
print '%(name)s: %(endpoint)s' % {
^
SyntaxError: invalid syntax

The entire function from that error is as follows:

def list_regions(service):
"""
List regions for the service
"""
for region in service.regions():
print '%(name)s: %(endpoint)s' % {
'name': region.name,
'endpoint': region.endpoint,
}

I am using an anaconda environment, with python 2.7. However it appears main.py is running under python 3.6 from the error. I also tried installing and running in my regular environment with 3.6 and had the same error as well.

Most helpful comment

Leaving this here in case someone comes across this via google like me:

I had the same issue with the same environment (anaconda environment with python 3.6). This is actually a different package, confusingly named "aws" which is throwing the error: https://github.com/eofs/aws

Make sure you run pip install awscli, NOT pip install aws. You may want to confirm which "aws" package you are calling via which aws.

All 9 comments

I don't see this list_regions function in the codebase. This seems to be custom code of some sort.

If you're hitting python 3, print needs to have parens. Some details can be found in this SO answer.

This appears to be an issue with something other than this code base. The importable name for this tool is awscli not aws

Leaving this here in case someone comes across this via google like me:

I had the same issue with the same environment (anaconda environment with python 3.6). This is actually a different package, confusingly named "aws" which is throwing the error: https://github.com/eofs/aws

Make sure you run pip install awscli, NOT pip install aws. You may want to confirm which "aws" package you are calling via which aws.

Remove the aws package with pip uninstall aws. Then install awscli, pip install awscli.

eze1981, that worked. Thanks pal :)

I installed AWSCLI using pip install awscli command but still got this error. It got resolved after upgrading the aws with the command pip install --upgrade awscli

I had to do a --force-reinstall after forgetting that I already had awscli installed, installing aws and then uninstalling aws. This removed the aws binary, hence the need for the --force-reinstall

In my case, I tried all the options highlighted and it still resulted in the same error until I did the following:

  1. Find the aws binary installed which aws and rm the file.
  2. Follow steps from @HUU and @eze1981

@HUU Thanks dude, you saved my day 👍

Was this page helpful?
0 / 5 - 0 ratings