Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Last active April 29, 2025 14:33
Show Gist options
  • Save douglascayers/c04a14d79f29a57fc1de48c143374932 to your computer and use it in GitHub Desktop.
Save douglascayers/c04a14d79f29a57fc1de48c143374932 to your computer and use it in GitHub Desktop.
Delete all IoT job executions for a Thing
#!/bin/bash
# https://gist.github.com/douglascayers/c04a14d79f29a57fc1de48c143374932
set -e # exit if a command fails
set -o pipefail # exit if a piped command fails
THING_NAME=""
HELP=0
function usage() {
echo "Deletes all IoT job executions for a Thing." 1>&2
echo "" 1>&2
echo "Usage: $0 [options]" 1>&2
echo "" 1>&2
echo "Options:" 1>&2
echo " -t, --thing-name Name of the Thing" 1>&2
echo " -h, --help Show this menu" 1>&2
exit 1
}
# Parse script arguments
while [ "$1" != "" ]; do
case $1 in
-t | --thing-name)
shift
THING_NAME=$1
;;
-h | --help)
HELP=1
;;
esac
if [ "$#" -gt 0 ]; then
shift
fi
done
if [ ${HELP} == 1 ] || [ -z "${THING_NAME}" ]; then
usage
fi
for job_id in $(aws iot list-job-executions-for-thing --thing-name "${THING_NAME}" --query 'executionSummaries[].jobId' --output text); do
exec_num=$(aws iot describe-job-execution --job-id "${job_id}" --thing-name "${THING_NAME}" --query 'execution.executionNumber' --output text)
echo "deleting job execution ${job_id}..."
aws iot delete-job-execution --job-id "${job_id}" --thing-name "${THING_NAME}" --execution-number "${exec_num}" --force
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment