Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active September 11, 2019 14:31
Show Gist options
  • Save greymd/9621f90740ec0fa05c94e3e9949f4d68 to your computer and use it in GitHub Desktop.
Save greymd/9621f90740ec0fa05c94e3e9949f4d68 to your computer and use it in GitHub Desktop.
Run given command as is with Custom AWS Lambda Runtime
# Input is like {"command":"bHMgLWFsIHwgZ3JlcCBob2dlaG9nZQo="}
function handler () {
EVENT_DATA="$1"
local _cmd
local _tmpdir
_cmd="$(tr -d '[:space:]' <<<"$EVENT_DATA" | sed -E "s/\{[\"']command[\"']:[\"']([0-9A-Za-z+/=]*)[\"']\}/\1/" | base64 --decode)"
_tmpdir="$(mktemp)"
eval "$_cmd" 2> "$_tmpdir-stderr" > "$_tmpdir-stdout" || true
echo "{\"stdout\": \"$(cat "$_tmpdir-stdout" | base64 | tr -d '\n')\", \"stderr\": \"$(cat "$_tmpdir-stderr" | base64 | tr -d '\n')\"}" || true
rm -rf "$_tmpdir-stderr" "$_tmpdir-stdout" "$_tmpdir"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment