Skip to content

Instantly share code, notes, and snippets.

@sergkondr
Last active September 2, 2020 14:16
Show Gist options
  • Save sergkondr/12a1b196edeb0821fc5dda65da8f3f95 to your computer and use it in GitHub Desktop.
Save sergkondr/12a1b196edeb0821fc5dda65da8f3f95 to your computer and use it in GitHub Desktop.
aws cli snippets
#########################################################
# Get Public IP of EC2-instances by tag:
aws ec2 describe-instances \
--profile=XXX \
--region=eu-west-1 \
--output=table \
--filter Name=tag:Name,Values=XXX \
--query 'Reservations[].Instances[].[PublicIpAddress]'
#########################################################
#
aws ec2 describe-instances \
--profile sandbox --region us-east-1 \
--filter "Name=instance-state-name,Values='running'" \
--query 'Reservations[*].Instances[*].{PublicIP:PublicIpAddress,PrivateIP:NetworkInterfaces[0].PrivateIpAddresses[0].PrivateIpAddress,MyInst:InstanceId,MyName:Tags[?Key==`Name`]|[0].Value}' \
--output table
-------------------------------------------------------------------------------
| DescribeInstances |
+----------------------+-----------------------+------------+-----------------+
| MyInst | MyName | PrivateIP | PublicIP |
+----------------------+-----------------------+------------+-----------------+
| i-04341f8831eb8a1b2 | *dev_green | 10.0.1.11 | 3.*.*.220 |
| i-0b367bdc912d1253d | *dev_blue | 10.0.1.37 | 34.*.*.188 |
+----------------------+-----------------------+------------+-----------------+
#########################################################
# Show unattached volumes
aws ec2 describe-volumes --region eu-west-1 \
--query 'Volumes[?!not_null(Attachments)].[VolumeId,AvailabilityZone]'
[
[
"vol-01bf9697f194236aa",
"eu-west-1a"
]
]
#########################################################
# Generate task-definition template
aws ecs register-task-definition --generate-cli-skeleton
#########################################################
# Find all security groups with specified IP-addresses
for region in $(aws ec2 describe-regions --region "eu-west-1" --query "Regions[*].RegionName" --output text); do
echo -n "$region: "
aws ec2 describe-security-groups --region "$region" \
--filters "Name=ip-permission.cidr,Values='0.0.0.0/0','1.1.1.1/32'" \
--query "SecurityGroups[*].GroupName"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment