Skip to content

Instantly share code, notes, and snippets.

@greymd greymd/function.sh
Last active Sep 11, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.