-
-
Save mrloop/f033b5f9ed8e368fc6b73d9f8704a2be to your computer and use it in GitHub Desktop.
Replay lambda from DLQ message
This file contains 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
function replay_lambda() { | |
local profile=$1 | |
local fn=$2 | |
sqs_message="initialising..." | |
dlq_arn=$(aws --profile=$profile lambda get-function --function-name "$fn" | jq -r '.Configuration.DeadLetterConfig.TargetArn') | |
dlq=$(aws --profile=$profile sqs get-queue-url --queue-name "$(echo ${dlq_arn##*:})" --output=text) | |
while [ ! -z "$sqs_message" ]; do | |
sqs_message=$(aws --profile=$profile sqs receive-message --queue-url $dlq | jq -c '.') | |
if [ -z "$sqs_message" ]; then echo "No messages left on queue"; kill -INT $$; fi | |
payload=$(jq -c '.Messages[].Body' <<< "$sqs_message" | sed 's/\\"/"/g' | sed 's/\\\\"/\\"/g' | sed -e 's/^"//' -e 's/"$//') | |
receipt_handle=$(jq -r '.Messages[].ReceiptHandle' <<< $sqs_message) | |
message_id=$(jq -r '.Messages[].MessageId' <<< $sqs_message) | |
echo $payload > /tmp/lambda-request.json | |
lambda_result=$(aws --profile=$profile lambda invoke --function-name $fn --payload fileb:///tmp/lambda-request.json /dev/null | jq -r '.StatusCode') | |
aws --profile=$profile sqs delete-message --queue-url $dlq --receipt-handle $receipt_handle > /dev/null | |
echo "Replayed $message_id, status: $lambda_result" | |
done | |
rm /tmp/lambda-request.json | |
echo "All done!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment