Skip to content
timkay edited this page Nov 5, 2014 · 1 revision

Using the --exec option

The aws recv QUEUE --exec command will receive a message from QUEUE, execute the message at the command line, and then, if the command was successful, delete the message. Example:

$ aws send /262088988105/test --message 'echo hello' --simple
cd18203adcdc4404664fea34541d8717        9bb8b116-2563-4327-8851-5b3075510f0b
$ aws recv /262088988105/test --wait 10 --exec
hello

In this example, the --exec option was provided without a value, so the body of the message is executed via the command line (the shell), using the system() call.

If a value for --exec=CMD is provided, then CMD is executed. The body of the message is available in the $body variable. For example:

$ aws send /262088988105/test --message 'echo hello' --simple
cd18203adcdc4404664fea34541d8717        4b974c9f-3093-43aa-a37d-ba1d064d9f18
$ aws recv /262088988105/test --wait 10 --exec='system "echo $body"'
echo hello

In this case, the entire body was echoed because the CMD is echo $body, and $body is echo hello, so the command line is echo echo hello.

If the command fails (returns non-zero return code), then the message is not deleted.