gpt4 book ai didi

python - 我如何将 Python Lambda 函数集成到 AWS Amplify 的管道中

转载 作者:行者123 更新时间:2023-12-04 08:05:24 24 4
gpt4 key购买 nike

所以我正在尝试使用 Javascript 和 Python Lambda 函数构建一个 Ampliy 应用程序。一切正常。我已经设置了我的 CodeCommit Branch 以进行持续部署的托管。我在 Python 中添加了一个带有 Lambda 函数的 API。通过 amplify push,amplify 成功部署了相应的 API Gateway 和 Lambda,我可以成功地与我的 lambda 函数进行交互。因此,一旦我将提交推送到我的存储库中,管道就会在构建阶段触发并崩溃:

                                 # Starting phase: build
# Executing command: amplifyPush --simple
2021-02-17T14:01:23.680Z [INFO]: [0mAmplify AppID found: d2l0j3vtlykp8l. Amplify App name is: documentdownload[0m
2021-02-17T14:01:23.783Z [INFO]: [0mBackend environment dev found in Amplify Console app: documentdownload[0m
2021-02-17T14:01:24.440Z [WARNING]: - Fetching updates to backend environment: dev from the cloud.
2021-02-17T14:01:24.725Z [WARNING]: ✔ Successfully pulled backend environment dev from the cloud.
2021-02-17T14:01:24.758Z [INFO]:
2021-02-17T14:01:26.925Z [INFO]: [33mNote: It is recommended to run this command from the root of your app directory[39m
2021-02-17T14:01:31.904Z [WARNING]: - Initializing your environment: dev
2021-02-17T14:01:32.216Z [WARNING]: ✔ Initialized provider successfully.
2021-02-17T14:01:32.829Z [INFO]: [31mpython3 found but version Python 3.7.9 is less than the minimum required version.[39m
[31mYou must have python >= 3.8 installed and available on your PATH as "python3" or "python". It can be installed from https://www.python.org/downloads[39m
[31mYou must have pipenv installed and available on your PATH as "pipenv". It can be installed by running "pip3 install --user pipenv".[39m
2021-02-17T14:01:32.830Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2021-02-17T14:01:32.830Z [WARNING]: ✖ There was an error initializing your environment.
2021-02-17T14:01:32.832Z [INFO]: [31minit failed[39m
2021-02-17T14:01:32.834Z [INFO]: [0mError: Missing required dependencies to package documentdownload[0m
[0m at Object.buildFunction (/root/.nvm/versions/node/v12.19.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/src/provider-utils/awscloudformation/utils/buildFunction.ts:21:11)[0m
[0m at processTicksAndRejections (internal/process/task_queues.js:97:5)[0m
[0m at prepareResource (/root/.nvm/versions/node/v12.19.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/push-resources.ts:474:33)[0m
[0m at async Promise.all (index 0)[0m
[0m at Object.run (/root/.nvm/versions/node/v12.19.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/push-resources.ts:106:5)[0m
2021-02-17T14:01:32.856Z [ERROR]: !!! Build failed
2021-02-17T14:01:32.856Z [ERROR]: !!! Non-Zero Exit Code detected
2021-02-17T14:01:32.856Z [INFO]: # Starting environment caching...
2021-02-17T14:01:32.857Z [INFO]: # Environment caching completed
在上一步中,PROVISION 步骤是 Python 3.8,不过..
## Install python3.8
RUN wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
RUN tar xvf Python-3.8.0.tgz
WORKDIR Python-3.8.0
RUN ./configure --enable-optimizations --prefix=/usr/local
RUN make altinstall
现在我不知道它为什么会这样。在本地推送更改它有效。有人可以帮忙吗?

最佳答案

来自 here 的两个解决方案:

  • 交换构建镜像 这可以通过 this 来完成.转到 Amplify 控制台,打开左侧菜单,单击“build设置”,向下滚动直到看到“构建图像设置”,在下拉列表中选择自定义,然后在正下方的字段中输入图像名称它

  • 2.如果你想从你提到的来源构建:将以下内容添加到 amplify.yml在应用设置下的 AWS 控制台中 -> build设置:
    backend:
    phases:
    preBuild:
    commands:
    - export BASE_PATH=$(pwd)
    - yum install -y gcc openssl-devel bzip2-devel libffi-devel python3.8-pip
    - cd /opt && wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
    - cd /opt && tar xzf Python-3.8.2.tgz
    - cd /opt/Python-3.8.2 && ./configure --enable-optimizations
    - cd /opt/Python-3.8.2 && make altinstall
    - pip3.8 install --user pipenv
    - ln -fs /usr/local/bin/python3.8 /usr/bin/python3
    - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3
    - cd $BASE_PATH

    关于python - 我如何将 Python Lambda 函数集成到 AWS Amplify 的管道中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66243613/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com