0

I want to run my Python program on IBM cloud functions, because of dependencies this needs to be done in an OpenWhisk Docker. I've changed my code so that it accepts a json:

json_input = json.loads(sys.argv[1])
INSTANCE_NAME = json_input['INSTANCE_NAME']

I can run it from the terminal:

python main/main.py '{"INSTANCE_NAME": "example"}'

I've added this Python program to OpenWhisk with this Dockerfile:

# 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"]

But now if I run it using IBM Cloud CLI I just get my Json back:

ibmcloud fn action invoke --result e2t-whisk --param-file ../env_var.json
# {"INSTANCE_NAME": "example"}

And if I run from the IBM Cloud Functions website with the same Json feed I get an error like it's not even there.

stderr: INSTANCE_NAME = json_input['INSTANCE_NAME']",
stderr: KeyError: 'INSTANCE_NAME'"

What can be wrong that the code runs when directly invoked, but not from the OpenWhisk container?

Herman
  • 750
  • 1
  • 10
  • 23
  • Did you try logging the input arguments to see what’s being passed in? – user6062970 Jun 05 '19 at 21:25
  • Like this? `json_input = json.loads(sys.argv[1])` `print json_input` I have. It didn't print anything. I don't invoke it in the `__main__.py` but in the file where I actually need the env variables. Could that be the problem? – Herman Jun 07 '19 at 08:42

0 Answers0