Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

amazon web services - AWS CLI: api gateway get-usage not returning usage of all keys

I'm trying to see usage of each API key in my usage plan. However when I run

aws apigateway get-usage --usage-plan-id ***** --start-date 2021-01-18 --end-date 2021-01-24 --profile prod --region ap-south-1 >> week04.txt 

It returns usage of only few keys. When I try to do that from the AWS management console from here

Snapshot

It gives me the usage of the same few keys. I have to manually click every single key and generate the report which is very tedious. What am I doing wrong? Please help.

question from:https://stackoverflow.com/questions/65880089/aws-cli-api-gateway-get-usage-not-returning-usage-of-all-keys

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

We can combine get-usage-plan-keys and get-usage with xargs to extract for every api key at once.

aws apigateway  get-usage-plan-keys --usage-plan-id xx44ww | jq -r ".items[].id" | xargs -I {} aws apigateway get-usage --usage-plan-id xg4j0w --key-id {} --start-date 2021-01-01 --end-date 2021-01-24 --no-paginate > output.json

Breaking it down for better readability:

Getting usage plan keys:

aws apigateway  get-usage-plan-keys --usage-plan-id xx44ww

Extracting plan keys

| jq -r ".items[].id"

loop for every api key id with xargs

aws apigateway get-usage --usage-plan-id xg4j0w --key-id {} --start-date 2021-01-01 --end-date 2021-01-24 --no-paginate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...