Is there a way to get API's from AWS API Gateway by name instead of ID using the AWS CLI?

Viewed 2195

aws apigateway get-rest-api --rest-api-id <api_id> --> gives you a specific API but I want to know is there a way that u can get an API by its name using the aws cli.

I have already tried this command but didn't work.

aws apigateway get-rest-api --rest-api-name <api_name>
3 Answers

You can use some like this:

aws apigateway get-rest-apis --query 'items[?name==`APIGATEWAYNAME`]'

But it will return a list instead of a single element.

You can further extract ID using Json Parser utility, jq (in Linux / MAC)

api_id_extracted=$(aws apigateway get-rest-apis --query 'items[?name==`APIGATEWAYNAME`]' --output json | jq '.[0] .id')

If you want just the ID you can use:

aws apigateway get-rest-apis --query 'items[?name==`APIGATEWAYNAME`].[id]' --output text

Where APIGATEWAYNAME is the name of your API Gateway.

Related