aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
749 stars 216 forks source link

Cannot "Update Function Code" with pip 19.3 #1283

Closed gamename closed 4 years ago

gamename commented 4 years ago

Describe the bug

There is a known-to-be-good lambda function already installed on AWS. When I try to update the function code, I get the following error:

/usr/local/bin/sam build --template /Users/tennis.smith/PycharmProjects/marsh_and_mclennan/.aws-sam/build/template.yaml --build-dir /Users/tennis.smith/PycharmProjects/marsh_and_mclennan/.aws-sam/build Function
Building resource 'Function'
Running PythonPipBuilder:ResolveDependencies

Build Failed
Error: PythonPipBuilder:ResolveDependencies - Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'module' object is not callable

Even if I comment out the entire file except the function handler, I get the same error.

To reproduce Right-click on the function name in the "Lambda" area on the "AWS Explorer" Choose "Update Function Code"

Expected behavior It should have updated my lambda function

Screenshots

Your Environment

Additional context

hunterwerlla commented 4 years ago

Did you happen to install pip 19.3? See this SAM issue: https://github.com/awslabs/aws-sam-cli/issues/1461

gamename commented 4 years ago

@hunterwerlla

Yes. That's it. I have pip 19.3 installed. I'll try lowering the pip version

gamename commented 4 years ago

@hunterwerlla That didn't work :( I downgraded my pip to 19.2.3 and get the same error

image

gamename commented 4 years ago

@hunterwerlla

I'm getting the same error when I try to create a function as well.

I created a "foo" project containing 3 files.

The file names are: foo.py template.yaml requirements.txt

The contents:

python code file "foo.py":

import boto3

def handler(event, context):
    print("Event:" + str(event))
    instance_id = event["ResourceProperties"]["Parameters"]["InstanceId"]
    ec2 = boto3.resource('ec2')
    instance = ec2.Instance(instance_id)

template file "template.yaml"

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:

  ServerlessFunction:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: foo
      Handler: foo.handler
      CodeUri: ./
      Runtime: python3.7
      Timeout: 900

requirements file "requirements.txt":

boto3

The pip version is 19.0.3

The build output when trying to create the function is:

/usr/local/bin/sam build --template /Users/tennis.smith/PycharmProjects/test_lambda_toolkit_failure/.aws-sam/build/template.yaml --build-dir /Users/tennis.smith/PycharmProjects/test_lambda_toolkit_failure/.aws-sam/build Function
Building resource 'Function'
Running PythonPipBuilder:ResolveDependencies

Build Failed
Error: PythonPipBuilder:ResolveDependencies - Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'module' object is not callable
abrooksv commented 4 years ago

Sam uses the python on your PATH so check that.

You could also try building in the container. It's a checkbox on the upload dialog.

gamename commented 4 years ago

@abrooksv

Good idea. Will try that.

gamename commented 4 years ago

@abrooksv I can rule out the path because I'm running in a venv.

As for the building in a container, I don't see that option on the upload dialog. Where is it?

hunterwerlla commented 4 years ago

@gamename it's on the "SAM CLI" page

Screen Shot 2019-10-18 at 10 42 15 AM
gamename commented 4 years ago

@hunterwerlla @abrooksv Ok. I found the option in "SAM CLI". I enabled that option, then tried to upload the function again. Same error.

What does building it in a container prove?

abrooksv commented 4 years ago

Re-read the code, we didn't wire the create/update dialog to the build in container option. :/

Also SAM ignores virtualenvs since it needs to use the same python version as the runtime so that it can compile wheels that are compatible with Lambda. So it will take whatever Python is on your path that matches the runtime of the Lambda and use its pip.

gamename commented 4 years ago

@abrooksv I found the problem. There was a 19.3 pip version in my environment. Doing a which -a showed it.

I downgraded the pip to 19.2 and everything works. Thanks guys. :)