Skip to content

Instantly share code, notes, and snippets.

View dbt4u's full-sized avatar

Detlef Burkhardt dbt4u

View GitHub Profile
@dbt4u
dbt4u / get-aws-service-count.sh
Last active September 24, 2019 17:09
Counts the numver of AWS-Services
curl -s https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/endpoints.json | jq -r '.partitions[0].services | keys[]' | wc -l
@dbt4u
dbt4u / get-aws-rds-endpoints.sh
Created September 24, 2019 17:07
List all AWS-RDS Instances with their endpoints
aws rds describe-db-instances | jq -r '.DBInstances[] | { (.DBInstanceIdentifier):(.Endpoint.Address + ":" + (.Endpoint.Port|tostring))}'
@dbt4u
dbt4u / get-aws-lambda-env.sh
Created September 24, 2019 17:05
List all Lambdas wither their environment variables
aws lambda list-functions | jq -r '[.Functions[]|{name: .FunctionName, env: .Environment.Variables}]|.[]|select(.env|length > 0)'
@dbt4u
dbt4u / get-aws-lambda-timouts.sh
Created September 24, 2019 17:02
List all Lambdas with their timeouts and memory size grouped by their runtime
aws lambda list-functions | jq ".Functions | group_by(.Runtime)|[.[]|{ (.[0].Runtime): [.[]|{ name: .FunctionName, timeout: .Timeout, memory: .MemorySize }] }]"
aws lambda list-functions | jq ".Functions | group_by(.Runtime)|[.[]|{ runtime:.[0].Runtime, functions:[.[]|.FunctionName] }]"
aws ec2 describe-security-groups | jq '[ .SecurityGroups[].IpPermissions[] as $a | { "ports": [($a.FromPort|tostring),($a.ToPort|tostring)]|unique, "cidr": $a.IpRanges[].CidrIp } ] | [group_by(.cidr)[] | { (.[0].cidr): [.[].ports|join("-")]|unique }] | add'
@dbt4u
dbt4u / get-aws-ec2-count.sh
Created September 24, 2019 16:56
Counts all EC2 Instances grouped by Type and State
aws ec2 describe-instances | jq -r "[[.Reservations[].Instances[]|{ state: .State.Name, type: .InstanceType }]|group_by(.state)|.[]|{state: .[0].state, types: [.[].type]|[group_by(.)|.[]|{type: .[0], count: ([.[]]|length)}] }]"
@dbt4u
dbt4u / aws-get-cost-per-service.sh
Created September 24, 2019 16:54
Get the AWS cost of this month per Service
aws ce get-cost-and-usage --time-period Start=$(date "+%Y-%m-01"),End=$(date --date="$(date +'%Y-%m-01') + 1 month - 1 second" -I) --granularity MONTHLY --metrics USAGE_QUANTITY BLENDED_COST --group-by Type=DIMENSION,Key=SERVICE | jq '[ .ResultsByTime[].Groups[] | select(.Metrics.BlendedCost.Amount > "0") | { (.Keys[0]): .Metrics.BlendedCost } ] | sort_by(.Amount) | add'
@dbt4u
dbt4u / get-aws-services.sh
Created September 24, 2019 16:50
List all AWS Services used by an account
aws ce get-cost-and-usage --time-period Start=$(date "+%Y-%m-01" -d "-1 Month"),End=$(date --date="$(date +'%Y-%m-01') - 1 second" -I) --granularity MONTHLY --metrics UsageQuantity --group-by Type=DIMENSION,Key=SERVICE | jq '.ResultsByTime[].Groups[] | select(.Metrics.UsageQuantity.Amount > 0) | .Keys[0]'
@dbt4u
dbt4u / sync.cmd
Created February 19, 2019 10:05
simple sync for git repos
git pull
git add .
git commit -m "Add new Stuff"
git push