Created
May 12, 2021 14:08
-
-
Save baztian/2a165ed11700a615c1c0870085d652f0 to your computer and use it in GitHub Desktop.
Create a shell template to copy from one AWS SQS queue to another
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
#!/usr/bin/env bash | |
choose_queue() | |
{ | |
title=$1 | |
queues=$(aws sqs list-queues --query 'QueueUrls' --output text|tr '\t' '\n') | |
i=1 | |
items="" | |
items=$(echo -e "$queues"|sed -e 's#.*/##g' | while read p; do echo "$i $p" && i=$((i+1));done) | |
TMPFILE=$(mktemp) | |
dialog --stdout --menu "$title" 0 0 0 $items >$TMPFILE | |
idx=$(cat $TMPFILE) | |
rm $TMPFILE | |
echo -n "$queues"|sed -e "${idx}q;d" | |
} | |
queue_details() | |
{ | |
QURL=$1 | |
aws sqs get-queue-attributes --queue-url "${QURL}" --attribute-names QueueArn ApproximateNumberOfMessages ApproximateNumberOfMessagesDelayed ApproximateNumberOfMessagesNotVisible | |
} | |
SQURL=$(choose_queue "source") | |
DQURL=$(choose_queue "destination") | |
echo "Source: $(queue_details "${SQURL}")" | |
echo "Destination: $(queue_details "${DQURL}")" | |
echo | |
cat << HERE | |
SQURL=$SQURL | |
DQURL=$DQURL | |
aws sqs receive-message --max-number-of-messages 1 --queue-url \$SQURL > /tmp/out && \ | |
aws sqs send-message --queue-url \$DQURL --message-body "\$(jq -r '.Messages[].Body' /tmp/out)" && \ | |
aws sqs delete-message --queue-url \$SQURL --receipt-handle \$(jq -r '.Messages[].ReceiptHandle' /tmp/out) | |
HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment