Skip to content

Instantly share code, notes, and snippets.

@rbalman
Created August 14, 2020 05:37
Show Gist options
  • Save rbalman/19079e96410ff59c1a65324ddfac0352 to your computer and use it in GitHub Desktop.
Save rbalman/19079e96410ff59c1a65324ddfac0352 to your computer and use it in GitHub Desktop.
Get AWS SQS queue attributes of multiple queues
#!/bin/bash
if [ -z ${AWS_PROFILE} ]
then
echo "AWS_PROFILE is not set"
exit
fi
if [ -z ${AWS_REGION} ]
then
echo "AWS_REGION is not set"
exit
fi
if [ -z ${SEPARATOR} ]
then
echo "SEPARATOR is not set"
exit
fi
ACCOUNT_ID=$(aws sts get-caller-identity --output text --query "Account" --profile ${AWS_PROFILE} --region ${AWS_REGION})
export PREFIX="https://sqs.us-east-1.amazonaws.com/${ACCOUNT_ID}"
function qattrs() {
qname="${1}"
endpoint="${PREFIX}/${qname}"
echo "ENDPOINT: ${endpoint}"
aws sqs get-queue-attributes --queue-url "${endpoint}" --attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible --profile "${AWS_PROFILE}" --region "${AWS_REGION}"
}
export -f qattrs
script=$(basename "$0")
cat /tmp/${script} | awk -F ${SEPARATOR} '{print $2}' | xargs -I {} bash -c 'qattrs "$@"' _ {}
###### INPUT
###- first-queue
###- 2nd-queue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment