Skip to content

Instantly share code, notes, and snippets.

@danieljimenez
Created May 12, 2017 15:36
Show Gist options
  • Select an option

  • Save danieljimenez/2d6075622970e33beefa77fa3e04fda5 to your computer and use it in GitHub Desktop.

Select an option

Save danieljimenez/2d6075622970e33beefa77fa3e04fda5 to your computer and use it in GitHub Desktop.
#!/bin/bash
aclid=acl-d347edbc
start_rule=1000
cidr=$1
if [ -z "${cidr}" ] ; then
echo "Must provide CIDR block to DENY"
exit 1
fi
used_entries=$(aws ec2 describe-network-acls --network-acl-ids ${aclid} \
--output text | grep ENTRIES | grep False | awk '{print $6}')
rule=$start_rule
while grep $rule <(echo "${used_entries}") > /dev/null ; do
((rule+=1))
done
echo "Adding new rule: ${rule} DENY ingress from ${cidr}"
aws ec2 create-network-acl-entry --network-acl-id "${aclid}" \
--cidr-block "${cidr}" \
--rule-number ${rule} \
--rule-action deny \
--ingress \
--protocol all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment