简体   繁体   English

使用 SQLAlchemy 时 SAM 构建失败

[英]SAM Build Fails when using SQLAlchemy

I am trying to use the sqlalchemy library in a Lambda I want to upload.我正在尝试在要上传的 Lambda 中使用 sqlalchemy 库。 This uses a AWS Lambda project created using the AWS toolkit in Pycharm.这使用了使用 Pycharm 中的 AWS 工具包创建的 AWS Lambda 项目。 The sqlalchemy library is used only to insert pandas tables into mysql (tables have 300+ columns with more to be added in the future, so explicitly defining column names is not an option). sqlalchemy 库仅用于将 Pandas 表插入 mysql(表有 300 多个列,将来会添加更多列,因此明确定义列名不是一种选择)。 Note that the library is included within the requirements.txt file.请注意,该库包含在 requirements.txt 文件中。 The lambda runs fine when running on my local machine using the "Build function inside a container" parameter inside the run configurations.使用运行配置中的“容器内的构建函数”参数在我的本地计算机上运行时,lambda 运行良好。 I believe this parameter is the equivalent to using the command:我相信这个参数相当于使用命令:

sam build --use-container

However, the configuration for remotely deploying the lambda does not include the parameter "Build function inside a container".但是,远程部署 lambda 的配置不包含参数“在容器内构建函数”。 As such I get the following error when I attempt the deploy my function remotely:因此,当我尝试远程部署我的函数时,出现以下错误:

