It allows you to access the value of JSON from the bash by supplying the JSON key as an environment variable.
Openwhisk can respond only stdout
of JSON type.
so if you want to return your custom response, you must
return (echo in last) JSON written to stdout
Like this
echo "{ \"hello\": \"ran without a docker pull!\" }"
If you return simple string, the result would be:
{
"result": "your custom message"
}
You can access to your JSON values from request by environment variables
-
Objects
From
{ "key":{ "key1":"value1", "key2":"value2" } }
To
# in exec echo $_key_key1 echo $_key_key2 # value1 # value2
-
List
From
{ "key":[ {"first":"value1"}, {"second":"value2"} ] }
To
# in exec echo $_key_0_first echo $_key_1_second # value1 # value2
-
docker build -t <your docker tag> .
-
docker run -it -p 8080:8080 <your docker tag>
-
vi exec
#!/bin/bash echo $_test
-
zip exec.zip exec && base64 exec.zip
UEsDBAoAAAAAAOFteUu08uFhGAAAABgAAAAEABwAZXhlY1VUCQADxvUYWsz1GFp1eAsAAQT1AQAABBQAAAAjIS9iaW4vYmFzaAoKZWNobyAkX3Rlc3RQSwECHgMKAAAAAADhbXlLtPLhYRgAAAAYAAAABAAYAAAAAAABAAAApIEAAAAAZXhlY1VUBQADxvUYWnV4CwABBPUBAAAEFAAAAFBLBQYAAAAAAQABAEoAAABWAAAAAAA=
-
Init your binary
POST http://localhost:8080/init
JSON body:
{ "value":{ "binary":true, "code":"UEsDBAoAAAAAAOFteUu08uFhGAAAABgAAAAEABwAZXhlY1VUCQADxvUYWsz1GFp1eAsAAQT1AQAABBQAAAAjIS9iaW4vYmFzaAoKZWNobyAkX3Rlc3RQSwECHgMKAAAAAADhbXlLtPLhYRgAAAAYAAAABAAYAAAAAAABAAAApIEAAAAAZXhlY1VUBQADxvUYWnV4CwABBPUBAAAEFAAAAFBLBQYAAAAAAQABAEoAAABWAAAAAAA" } }
-
Execute
POST http://localhost:8080/run
JSON body:
{ "value":{ "test":"Hello World!" } }
Response would like this
{ "result":"Hello World!" }
- push your docker image to docker hub
wsk action create bash2action --docker <docker image tag (dockerhub)>
wsk action invoke bash2action --blocking --result -p test "Hello World!"