Skip to content

Instantly share code, notes, and snippets.

@softprops
Last active March 25, 2019 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softprops/d38e34d557c58f2cfba8caf77f727833 to your computer and use it in GitHub Desktop.
Save softprops/d38e34d557c58f2cfba8caf77f727833 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# discover what values you can use for a given service in the last 3 months
#
# aws ce get-dimension-values \
# --dimension SERVICE \
# --time-period Start=$(date -v-3m +%Y-%m-01),End=$(date +%Y-%m-01) \
# --query 'DimensionValues[*].Value'
# last 3 months of ecr usage/spend
# typically this is grouped into DataTransfer-Out-Bytes and TimedStorage-ByteHrs
# where TimedStorage-ByteHrs is the majority of your spend for larger docker images
# see ecr pricing page for more details on costs https://aws.amazon.com/ecr/pricing/
aws ce get-cost-and-usage \
--time-period Start=$(date -v-3m +%Y-%m-01),End=$(date +%Y-%m-01) \
--granularity MONTHLY \
--metrics "UsageQuantity" "AmortizedCost" \
--group-by Type=DIMENSION,Key=USAGE_TYPE \
--filter "$(cat <<'EOF'
{
"Dimensions": {
"Key": "SERVICE",
"Values": ["Amazon EC2 Container Registry (ECR)"]
}
}
EOF
)" --query "ResultsByTime[*]" --output json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment