我如何将 Python Lambda 函数集成到 AWS Amplify 的管道中
How do i integrate a Python Lambda Function into the Pipeline of AWS Amplify
所以我正在尝试使用 Javascript 和 Python Lambda 函数构建一个 Ampliy 应用程序。一切正常。我已经设置了我的 CodeCommit 分支,用于托管和持续部署。我在 Python 中添加了一个带有 Lambda 函数的 API。通过 amplify 推送,amplify 成功部署了相应的 API 网关和 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 控制台,打开左侧的菜单,单击“构建设置”,向下滚动直到看到“构建映像设置” , 在下拉菜单 select 自定义中,然后在其正下方的字段中输入图像名称
2.If 你想从你提到的来源构建:将以下内容添加到 AWS 控制台中应用程序设置下的 amplify.yml
-> 构建设置:
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
所以我正在尝试使用 Javascript 和 Python Lambda 函数构建一个 Ampliy 应用程序。一切正常。我已经设置了我的 CodeCommit 分支,用于托管和持续部署。我在 Python 中添加了一个带有 Lambda 函数的 API。通过 amplify 推送,amplify 成功部署了相应的 API 网关和 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 控制台,打开左侧的菜单,单击“构建设置”,向下滚动直到看到“构建映像设置” , 在下拉菜单 select 自定义中,然后在其正下方的字段中输入图像名称
2.If 你想从你提到的来源构建:将以下内容添加到 AWS 控制台中应用程序设置下的 amplify.yml
-> 构建设置:
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