Last active
January 22, 2017 16:51
-
-
Save gdelgado/c8742a4b44643aac5bd02a9003f3c471 to your computer and use it in GitHub Desktop.
Bash to enable or disable lambda triggers.
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
#!/bin/bash | |
usage () | |
{ | |
echo "-h, --help: Display this message" | |
echo "-p, --profile: AWS Profile" | |
echo "-r, --region: AWS Region" | |
echo "-n, --name: Lambda function name" | |
echo "-e, --enable: Enable Lambda trigger (Enable or Disable)" | |
} | |
while getopts hp:r:n:e:-: OPT | |
do | |
if [[ $OPT == - ]] | |
then | |
OPT=${OPTARG%%=*} | |
if [[ "$OPT" == "$OPTARG" ]] | |
then | |
OPTARG=${*:OPTIND:1} | |
let OPTIND=$OPTIND+1 | |
else | |
OPTARG=${OPTARG#*=} | |
fi | |
fi | |
case $OPT in | |
h|help) usage; exit;; | |
p|profile) AWS_PROFILE=$OPTARG;; | |
r|region) AWS_REGION=$OPTARG;; | |
n|name) LAMBDA_NAME=$OPTARG;; | |
e|enable) ENABLE=$OPTARG;; | |
?) exit 1;; | |
*) echo "$0: illegal option -- $OPT"; exit 1;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
EVENT_SOURCE_MAPPING=$(aws lambda --region $AWS_REGION --profile $AWS_PROFILE list-event-source-mappings --function-name $LAMBDA_NAME) | |
UUID=$(echo $EVENT_SOURCE_MAPPING | jq '.EventSourceMappings[].UUID' | sed -e 's/^"//' -e 's/"$//') | |
ARRAYI=( $UUID ) | |
for ID in ${ARRAYI[@]}; do | |
if [[ $ENABLE == "disable" || $ENABLE == "Disable" ]]; then | |
ENABLE_EVENT_SOURCE=$(aws lambda --region $AWS_REGION --profile $AWS_PROFILE update-event-source-mapping --function-name $LAMBDA_NAME --uuid $ID --no-enabled) | |
echo $ENABLE_EVENT_SOURCE | |
else | |
ENABLE_EVENT_SOURCE=$(aws lambda --region $AWS_REGION --profile $AWS_PROFILE update-event-source-mapping --function-name $LAMBDA_NAME --uuid $ID --enabled) | |
echo $ENABLE_EVENT_SOURCE | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment