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
744 stars 213 forks source link

Sam build fails if executed within 60 seconds of a previous sam build command. #1473

Open mjmonroe opened 4 years ago

mjmonroe commented 4 years ago

Describe the bug When running a local invoke of a python lambda using the AWS toolkit in JetBrains, the first time the invoke works. If I run it again within 60 seconds, the second time it fails saying that it can not find the requirements file. The 60 seconds is from the last time SAM build was executed. Whether the build succeeds doesn't matter; an unsuccessful build will reset the timeout period back to 0.

SAM build error that occurs if running the lambda within 60 seconds of a previous SAM build.

Running PythonPipBuilder:ResolveDependencies
Build Failed
PythonPipBuilder:ResolveDependencies failed
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/0.39.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 39, in execute
    requirements_path=self.manifest_path
  File "/usr/local/Cellar/aws-sam-cli/0.39.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 141, in build_dependencies
    raise RequirementsFileNotFoundError(requirements_path)
aws_lambda_builders.workflows.python_pip.packager.RequirementsFileNotFoundError: Requirements file not found: /Users/machine/PycharmProjects/Marsh/.aws-sam/build/Function/requirements.txt

To reproduce

  1. Create a python lambda function.
  2. Create a SAM CLI local invoke configuration Screen Shot 2020-01-02 at 11 34 57 AM
  3. Run the lambda through the IDE.
  4. Run the lambda again through the IDE within 60 seconds.

SAM build logs

