Skip to content

Instantly share code, notes, and snippets.

@stephanfuchs
Forked from weyderfs/awscli_jq_tricks.sh
Created June 10, 2024 07:06
Show Gist options
  • Save stephanfuchs/57b2efd7540432b2514b16a604e5cde8 to your computer and use it in GitHub Desktop.
Save stephanfuchs/57b2efd7540432b2514b16a604e5cde8 to your computer and use it in GitHub Desktop.

Revisions

  1. @weyderfs weyderfs revised this gist May 2, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -81,6 +81,9 @@ aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}'
    #List Transit Gateways by TagName
    aws ec2 describe-transit-gateways --region sa-east-1 | jq -r .'TransitGateways[] | .Tags[]?.Value'
    #List VPC's by name
    aws ec2 describe-vpcs --region us-east-1 | jq -r '.Vpcs[].Tags[] | select(.Key == "Name") | .Value'

    #Empty and Delete Bucket S3
    BUCKET=<bucket> ; echo $BUCKET ; aws s3 rm s3://${BUCKET} --recursive --profile dev && aws s3api delete-bucket --bucket ${BUCKET} ; echo $?

  2. @weyderfs weyderfs revised this gist Apr 30, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -72,6 +72,9 @@ aws elasticache describe-cache-clusters --region sa-east-1 | jq -r '.CacheCluste
    #List EC2 Volumes group by TagsName, VolumeId and InstanceId
    aws ec2 describe-volumes --region sa-east-1 | jq '.Volumes[] | {Name:.Tags[]?.Value,Specs:([.Attachments[].VolumeId,.Attachments[].InstanceId] | join(";"))} | join(";")'
    #List Parameters Store by Name
    aws ssm describe-parameters | jq -r ".Parameters[] | .Name"
    #List S3 Buckets showing only Name
    aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}'
  3. @weyderfs weyderfs revised this gist Apr 29, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -78,6 +78,9 @@ aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}'
    #List Transit Gateways by TagName
    aws ec2 describe-transit-gateways --region sa-east-1 | jq -r .'TransitGateways[] | .Tags[]?.Value'
    #Empty and Delete Bucket S3
    BUCKET=<bucket> ; echo $BUCKET ; aws s3 rm s3://${BUCKET} --recursive --profile dev && aws s3api delete-bucket --bucket ${BUCKET} ; echo $?
    #Delete CloudFormation Stacks
    for i in $(aws cloudformation list-stacks |jq -r '.StackSummaries[] | {StackName} | join(" ")')
    do echo aws cloudformation delete-stack --stack-name $i #remove echo to delete
  4. @weyderfs weyderfs revised this gist Apr 24, 2024. No changes.
  5. @weyderfs weyderfs revised this gist Apr 24, 2024. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -50,6 +50,7 @@ ws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[].TopicArn'
    #List SQS Queues group by Name
    aws sqs list-queues --region sa-east-1 | jq -r '.QueueUrls[]' | cut -d/ -f5


    #List Load Balancers Classic group by LBName and DNSName
    aws elb describe-load-balancers --region sa-east-1 | jq -r '.LoadBalancerDescriptions[] | [.LoadBalancerName,.DNSName] | join(";")
    @@ -131,3 +132,8 @@ do
    echo $(aws sns get-topic-attributes --topic-arn $x --profile dev | jq -r '.Attributes | [.TopicArn,.KmsMasterKeyId] | join(" -> ")')
    done
    # Enable encrypt for SQS Queues previously created
    for x in $(aws sqs list-queues --profile prd --region us-east-1 | jq -r ".QueueUrls[]") ─╯
    do
    aws sqs set-queue-attributes --queue-url $x --attributes '{"KmsMasterKeyId":"....","KmsDataKeyReusePeriodSeconds":"300"}' --profile prd --region us-east-1
    done
  6. @weyderfs weyderfs revised this gist Apr 18, 2024. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,7 @@ aws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[] | [.Subs
    #List SNS Topic group by Name
    ws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[].TopicArn' | cut -d: -f6 | sort


    #List SQS Queues group by Name
    aws sqs list-queues --region sa-east-1 | jq -r '.QueueUrls[]' | cut -d/ -f5

    @@ -124,3 +125,9 @@ done
    #Get SQS Queue Name
    aws sqs list-queue-tags --region sa-east-1 --queue-url <queue-url>| jq -r '.Tags.Name'
    # Validate if all SNS Topics are encrypted with KMS
    for x in $(aws sns list-subscriptions --profile dev| jq -r '.Subscriptions[].TopicArn' | sort)
    do
    echo $(aws sns get-topic-attributes --topic-arn $x --profile dev | jq -r '.Attributes | [.TopicArn,.KmsMasterKeyId] | join(" -> ")')
    done
  7. Weyder Ferreira revised this gist Sep 20, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,9 @@ aws rds describe-db-instances --region sa-east-1 | jq -r '.DBInstances[]|[.DBIns
    #List RDS Snapshots group by SnapshotIdentifier and InstanceIdentifier
    aws rds describe-db-snapshots --region sa-east-1 | jq '.DBSnapshots[] | [.DBSnapshotIdentifier,.DBInstanceIdentifier] | join (";")'

    #List Secrets Manager
    aws secretsmanager list-secrets | jq '.SecretList[]'

    #List SNS Subscription group by ARN and Endpoint
    aws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[] | [.SubscriptionArn,.Endpoint] | join(";")'

  8. Weyder Ferreira revised this gist Jul 27, 2022. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -96,6 +96,28 @@ done
    #Get Logs filtered by Lambdas log-group
    aws logs describe-log-groups | jq -r '.logGroups[].logGroupName' | egrep -e /aws/lambda
    #Get Logs from Lambdas concatenating LogroupName + Last Log Stream of them
    #!/bin/bash
    # LOG_GROUP=$(aws logs describe-log-groups --region sa-east-1 | jq -r '.logGroups[].logGroupName' | egrep -e /aws/lambda | sort)
    # LOG_STREAM=" "
    # for x in $LOG_GROUP
    # do
    # LOG_STREAM="$LOG_STREAM$(aws logs describe-log-streams --log-group-name $x --max-items 1 --order-by LastEventTime --descending | jq -r '.logStreams[].logStreamName')"
    # done
    # read $LOG_GROUP $LOG_STREAM
    # R="$LOG_GROUP ; $LOG_STREAM"
    # echo $R
    LOG_GROUP=$(aws logs describe-log-groups --region sa-east-1| jq -r '.logGroups[].logGroupName' | egrep -e /aws/lambda | sort)
    for x in $LOG_GROUP
    do
    echo "$x;$(aws logs describe-log-streams --log-group-name $x --max-items 1 --order-by LastEventTime --descending | jq -r '.logStreams[].logStreamName')"
    done
    #Get SQS Queue Name
    aws sqs list-queue-tags --region sa-east-1 --queue-url <queue-url>| jq -r '.Tags.Name'
  9. Weyder Ferreira revised this gist Jul 27, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -93,6 +93,8 @@ do
    echo aws lambda get-policy --region sa-east-1 --function-name $x
    done
    #Get Logs filtered by Lambdas log-group
    aws logs describe-log-groups | jq -r '.logGroups[].logGroupName' | egrep -e /aws/lambda
    #Get SQS Queue Name
    aws sqs list-queue-tags --region sa-east-1 --queue-url <queue-url>| jq -r '.Tags.Name'
  10. Weyder Ferreira revised this gist Jul 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,7 @@ aws ecs describe-services --cluster <cluster-name --service <service-name> --reg
    #Get Lambda Functions and Policy from them
    for x in $(aws lambda list-functions --region sa-east-1 | jq -r '.Functions[].FunctionName')
    do
    echo aws lambda get-policy --region sa-east-1 --function-name $x
    echo aws lambda get-policy --region sa-east-1 --function-name $x
    done
  11. Weyder Ferreira revised this gist Jul 27, 2022. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -78,15 +78,22 @@ for i in $(aws cloudformation list-stacks |jq -r '.StackSummaries[] | {StackName
    do echo aws cloudformation delete-stack --stack-name $i #remove echo to delete
    done
    #Get ECS Services group by ServiceName
    aws ecs describe-services --cluster <cluster-name --service <service-name> --region sa-east-1 | jq -r '.services[] | [.serviceName,.desiredCount,.runningCount] | join(",")'
    #Get Buckets s3 and concatenating it with its policy
    for x in $(aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}')
    do
    echo aws s3api get-bucket-policy-status --bucket $x
    done
    #Get ECS Services group by ServiceName
    aws ecs describe-services --cluster <cluster-name --service <service-name> --region sa-east-1 | jq -r '.services[] | [.serviceName,.desiredCount,.runningCount] | join(",")'
    #Get Lambda Functions and Policy from them
    for x in $(aws lambda list-functions --region sa-east-1 | jq -r '.Functions[].FunctionName')
    do
    echo aws lambda get-policy --region sa-east-1 --function-name $x
    done
    #Get SQS Queue Name
    aws sqs list-queue-tags --region sa-east-1 --queue-url <queue-url>| jq -r '.Tags.Name'
  12. Weyder Ferreira revised this gist Jul 25, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -78,6 +78,9 @@ for i in $(aws cloudformation list-stacks |jq -r '.StackSummaries[] | {StackName
    do echo aws cloudformation delete-stack --stack-name $i #remove echo to delete
    done
    #Get ECS Services group by ServiceName
    aws ecs describe-services --cluster <cluster-name --service <service-name> --region sa-east-1 | jq -r '.services[] | [.serviceName,.desiredCount,.runningCount] | join(",")'
    #Get Buckets s3 and concatenating it with its policy
    for x in $(aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}')
    do
  13. Weyder Ferreira revised this gist Jul 25, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,9 @@ aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r
    #List ECS Clusters by Name
    aws ecs list-clusters --region <region> | jq -r '.clusterArns[]' | cut -d/ -f2

    #List ECS List ServiceNames by Cluster
    aws ecs list-services --cluster <cluster-name> --region sa-east-1 | jq -r '.serviceArns[]' | cut -d/ -f3

    #List EventBridge Event Buses
    aws events list-event-buses --region <region> | jq -r '.EventBuses[].Name'

  14. Weyder Ferreira revised this gist Jul 25, 2022. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -43,9 +43,12 @@ ws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[].TopicArn'
    #List SQS Queues group by Name
    aws sqs list-queues --region sa-east-1 | jq -r '.QueueUrls[]' | cut -d/ -f5

    #List Load Balancers group by LBName and DNSName
    #List Load Balancers Classic group by LBName and DNSName
    aws elb describe-load-balancers --region sa-east-1 | jq -r '.LoadBalancerDescriptions[] | [.LoadBalancerName,.DNSName] | join(";")
    #List Load Balancers V2 (NBL, ALB)
    aws elbv2 describe-load-balancers --region <region> | jq -r '.LoadBalancers[]| [.LoadBalancerName,.Type] | join(";")'
    #List API Gateways by Name
    aws apigateway get-rest-apis --region sa-east-1 | jq -r '.items[].name'
  15. Weyder Ferreira revised this gist Jul 21, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,12 @@ aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r
    #List ECS Clusters by Name
    aws ecs list-clusters --region <region> | jq -r '.clusterArns[]' | cut -d/ -f2

    #List EventBridge Event Buses
    aws events list-event-buses --region <region> | jq -r '.EventBuses[].Name'

    #List EventBridge Rules
    aws events list-rules --region us-east-1 | jq -r '.Rules[].Name'

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'

  16. Weyder Ferreira revised this gist Jul 19, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,9 @@ aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[]
    #List EC2 Snapshots
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List ECS Clusters by Name
    aws ecs list-clusters --region <region> | jq -r '.clusterArns[]' | cut -d/ -f2

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'

  17. Weyder Ferreira revised this gist Jul 19, 2022. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,11 @@
    #List AMI's group by AMIId, Description and sorting to turns easy identify duplicates
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List API Gateways by Name
    aws apigateway get-rest-apis --region sa-east-1 | jq -r '.items[].name'

    #List / Describe AWS Regions group by RegionName
    aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName'

    #List DyamoDB Table Names
    aws dynamodb list-tables --region sa-east-1 | jq -r '.TableNames[]' | sort
    #List EC2 AMI's group by ID and TagName handling with null values
    aws ec2 describe-images --owners <owner-id> --region sa-east-1 | jq '.Images[] | [.ImageId,.Tags[]?.Value] | join(";")'

    #List EC2 Instances group by Tag Name and InstanceType
    aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[] | [.InstanceType,.Tags[].Value] | join(";")'

    #List EC2 AMI's group by ID and TagName handling with null values
    aws ec2 describe-images --owners <owner-id> --region sa-east-1 | jq '.Images[] | [.ImageId,.Tags[]?.Value] | join(";")'

    #List Elasticache Clusters
    aws elasticache describe-cache-clusters --region sa-east-1 | jq -r '.CacheClusters[].CacheClusterId' | sort
    #List EC2 Snapshots
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'
    @@ -49,6 +37,18 @@ aws sqs list-queues --region sa-east-1 | jq -r '.QueueUrls[]' | cut -d/ -f5
    #List Load Balancers group by LBName and DNSName
    aws elb describe-load-balancers --region sa-east-1 | jq -r '.LoadBalancerDescriptions[] | [.LoadBalancerName,.DNSName] | join(";")
    #List API Gateways by Name
    aws apigateway get-rest-apis --region sa-east-1 | jq -r '.items[].name'
    #List / Describe AWS Regions group by RegionName
    aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName'
    #List DyamoDB Table Names
    aws dynamodb list-tables --region sa-east-1 | jq -r '.TableNames[]' | sort
    #List Elasticache Clusters
    aws elasticache describe-cache-clusters --region sa-east-1 | jq -r '.CacheClusters[].CacheClusterId' | sort
    #List EC2 Volumes group by TagsName, VolumeId and InstanceId
    aws ec2 describe-volumes --region sa-east-1 | jq '.Volumes[] | {Name:.Tags[]?.Value,Specs:([.Attachments[].VolumeId,.Attachments[].InstanceId] | join(";"))} | join(";")'
  18. Weyder Ferreira revised this gist Jul 19, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    #List AMI's group by AMIId, Description and sorting to turns easy identify duplicates
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List API Gateways by Name
    aws apigateway get-rest-apis --region sa-east-1 | jq -r '.items[].name'

    #List / Describe AWS Regions group by RegionName
    aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName'

  19. Weyder Ferreira revised this gist Jul 19, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    #List AMI's group by AMIId, Description and sorting to turns easy identify duplicates
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List / Describe AWS Regions group by RegionName
    aws ec2 describe-regions --region us-east-1 | jq -r '.Regions[].RegionName'

    #List DyamoDB Table Names
    aws dynamodb list-tables --region sa-east-1 | jq -r '.TableNames[]' | sort

  20. Weyder Ferreira revised this gist Jul 18, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,9 @@ aws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[] | [.Subs
    #List SNS Topic group by Name
    ws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[].TopicArn' | cut -d: -f6 | sort

    #List SQS Queues group by Name
    aws sqs list-queues --region sa-east-1 | jq -r '.QueueUrls[]' | cut -d/ -f5

    #List Load Balancers group by LBName and DNSName
    aws elb describe-load-balancers --region sa-east-1 | jq -r '.LoadBalancerDescriptions[] | [.LoadBalancerName,.DNSName] | join(";")
  21. Weyder Ferreira revised this gist Jul 18, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,9 @@ aws rds describe-db-snapshots --region sa-east-1 | jq '.DBSnapshots[] | [.DBSnap
    #List SNS Subscription group by ARN and Endpoint
    aws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[] | [.SubscriptionArn,.Endpoint] | join(";")'

    #List SNS Topic group by Name
    ws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[].TopicArn' | cut -d: -f6 | sort

    #List Load Balancers group by LBName and DNSName
    aws elb describe-load-balancers --region sa-east-1 | jq -r '.LoadBalancerDescriptions[] | [.LoadBalancerName,.DNSName] | join(";")
  22. Weyder Ferreira revised this gist Jul 18, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    #List AMI's group by AMIId, Description and sorting to turns easy identify duplicates
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List DyamoDB Table Names
    aws dynamodb list-tables --region sa-east-1 | jq -r '.TableNames[]' | sort

    #List EC2 Instances group by Tag Name and InstanceType
    aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[] | [.InstanceType,.Tags[].Value] | join(";")'

  23. Weyder Ferreira revised this gist Jul 18, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,9 @@ aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[]
    #List EC2 AMI's group by ID and TagName handling with null values
    aws ec2 describe-images --owners <owner-id> --region sa-east-1 | jq '.Images[] | [.ImageId,.Tags[]?.Value] | join(";")'

    #List Elasticache Clusters
    aws elasticache describe-cache-clusters --region sa-east-1 | jq -r '.CacheClusters[].CacheClusterId' | sort

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'

  24. Weyder Ferreira revised this gist Jul 15, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    #List AMI's group by AMIId, Description and sorting to turns easy identify duplicates
    aws ec2 describe-snapshots --region <the-region> --owner-id <123456789> | jq -r '.Snapshots[] | [.SnapshotId,.Description] | join(" ")' | sort

    #List EC2 Instances group by Tag Name and InstanceType
    aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[] | [.InstanceType,.Tags[].Value] | join(";")'

  25. Weyder Ferreira revised this gist Jul 14, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -47,3 +47,7 @@ for x in $(aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}')
    do
    echo aws s3api get-bucket-policy-status --bucket $x
    done
    #Get SQS Queue Name
    aws sqs list-queue-tags --region sa-east-1 --queue-url <queue-url>| jq -r '.Tags.Name'
  26. Weyder Ferreira revised this gist Jul 13, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,9 @@ aws ec2 describe-volumes --region sa-east-1 | jq '.Volumes[] | {Name:.Tags[]?.Va
    #List S3 Buckets showing only Name
    aws s3 ls | awk '{for(i=3;i<=NF;++i)print $i}'
    #List Transit Gateways by TagName
    aws ec2 describe-transit-gateways --region sa-east-1 | jq -r .'TransitGateways[] | .Tags[]?.Value'
    #Delete CloudFormation Stacks
    for i in $(aws cloudformation list-stacks |jq -r '.StackSummaries[] | {StackName} | join(" ")')
    do echo aws cloudformation delete-stack --stack-name $i #remove echo to delete
  27. Weyder Ferreira revised this gist Jul 13, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,13 @@ aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[]
    #List EC2 AMI's group by ID and TagName handling with null values
    aws ec2 describe-images --owners <owner-id> --region sa-east-1 | jq '.Images[] | [.ImageId,.Tags[]?.Value] | join(";")'

    #List IAM Roles
    aws iam list-roles | jq -r '.Roles[] | .RoleName'

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'

    ##List IAM Users
    #List IAM Roles
    aws iam list-roles | jq -r '.Roles[] | .RoleName'

    #List IAM Users
    aws iam list-users | jq -r '.Users[] | .UserName'

    #List Lambda Function by Name
  28. Weyder Ferreira revised this gist Jul 13, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[]
    #List EC2 AMI's group by ID and TagName handling with null values
    aws ec2 describe-images --owners <owner-id> --region sa-east-1 | jq '.Images[] | [.ImageId,.Tags[]?.Value] | join(";")'

    #List IAM Roles
    aws iam list-roles | jq -r '.Roles[] | .RoleName'

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'

  29. Weyder Ferreira revised this gist Jul 13, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,12 @@ aws ec2 describe-instances --region sa-east-1 | jq '.Reservations[].Instances[]
    #List EC2 AMI's group by ID and TagName handling with null values
    aws ec2 describe-images --owners <owner-id> --region sa-east-1 | jq '.Images[] | [.ImageId,.Tags[]?.Value] | join(";")'

    #List IAM Policies Custom Managed
    aws iam list-policies --scope Local | jq -r '.Policies[] | .PolicyName'

    ##List IAM Users
    aws iam list-users | jq -r '.Users[] | .UserName'

    #List Lambda Function by Name
    aws lambda list-functions --region sa-east-1 | jq -r '.Functions[] | .FunctionName'

  30. Weyder Ferreira revised this gist Jul 13, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions awscli_jq_tricks.sh
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,9 @@ aws rds describe-db-instances --region sa-east-1 | jq -r '.DBInstances[]|[.DBIns
    #List RDS Snapshots group by SnapshotIdentifier and InstanceIdentifier
    aws rds describe-db-snapshots --region sa-east-1 | jq '.DBSnapshots[] | [.DBSnapshotIdentifier,.DBInstanceIdentifier] | join (";")'

    #List SNS Subscription group by ARN and Endpoint
    aws sns list-subscriptions --region sa-east-1 | jq -r '.Subscriptions[] | [.SubscriptionArn,.Endpoint] | join(";")'

    #List Load Balancers group by LBName and DNSName
    aws elb describe-load-balancers --region sa-east-1 | jq -r '.LoadBalancerDescriptions[] | [.LoadBalancerName,.DNSName] | join(";")