aws-sam-build-images
aws-sam-build-images copied to clipboard
Bug: Install library from git using ssh is not success on python3.12 and python3.13
Description:
When i was building my python lambda i can't download packages from github repo, installing packages worked using pip command, but it is failing using sam build and it failed to build my sam template
Steps to reproduce:
Run Docker container with Python 3.12
SSH_KEY_PATH="${HOME}/.ssh"
docker run -it \
--entrypoint /bin/bash \
-v "${SSH_KEY_PATH}:/root/.ssh" \
public.ecr.aws/sam/build-python3.12:latest
Inside the container
Add SSH key
chmod 400 ~/.ssh/github
eval `ssh-agent -s`
ssh-add ~/.ssh/github
ssh-keyscan github.com >> ~/.ssh/known_hosts
Add requirements to test
echo "git+ssh://[email protected]/aio-libs/[email protected]" >> requirements.txt
Install vim to paste sam template
dnf install vim -y
vim test_sam.yml
Paste python3.12 sam template for lambda
AWSTemplateFormatVersion: '2010-09-09'
Transform:
- AWS::Serverless-2016-10-31
Description: test
Resources:
lambda:
Type: AWS::Serverless::Function
DependsOn:
- LambdaRole
Properties:
FunctionName: test
Handler: app.listen
Runtime: python3.12
CodeUri: ./
MemorySize: 512
Timeout: 300
Environment:
Variables:
ENV: 'dev'
Build Sam
sam build --debug --template test_sam.yml
Observed result:
bash-5.2# sam build --debug --template test_sam.yml
2025-01-22 17:31:27,557 | Using SAM Template at /var/task/test_sam.yml
2025-01-22 17:31:27,559 | No config file found in this directory.
2025-01-22 17:31:27,560 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/var/task/samconfig.toml'
2025-01-22 17:31:27,561 | Config file location: /var/task/samconfig.toml
2025-01-22 17:31:27,561 | Config file '/var/task/samconfig.toml' does not exist
2025-01-22 17:31:27,573 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/var/task/samconfig.toml'
2025-01-22 17:31:27,574 | Using config file: samconfig.toml, config environment: default
2025-01-22 17:31:27,574 | Expand command line arguments to:
2025-01-22 17:31:27,575 | --template_file=/var/task/test_sam.yml --mount_with=READ --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2025-01-22 17:31:27,629 | 'build' command is called
2025-01-22 17:31:27,631 | No Parameters detected in the template
2025-01-22 17:31:27,646 | There is no customer defined id or cdk path defined for resource lambda, so we will use the resource logical id as the resource id
2025-01-22 17:31:27,647 | 0 stacks found in the template
2025-01-22 17:31:27,647 | No Parameters detected in the template
2025-01-22 17:31:27,664 | There is no customer defined id or cdk path defined for resource lambda, so we will use the resource logical id as the resource id
2025-01-22 17:31:27,664 | 1 resources found in the stack
2025-01-22 17:31:27,665 | Found Serverless function with name='lambda' and CodeUri='./'
2025-01-22 17:31:27,666 | --base-dir is not presented, adjusting uri ./ relative to /var/task/test_sam.yml
2025-01-22 17:31:27,686 | 1 resources found in the stack
2025-01-22 17:31:27,692 | Found Serverless function with name='lambda' and CodeUri='./'
2025-01-22 17:31:27,699 | Instantiating build definitions
2025-01-22 17:31:27,700 | No previous build graph found, generating new one
2025-01-22 17:31:27,704 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(python3.12, /var/task, Zip, ,
9ac2641a-a1c2-4be7-bc02-7f114631de01, {}, {}, x86_64, []), Function: Function({'function_id': 'lambda', 'name': 'lambda', 'functionname': 'test', 'runtime': 'python3.12', 'memory':
512, 'timeout': 300, 'handler': 'app.listen', 'imageuri': None, 'packagetype': 'Zip', 'imageconfig': None, 'codeuri': '/var/task', 'environment': {'Variables': {'ENV': 'dev'}},
'rolearn': None, 'layers': [], 'events': None, 'metadata': {'SamResourceId': 'lambda'}, 'inlinecode': None, 'codesign_config_arn': None, 'architectures': None, 'function_url_config':
None, 'function_build_info': <FunctionBuildInfo.BuildableZip: ('BuildableZip', 'Regular ZIP function which can be build with SAM CLI')>, 'stack_path': '',
'runtime_management_config': None, 'logging_config': None}))
2025-01-22 17:31:27,709 | Building codeuri: /var/task runtime: python3.12 architecture: x86_64 functions: lambda
2025-01-22 17:31:27,710 | Building to following folder /var/task/.aws-sam/build/lambda
2025-01-22 17:31:27,715 | Loading workflow module 'aws_lambda_builders.workflows'
2025-01-22 17:31:27,720 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
2025-01-22 17:31:27,722 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2025-01-22 17:31:27,723 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
2025-01-22 17:31:27,725 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
2025-01-22 17:31:27,727 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2025-01-22 17:31:27,730 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2025-01-22 17:31:27,732 | Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
2025-01-22 17:31:27,737 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2025-01-22 17:31:27,757 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
2025-01-22 17:31:27,758 | Registering workflow 'RustCargoLambdaBuilder' with capability 'Capability(language='rust', dependency_manager='cargo', application_framework=None)'
2025-01-22 17:31:27,759 | Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2025-01-22 17:31:27,778 | Running workflow 'PythonPipBuilder'
2025-01-22 17:31:27,779 | Running PythonPipBuilder:ResolveDependencies
2025-01-22 17:31:27,819 | calling pip download -r /var/task/requirements.txt --dest /tmp/tmp3c7dm8ym --exists-action i
2025-01-22 17:31:45,975 | pip stdout: b"Collecting git+ssh://****@github.com/aio-libs/[email protected] (from -r /var/task/requirements.txt (line 1))\n Cloning
ssh://****@github.com/aio-libs/aiohttp.git (to revision v3.11.11) to /tmp/pip-req-build-7509bqax\n Resolved ssh://****@github.com/aio-libs/aiohttp.git to commit
d8d79215ee4f27742b8ce96ea3a0d21756e6afde\n Installing build dependencies: started\n Installing build dependencies: finished with status 'done'\n Getting requirements to build
wheel: started\n Getting requirements to build wheel: finished with status 'done'\n Preparing metadata (pyproject.toml): started\n Preparing metadata (pyproject.toml): finished
with status 'done'\nCollecting aiohappyeyeballs>=2.3.0 (from aiohttp==3.11.11->-r /var/task/requirements.txt (line 1))\n Downloading aiohappyeyeballs-2.4.4-py3-none-any.whl.metadata
(6.1 kB)\nCollecting aiosignal>=1.1.2 (from aiohttp==3.11.11->-r /var/task/requirements.txt (line 1))\n Downloading aiosignal-1.3.2-py2.py3-none-any.whl.metadata (3.8
kB)\nCollecting attrs>=17.3.0 (from aiohttp==3.11.11->-r /var/task/requirements.txt (line 1))\n Downloading attrs-24.3.0-py3-none-any.whl.metadata (11 kB)\nCollecting
frozenlist>=1.1.1 (from aiohttp==3.11.11->-r /var/task/requirements.txt (line 1))\n Downloading
frozenlist-1.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (13 kB)\nCollecting multidict<7.0,>=4.5 (from aiohttp==3.11.11->-r /var/task/requirements.txt
(line 1))\n Downloading multidict-6.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (5.0 kB)\nCollecting propcache>=0.2.0 (from aiohttp==3.11.11->-r
/var/task/requirements.txt (line 1))\n Downloading propcache-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (9.2 kB)\nCollecting yarl<2.0,>=1.17.0 (from
aiohttp==3.11.11->-r /var/task/requirements.txt (line 1))\n Downloading yarl-1.18.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (69 kB)\nCollecting
idna>=2.0 (from yarl<2.0,>=1.17.0->aiohttp==3.11.11->-r /var/task/requirements.txt (line 1))\n Downloading idna-3.10-py3-none-any.whl.metadata (10 kB)\nDownloading
aiohappyeyeballs-2.4.4-py3-none-any.whl (14 kB)\nDownloading aiosignal-1.3.2-py2.py3-none-any.whl (7.6 kB)\nDownloading attrs-24.3.0-py3-none-any.whl (63 kB)\nDownloading
frozenlist-1.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (282 kB)\nDownloading multidict-6.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (130
kB)\nDownloading propcache-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (241 kB)\nDownloading
yarl-1.18.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (332 kB)\nDownloading idna-3.10-py3-none-any.whl (70 kB)\nSaved /tmp/tmp3c7dm8ym/aiohttp-3.11.11.zip\nSaved
/tmp/tmp3c7dm8ym/aiohappyeyeballs-2.4.4-py3-none-any.whl\nSaved /tmp/tmp3c7dm8ym/aiosignal-1.3.2-py2.py3-none-any.whl\nSaved /tmp/tmp3c7dm8ym/attrs-24.3.0-py3-none-any.whl\nSaved
/tmp/tmp3c7dm8ym/frozenlist-1.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl\nSaved
/tmp/tmp3c7dm8ym/multidict-6.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl\nSaved
/tmp/tmp3c7dm8ym/propcache-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl\nSaved
/tmp/tmp3c7dm8ym/yarl-1.18.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl\nSaved /tmp/tmp3c7dm8ym/idna-3.10-py3-none-any.whl\nSuccessfully downloaded aiohttp
aiohappyeyeballs aiosignal attrs frozenlist multidict propcache yarl idna\n"
2025-01-22 17:31:45,990 | pip stderr: b"WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.\nPlease see
https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.\nTo avoid this problem you can invoke Python with '-m pip' instead of running pip directly.\n
Running command git clone --filter=blob:none --quiet 'ssh://****@github.com/aio-libs/aiohttp.git' /tmp/pip-req-build-7509bqax\n Running command git checkout -q
d8d79215ee4f27742b8ce96ea3a0d21756e6afde\n Running command git submodule update --init --recursive -q\n\n[notice] A new release of pip is available: 24.2 -> 24.3.1\n[notice] To
update, run: pip install --upgrade pip\n"
2025-01-22 17:31:46,176 | Non zero rc (1) from the setup.py egg_info command: b'Traceback (most recent call last):\n File "<string>", line 1, in <module>\nModuleNotFoundError: No
module named \'setuptools\'\n'
2025-01-22 17:31:46,177 | Using fallback location for PKG-INFO file in package directory: /tmp/tmpq8gl6mbt/aiohttp
2025-01-22 17:31:46,183 | PythonPipBuilder:ResolveDependencies raised unhandled exception
Traceback (most recent call last):
File "aws_lambda_builders/workflow.py", line 374, in run
File "aws_lambda_builders/workflows/python_pip/actions.py", line 71, in execute
File "aws_lambda_builders/workflows/python_pip/packager.py", line 158, in build_dependencies
File "aws_lambda_builders/workflows/python_pip/packager.py", line 263, in build_site_packages
File "aws_lambda_builders/workflows/python_pip/packager.py", line 287, in _download_dependencies
File "aws_lambda_builders/workflows/python_pip/packager.py", line 370, in _download_all_dependencies
File "aws_lambda_builders/workflows/python_pip/packager.py", line 371, in <setcomp>
File "aws_lambda_builders/workflows/python_pip/packager.py", line 523, in __init__
File "aws_lambda_builders/workflows/python_pip/packager.py", line 565, in _calculate_name_and_version
File "aws_lambda_builders/workflows/python_pip/packager.py", line 707, in get_package_name_and_version
File "aws_lambda_builders/workflows/python_pip/packager.py", line 619, in _get_pkg_info_filepath
aws_lambda_builders.workflows.python_pip.packager.UnsupportedPackageError: Unable to retrieve name/version for package: aiohttp
Build Failed
2025-01-22 17:31:46,192 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-01-22 17:31:46,216 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-01-22 17:31:46,217 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '19352686-8229-439b-a4e9-78fbd20af953', 'installationId':
'f02e5575-fe7a-4805-8cb7-b230e61a4de7', 'sessionId': '243b271f-e9cf-4703-84d1-b3ec2510f9fe', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.10', 'samcliVersion':
'1.132.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None,
'projectName': '0ebb429fa86d481c2630fac53db1c91cffed5d4d41d1021c179444eb67e7ee0b', 'initialCommit': None}, 'duration': 18617, 'exitReason': 'WorkflowUnknownError', 'exitCode': 1}}]}
2025-01-22 17:31:46,217 | Unable to find Click Context for getting session_id.
2025-01-22 17:31:46,221 | Sending Telemetry: {'metrics': [{'events': {'requestId': '7161d8d8-fbf0-463a-94b7-023663c84012', 'installationId': 'f02e5575-fe7a-4805-8cb7-b230e61a4de7',
'sessionId': '243b271f-e9cf-4703-84d1-b3ec2510f9fe', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.10', 'samcliVersion': '1.132.0', 'commandName': 'sam build',
'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '7d14c9db89704d2c97cc7930c4a0e511', 'time_stamp': '2025-01-22
17:31:27.561', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'd67180278a6e46d2a5745e958d12cd2a', 'time_stamp': '2025-01-22
17:31:27.574', 'exception_name': None}, {'event_name': 'BuildFunctionRuntime', 'event_value': 'python3.12', 'thread_id': 'b7b41f6c0e1346428cf93849577035f8', 'time_stamp': '2025-01-22
17:31:27.698', 'exception_name': None}, {'event_name': 'BuildWorkflowUsed', 'event_value': 'python-pip', 'thread_id': '366d46e446194dc08ef1c7fc9042f38c', 'time_stamp': '2025-01-22
17:31:27.710', 'exception_name': None}]}}}]}
2025-01-22 17:31:46,791 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: PythonPipBuilder:ResolveDependencies - Unable to retrieve name/version for package: aiohttp
2025-01-22 17:31:46,798 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
bash-5.2#
Expected result:
Build Success
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- Used Images:
public.ecr.aws/sam/build-python3.12:latestandpublic.ecr.aws/sam/build-python3.13:latest - Fixed by install setuptools while running by
pip3 install setuptools
@hawflau @hnnasit can you have a look into this issue ?
git+ssh://[email protected]/aio-libs/[email protected] it seems adding dependency this way will actually build the package on the fly. Which I don't think sam support that. Is there any limitation that you can't use the package directly from pipy?
@roger-zhangg i did this as example and to help community to reproduce the issue, but i use this to install private package, that was work on python3.11 and before, but now it is not working on python3.12 and python3.13
Thanks for the context, I believe sam is doing a pip download -r /var/task/requirements.txt could you help to try if the error is the same if you run the command directly?
@roger-zhangg i have a flow that build venv with flake8 to do syntax check before sam build, it work and successful to install venv with the package but it fail on sam build, I don't know why, but it worked when i tried to install setuptools before sam build then it worked, I don't know how sam build install packages, but we started see this error on python3.12 and 3.13 images
@roger-zhangg please let me know if there any other info needed
Thanks @husseinmimi , will investigate more on this one.
@roger-zhangg any updates ?
any updates on this?
@roger-zhangg can this be escalated ?
@roger-zhangg any updates
@roger-zhangg @vicheey any updates, can we get this done ?
any updates ?
I am also facing same issue waiting for the @husseinmimi fix to be merged as soon as possible.... @roger-zhangg @vicheey
@niranjan-hd i am waiting my pr to get merged it just need a review 🙂
@roger-zhangg @vicheey any updates, i married and back from my vacation and PR still as it 😂
@husseinmimi Congrats 🥳
Hope your PR gets married to the develop branch soon too 😂
@husseinmimi congrats on the marriage! Sorry for the delay on this one
@roger-zhangg thanks man 🙌🏻