Log of the first successful lambda local invoke > /usr/local/bin/sam build --template /Users/machine/PycharmProjects/Marsh/.aws-sam/build/template.yaml --build-dir /Users/machine/PycharmProjects/Marsh/.aws-sam/build --skip-pull-image --debug Function > Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics > 'build' command is called > No Parameters detected in the template > 1 resources found in the template > Found Serverless function with name='Function' and CodeUri='/Users/machine/PycharmProjects/Marsh/marsh-worker/marsh_pedigree_worker' > Building resource 'Function' > Loading workflow module 'aws_lambda_builders.workflows' > Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)' > Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)' > Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)' > Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)' > Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)' > Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)' > Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)' > Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)' > Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)' > Running workflow 'PythonPipBuilder' > Running PythonPipBuilder:ResolveDependencies > calling pip download -r /Users/machine/PycharmProjects/Marsh/marsh-worker/marsh_pedigree_worker/requirements.txt --dest /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 > Full dependency closure: {elasticsearch-async==6.2.0(sdist), aiohttp==3.6.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel), motor==2.1.0(wheel), async-timeout==3.0.1(wheel), chardet==3.0.4(wheel), idna==2.8(wheel), yarl==1.4.2(wheel), python-dotenv==0.10.3(wheel), pydantic==1.3(wheel), attrs==19.3.0(wheel), urllib3==1.25.7(wheel), elasticsearch==7.1.0(wheel)} > initial compatible: {async-timeout==3.0.1(wheel), motor==2.1.0(wheel), chardet==3.0.4(wheel), idna==2.8(wheel), python-dotenv==0.10.3(wheel), pydantic==1.3(wheel), attrs==19.3.0(wheel), urllib3==1.25.7(wheel), elasticsearch==7.1.0(wheel)} > initial incompatible: {aiohttp==3.6.2(wheel), yarl==1.4.2(wheel), elasticsearch-async==6.2.0(sdist), multidict==4.7.3(wheel), pymongo==3.10.0(wheel)} > Downloading missing wheels: {elasticsearch-async==6.2.0(sdist), aiohttp==3.6.2(wheel), yarl==1.4.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel)} > calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 elasticsearch-async==6.2.0 > calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 aiohttp==3.6.2 > calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 yarl==1.4.2 > calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 multidict==4.7.3 > calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 pymongo==3.10.0 > compatible wheels after second download pass: {aiohttp==3.6.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel), motor==2.1.0(wheel), async-timeout==3.0.1(wheel), chardet==3.0.4(wheel), idna==2.8(wheel), yarl==1.4.2(wheel), python-dotenv==0.10.3(wheel), pydantic==1.3(wheel), attrs==19.3.0(wheel), urllib3==1.25.7(wheel), elasticsearch==7.1.0(wheel)} > Build missing wheels from sdists (C compiling True): {elasticsearch-async==6.2.0(sdist)} > calling pip wheel --no-deps --wheel-dir /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4 /var/folders/2r/5kg_kk1n6x794c288npr0x0m0000gp/T/tmpwqy9_0v4/elasticsearch-async-6.2.0.tar.gz > compatible after building wheels (no C compiling): {elasticsearch-async==6.2.0(wheel), aiohttp==3.6.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel), motor==2.1.0(wheel), async-timeout==3.0.1(wheel), chardet==3.0.4(wheel), idna==2.8(wheel), yarl==1.4.2(wheel), python-dotenv==0.10.3(wheel), pydantic==1.3(wheel), attrs==19.3.0(wheel), urllib3==1.25.7(wheel), elasticsearch==7.1.0(wheel)} > Build missing wheels from sdists (C compiling False): set() > compatible after building wheels (C compiling): {elasticsearch-async==6.2.0(wheel), aiohttp==3.6.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel), motor==2.1.0(wheel), async-timeout==3.0.1(wheel), chardet==3.0.4(wheel), idna==2.8(wheel), yarl==1.4.2(wheel), python-dotenv==0.10.3(wheel), pydantic==1.3(wheel), attrs==19.3.0(wheel), urllib3==1.25.7(wheel), elasticsearch==7.1.0(wheel)} > Final compatible: {elasticsearch-async==6.2.0(wheel), aiohttp==3.6.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel), motor==2.1.0(wheel), async-timeout==3.0.1(wheel), chardet==3.0.4(wheel), idna==2.8(wheel), yarl==1.4.2(wheel), python-dotenv==0.10.3(wheel), pydantic==1.3(wheel), attrs==19.3.0(wheel), urllib3==1.25.7(wheel), elasticsearch==7.1.0(wheel)} > Final incompatible: {aiohttp==3.6.2(wheel), yarl==1.4.2(wheel), multidict==4.7.3(wheel), pymongo==3.10.0(wheel)} > Final missing wheels: set() > PythonPipBuilder:ResolveDependencies succeeded > Running PythonPipBuilder:CopySource > PythonPipBuilder:CopySource succeeded > > Build Succeeded > > Built Artifacts : ../../../../Users/machine/PycharmProjects/Marsh/.aws-sam/build > Built Template : ../../../../Users/machine/PycharmProjects/Marsh/.aws-sam/build/template.yaml > > Commands you can use next > \========================= > [*] Invoke Function: sam local invoke -t ../../../../Users/machine/PycharmProjects/Marsh/.aws-sam/build/template.yaml > [*] Deploy: sam deploy --guided --template-file ../../../../Users/machine/PycharmProjects/Marsh/.aws-sam/build/template.yaml > > Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 7465, 'exitReason': 'success', 'exitCode': 0, 'requestId': '77bb7cfa-377c-4396-8561-51a4e5a9a72e', 'installationId': '72dd4e59-d6e3-4e07-a226-f0ac40f516ed', 'sessionId': 'e182d0ad-83b7-4956-bc09-1c1ac2462c11', 'executionEnvironment': 'CLI', 'pyversion': '3.7.6', 'samcliVersion': '0.39.0'}}]} > Telemetry response: 200
Log of the second unsuccessful lambda local invoke > /usr/local/bin/sam build --template /Users/machine/PycharmProjects/Marsh/.aws-sam/build/template.yaml --build-dir /Users/machine/PycharmProjects/Marsh/.aws-sam/build --debug Function > Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics > 'build' command is called > No Parameters detected in the template > 1 resources found in the template > Found Serverless function with name='Function' and CodeUri='/Users/machine/PycharmProjects/Marsh/.aws-sam/build/Function' > Building resource 'Function' > Loading workflow module 'aws_lambda_builders.workflows' > Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)' > Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)' > Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)' > Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)' > Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)' > Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)' > Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)' > Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)' > Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)' > Running workflow 'PythonPipBuilder' > Running PythonPipBuilder:ResolveDependencies > > Build Failed > PythonPipBuilder:ResolveDependencies failed > Traceback (most recent call last): > File "/usr/local/Cellar/aws-sam-cli/0.39.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 39, in execute > requirements_path=self.manifest_path > File "/usr/local/Cellar/aws-sam-cli/0.39.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 141, in build_dependencies > raise RequirementsFileNotFoundError(requirements_path) > aws_lambda_builders.workflows.python_pip.packager.RequirementsFileNotFoundError: Requirements file not found: /Users/machine/PycharmProjects/Marsh/.aws-sam/build/Function/requirements.txt > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/usr/local/Cellar/aws-sam-cli/0.39.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 248, in run > action.execute() > File "/usr/local/Cellar/aws-sam-cli/0.39.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 42, in execute > raise ActionFailedError(str(ex)) > aws_lambda_builders.actions.ActionFailedError: Requirements file not found: /Users/machine/PycharmProjects/Marsh/.aws-sam/build/Function/requirements.txt > Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 248, 'exitReason': 'BuildError', 'exitCode': 1, 'requestId': '572926ef-fd63-4d7e-b2ed-a87da0f9a0a8', 'installationId': '72dd4e59-d6e3-4e07-a226-f0ac40f516ed', 'sessionId': 'ec488759-6a32-46fb-8fc1-84ca0f4d664f', 'executionEnvironment': 'CLI', 'pyversion': '3.7.6', 'samcliVersion': '0.39.0'}}]} > Telemetry response: 200 > Error: PythonPipBuilder:ResolveDependencies - Requirements file not found: /Users/machine/PycharmProjects/Marsh/.aws-sam/build/Function/requirements.txt

Expected behavior It should be possible to invoke a python lambda function through the IDE within 60 seconds of the previous invocation.

Your Environment

greg-gl commented 4 years ago

I too get this issue however its every second run (unless I delete the build directory manually). This is because the sam cli build command deletes the entire build directory before restarting a build and hence the requirements.txt that was in the build directory is no longer there. Once the build directory is gone then a subsequent run of the lamba function works because it uses the requirements.txt in the root of my project.

An additional side effect of this is that all the requirements are downloaded every time the lambda function is run which considering the time it takes even if just boto3 is installed makes this a very cumbersome and relatively unproductive environment for debugging lambda functions locally due to over a minute of build time for each code change.

For this particular issue a nice solution would be if the requirements.txt in the root directory is the same as in the build directory then do not do a full sam cli build but instead just replace the lambda file and re-deploy to the docker container. This would definitely make debugging lambda locally much faster and better. Thanks for any attention you can pay on this issue!

Windows 10 Professional Pycharm Professional 2019.3.4 Python 3.7 SAM CLI version 0.45.0 aws-cli/1.17.10 Python/3.6.0 Windows/10 botocore/1.14.10