rackerlabs / lambda-uploader

Helps package and upload Python lambda functions to AWS
Apache License 2.0
272 stars 56 forks source link

Unexpected error + traceback #128

Open gamename opened 7 years ago

gamename commented 7 years ago

Hi,

I just upgraded and am having problems with a lambda.json file that previously worked. Can you tell me what I'm doing wrong?

Here is my version

$ lambda-uploader --version
1.1.0

I'm getting this error:

lambda-uploader --publish ./ngd
⁉️ Unexpected error. Please report this traceback.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lambda_uploader/shell.py", line 182, in main
    _execute(args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lambda_uploader/shell.py", line 51, in _execute
    variables=args.variables)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lambda_uploader/config.py", line 40, in __init__
    self._load_config(config_file)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lambda_uploader/config.py", line 144, in _load_config
    raise Exception("%s not a valid configuration file" % lambda_file)
Exception: lambda.json not a valid configuration file
make: *** [build] Error 1

This is the content of my lambda.json file (with account redacted):

{
  "name": "ngd",
  "description": "Main Function. Calls all other lambdas",
  "region": "us-east-1",
  "handler": "ngd.handler",
  "role": "arn:aws:iam::1234567890:role/audit_role",
  "requirements": [],
  "ignore": [
    "/.*\\.pyc$"
  ],
  "timeout": 30,
  "memory": 512
}
jarosser06 commented 7 years ago

So this is looking for the lambda.json in the CWD so when you are specifying your function path ./ngd but not your config the lambda-uploader is looking in the current working directory and not the ./ngd directory. If you run the command from the function directory or specify the config path it should work.

We usually treat our Python code as a package and put the lambda.json in the root of the project repo.

I am hesitant to change the functionality in this since people may be using it this way. Perhaps searching for the config in both the package directory and then the CWD would make more sense. @martinb3 Any thoughts on that?

gamename commented 7 years ago

@jarosser06 Thanks for the quick reply. Much appreciated.

Yeah, I figured out that I have to pass an explicit path to the json file. Its an added hassle to pass the lambda.json file location, but its manageable.

My Makefile was working like this:

build:
    lambda-uploader --publish ./ngd 

Now it requires:

build:
    lambda-uploader --publish ./ngd \
                    --config ./ngd/lambda.json

Again, that's a bit messier, but I can live with it as long as it works.

brandond commented 7 years ago

FWIW, I would +1 on having it look for lambda.json in the same location as the code being published. If I point it at a folder, I expect it to look there for both code AND configuration. Doesn't make any sense to me that I have to explicitly tell it to look in the same folder for both - especially for simple projects that are just lambda.json and function.py.

jarosser06 commented 7 years ago

The reason we did that was because we have a number of large projects where the code is in a specific directory and the config is elsewhere. For smaller projects I agree it probably would make sense to look in the directory passed. To make it backwards compatible I think I'm just going to have it look first in the code directory and then in the CWD.