首页 > 解决方案 > 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 容器中运行时会出现什么问题?

标签: pythondockeropenwhiskibm-cloud-functions

解决方案


推荐阅读