python - Openwhisk Docker 与 IBM 云 CLI 的行为与其前端不同
问题描述
我想在 IBM 云函数上运行我的 Python 程序,因为这需要在 OpenWhisk Docker 中完成。我已经更改了我的代码,以便它接受一个 json:
json_input = json.loads(sys.argv[1])
INSTANCE_NAME = json_input['INSTANCE_NAME']
我可以从终端运行它:
python main/main.py '{"INSTANCE_NAME": "example"}'
我已使用此 Dockerfile 将此 Python 程序添加到 OpenWhisk:
# Dockerfile for example whisk docker action
FROM openwhisk/dockerskeleton
ENV FLASK_PROXY_PORT 8080
### Add source file(s)
ADD requirements.txt /action/requirements.txt
RUN cd /action; pip install -r requirements.txt
# Move the file to
ADD ./main /action
# Rename our executable Python action
ADD /main/main.py /action/exec
CMD ["/bin/bash", "-c", "cd actionProxy && python -u actionproxy.py"]
但是现在,如果我使用 IBM Cloud CLI 运行它,我只会取回我的 Json:
ibmcloud fn action invoke --result e2t-whisk --param-file ../env_var.json
# {"INSTANCE_NAME": "example"}
如果我使用相同的 Json 提要从 IBM Cloud Functions 网站运行,我会收到一个错误,就像它根本不存在一样。
stderr: INSTANCE_NAME = json_input['INSTANCE_NAME']",
stderr: KeyError: 'INSTANCE_NAME'"
代码在直接调用而不是从 OpenWhisk 容器中运行时会出现什么问题?
解决方案
推荐阅读
- python - 如果我在我的用户帐户(linux 集群)中运行 http 服务器,如何让其他用户访问它?
- javascript - 是否可以将此代码(或转换)与不同的 jQuery 版本一起使用?
- asp.net-mvc - Linq GroupBy 查询超时
- opayo - 以编程方式确定 Sagepay 卡详细信息表单是否不完整
- mysql - 在给定日期之前查找分数的存储过程
- r - 为 Ops 分组通用方法(用于时间序列)
- azure - 如何在 Azure Blob 存储中的容器中添加自定义列?
- wordpress - 在 word press 错误中导入应用程序
- c# - CsvHelper.Configuration.ClassMap 的动态分配属性
- nestjs - 有没有办法使用单个装饰器隐藏 controller.ts 中的所有端点?