2019-04-17 13:23:07 Using SAM Template at /Users/davidpell/PycharmProjects/lambda/template.yaml
2019-04-17 13:23:07 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-04-17 13:23:07 Changing event name from before-call.apigateway to before-call.api-gateway
2019-04-17 13:23:07 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-04-17 13:23:07 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-04-17 13:23:07 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-04-17 13:23:07 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-04-17 13:23:07 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-04-17 13:23:07 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-04-17 13:23:07 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-04-17 13:23:07 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-04-17 13:23:07 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-04-17 13:23:07 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-04-17 13:23:07 Changing event name from before-call.apigateway to before-call.api-gateway
2019-04-17 13:23:07 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-04-17 13:23:07 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-04-17 13:23:07 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-04-17 13:23:07 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-04-17 13:23:07 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-04-17 13:23:07 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-04-17 13:23:07 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-04-17 13:23:07 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-04-17 13:23:07 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-04-17 13:23:07 'build' command is called
2019-04-17 13:23:07 No Parameters detected in the template
2019-04-17 13:23:07 2 resources found in the template
2019-04-17 13:23:07 Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2019-04-17 13:23:08 Building resource 'HelloWorldFunction'
2019-04-17 13:23:08 Loading workflow module 'aws_lambda_builders.workflows'
2019-04-17 13:23:08 Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2019-04-17 13:23:08 Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2019-04-17 13:23:08 Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2019-04-17 13:23:08 Running workflow 'PythonPipBuilder'
2019-04-17 13:23:08 Running PythonPipBuilder:ResolveDependencies
2019-04-17 13:23:08 calling pip download -r /Users/davidpell/PycharmProjects/lambda/hello_world/requirements.txt --dest /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp
2019-04-17 13:23:13 Full dependency closure: {numpy==1.16.2(wheel), six==1.12.0(wheel), requests==2.21.0(wheel), pytz==2019.1(wheel), pymysql==0.9.3(wheel), urllib3==1.24.1(wheel), python-dateutil==2.8.0(wheel), setuptools==41.0.0(wheel), sqlalchemy==1.3.3(sdist), pip==19.0.3(wheel), idna==2.8(wheel), chardet==3.0.4(wheel), certifi==2019.3.9(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:13 initial compatible: {six==1.12.0(wheel), requests==2.21.0(wheel), pytz==2019.1(wheel), pymysql==0.9.3(wheel), urllib3==1.24.1(wheel), python-dateutil==2.8.0(wheel), setuptools==41.0.0(wheel), pip==19.0.3(wheel), idna==2.8(wheel), chardet==3.0.4(wheel), certifi==2019.3.9(wheel)}
2019-04-17 13:23:13 initial incompatible: {numpy==1.16.2(wheel), pandas==0.24.2(wheel), sqlalchemy==1.3.3(sdist)}
2019-04-17 13:23:13 Downloading missing wheels: {sqlalchemy==1.3.3(sdist), numpy==1.16.2(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:13 calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp sqlalchemy==1.3.3
2019-04-17 13:23:14 calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp numpy==1.16.2
2019-04-17 13:23:15 calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp pandas==0.24.2
2019-04-17 13:23:16 compatible wheels after second download pass: {numpy==1.16.2(wheel), six==1.12.0(wheel), requests==2.21.0(wheel), pytz==2019.1(wheel), pymysql==0.9.3(wheel), urllib3==1.24.1(wheel), python-dateutil==2.8.0(wheel), setuptools==41.0.0(wheel), pip==19.0.3(wheel), idna==2.8(wheel), chardet==3.0.4(wheel), certifi==2019.3.9(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:16 Build missing wheels from sdists (C compiling True): {sqlalchemy==1.3.3(sdist)}
2019-04-17 13:23:16 calling pip wheel --no-deps --wheel-dir /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp/SQLAlchemy-1.3.3.tar.gz
2019-04-17 13:23:17 compatible after building wheels (no C compiling): {numpy==1.16.2(wheel), six==1.12.0(wheel), requests==2.21.0(wheel), pytz==2019.1(wheel), pymysql==0.9.3(wheel), urllib3==1.24.1(wheel), python-dateutil==2.8.0(wheel), setuptools==41.0.0(wheel), pip==19.0.3(wheel), idna==2.8(wheel), chardet==3.0.4(wheel), certifi==2019.3.9(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:17 Build missing wheels from sdists (C compiling False): {sqlalchemy==1.3.3(sdist)}
2019-04-17 13:23:17 calling pip wheel --no-deps --wheel-dir /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp/SQLAlchemy-1.3.3.tar.gz
2019-04-17 13:23:19 compatible after building wheels (C compiling): {numpy==1.16.2(wheel), six==1.12.0(wheel), requests==2.21.0(wheel), pytz==2019.1(wheel), pymysql==0.9.3(wheel), urllib3==1.24.1(wheel), python-dateutil==2.8.0(wheel), setuptools==41.0.0(wheel), pip==19.0.3(wheel), idna==2.8(wheel), chardet==3.0.4(wheel), certifi==2019.3.9(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:19 Final compatible: {numpy==1.16.2(wheel), six==1.12.0(wheel), requests==2.21.0(wheel), pytz==2019.1(wheel), pymysql==0.9.3(wheel), urllib3==1.24.1(wheel), python-dateutil==2.8.0(wheel), setuptools==41.0.0(wheel), pip==19.0.3(wheel), idna==2.8(wheel), chardet==3.0.4(wheel), certifi==2019.3.9(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:19 Final incompatible: {numpy==1.16.2(wheel), pandas==0.24.2(wheel)}
2019-04-17 13:23:19 Final missing wheels: {sqlalchemy==1.3.3(sdist)}
2019-04-17 13:23:20 PythonPipBuilder:ResolveDependencies failed
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/0.14.2/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 39, in execute
    self.scratch_dir
  File "/usr/local/Cellar/aws-sam-cli/0.14.2/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 143, in build_dependencies
    requirements_path, artifacts_dir_path, scratch_dir_path)
  File "/usr/local/Cellar/aws-sam-cli/0.14.2/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 212, in build_site_packages
    raise MissingDependencyError(packages_without_wheels)
aws_lambda_builders.workflows.python_pip.packager.MissingDependencyError: {sqlalchemy==1.3.3(sdist)}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/0.14.2/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 236, in run
    action.execute()
  File "/usr/local/Cellar/aws-sam-cli/0.14.2/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: {sqlalchemy==1.3.3(sdist)}
Build Failed
Error: PythonPipBuilder:ResolveDependencies - {sqlalchemy==1.3.3(sdist)}

The point of interest is calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp sqlalchemy==1.3.3兴趣点是calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp37m --dest /var/folders/c4/jqqz7trx02l9w1qkbx8dzxvr0000gn/T/tmpgl5r1tqp sqlalchemy==1.3.3

Removing the parameter --only-binary=:all: will allow this individual command to function, however I do not know whether this will help.删除参数--only-binary=:all:将允许这个单独的命令起作用,但是我不知道这是否有帮助。

How can I build my lambda function that includes the sqlalchemy dependency?如何构建包含 sqlalchemy 依赖项的 lambda 函数?

The functionality within Pycharm exists. Pycharm 中的功能存在。 Right click on the root project folder as shown and select "Deploy Serverless Application".右键单击如图所示的根项目文件夹,然后选择“部署无服务器应用程序”。

在此处输入图片说明

Select whether to Create/Update a (CloudFormation) stack and then tick "Build function inside a container".选择是否创建/更新 (CloudFormation) 堆栈,然后勾选“在容器内构建函数”。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 AWS SAM 创建 Hello World 应用程序:运行“sam build”时出现问题 - Creating a Hello World application using AWS SAM : issue when running "sam build" 为什么使用全局部分时 AWS SAM CLI (awssamcli) 无法构建? - Why does AWS SAM CLI (awssamcli) fail to build when using Global section? 使用 SQLAlchemy TypeDecorator 时棉花糖验证错误地失败 - Marshmallow validation incorrectly fails when using an SQLAlchemy TypeDecorator 使用 aws sam 时有没有办法修复 pythonpath? - Is there a way to fix the pythonpath when using aws sam? 添加literal_column时SQLAlchemy失败 - SQLAlchemy fails when adding literal_column 使用Homebrew在Mountain Lion上的MBA上安装python时,构建失败 - Build fails when installing python on MBA with Mountain Lion using Homebrew 尝试使用 python 映像安装 Fiona 时 Docker 构建失败 - Docker build Fails when trying to install Fiona using python image 使用 set(int) (Python) 时构建集合失败 - Build a set fails when using set(int) (Python) SQLAlchemy:使用`and` 和`or` 时出现意外结果 - SQLAlchemy: unexpected results when using `and` and `or` 引用uid时创建新的SQLalchemy对象失败 - create new SQLalchemy object fails when referenceing uid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM