Last active
September 11, 2019 14:31
-
-
Save greymd/9621f90740ec0fa05c94e3e9949f4d68 to your computer and use it in GitHub Desktop.
Run given command as is with Custom AWS Lambda Runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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