Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to invoke a web action for .json context extension via wsk command? #465

Open
JiniousChoi opened this issue Dec 6, 2019 · 6 comments

Comments

@JiniousChoi
Copy link

apache/openwhisk#4712 Environment details:

local deployment

Steps to reproduce the issue:

  1. make a simple raw HTTP web action in python
def main(args):
    val = args['__ow_headers']
    print(args)
    return { "response": args,
             "val": val }
  1. try to invoke it with wsk command
$ wsk action invoke -r cs/jin-test
{
    "error": "The action did not return a dictionary."
}
  1. check out the activation log
wsk activation get --last
    "logs": [
        "2019-12-06T04:11:54.832861208Z stderr: Traceback (most recent call last):",
        "2019-12-06T04:11:54.832914474Z stderr: File \"pythonrunner.py\", line 88, in run",
        "2019-12-06T04:11:54.832926486Z stderr: exec('fun = %s(param)' % self.mainFn, self.global_context)",
        "2019-12-06T04:11:54.832934019Z stderr: File \"<string>\", line 1, in <module>",
        "2019-12-06T04:11:54.832941Z    stderr: File \"__main__.py\", line 3, in main",
        "2019-12-06T04:11:54.833038393Z stderr: KeyError: '__ow_headers'"
    ],
  1. But it works with curl when invoked with .json context extension
curl https://frisb.kakao.com/api/v1/web/jin.c/cs/jin-test.json
{
  "response": {
    "__ow_body": "",
    "__ow_headers": {
      "accept": "*/*",
      "host": "controllers",
      "user-agent": "curl/7.54.0",
      "x-request-id": "e7e3d9a52c099c6a6e46bce11207d5a4"
    },
    "__ow_method": "get",
    "__ow_path": "",
    "__ow_query": ""
  },
  "val": {
    "accept": "*/*",
    "host": "controllers",
    "user-agent": "curl/7.54.0",
    "x-request-id": "e7e3d9a52c099c6a6e46bce11207d5a4"
  }

What I want

I'd love to know if there is a way for the wsk command to invoke a web action with context extensions. I learned that the default is .http in the docs and I wonder if there is no way for wsk to invoke an action other context extensions but .http.

@JiniousChoi JiniousChoi changed the title How to invoke a web action via web action for .json context extension? How to invoke a web action via wsk command for .json context extension? Dec 6, 2019
@JiniousChoi JiniousChoi changed the title How to invoke a web action via wsk command for .json context extension? How to invoke a web action for .json context extension via wsk command? Dec 6, 2019
@style95
Copy link
Member

style95 commented Dec 6, 2019

I believe you can execute your web action with wsk.
Could you replace the way you are getting inputs as follow:

def main(args):
    val = args.get('__ow_headers', "default")
    print(args)
    return { "response": args,
             "val": val }

I can invoke the action with your code.

$ wsk action invoke /style95/python-web -r
{
    "response": {},
    "val": "default"
}

When you invoke a web action with wsk, OW would not populate some information such as __ow_headers because it treats the action as a normal action.

@upgle
Copy link
Member

upgle commented Dec 6, 2019

There is no command to invoke a web action including extension. You should send the request directly using the curl command.

@style95
Copy link
Member

style95 commented Dec 6, 2019

@JiniousChoi
Currently, you can easily get the URL of a web action.

$ wsk action get python-web --url
ok: got action python-web
https://{HOST}/api/v1/web/style95/default/python-web

Is there any specific reason that you need to invoke it with wsk?

@JiniousChoi
Copy link
Author

JiniousChoi commented Dec 6, 2019

I suggest that wsk should provide a switch for web action invocation.
Say, if there is an action named ACTION:

wsk action invoke -r ACTION -web=[http|json|text|svg|...]

or, we could be more explicit about this matter in wsk action invoke --help, regarding what's feasible and what isn't.

@style95
While we can make both normal/web action types with the command, we ONLY can invoke normal actions with it. And I don't see any explicit explanation about it.

It's a matter of UX. it seems inconsistent to me.

@style95
And that brings in one more hop here.
A user who simply wants to check if one's web action is working or not would need to run like:

curl $(wsk action get python-web --url)

I think wsk action invoke python-web --web looks intuitive and nicer.

@style95
Copy link
Member

style95 commented Dec 6, 2019

Interesting.
Would be a good point to add.

I would move this issue to cli repo to proceed with it.

@rabbah
Copy link
Member

rabbah commented Dec 6, 2019

Indeed a good idea.

@style95 style95 transferred this issue from apache/openwhisk Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants