10

I have a script where I want to fetch the AWS API gateway ID and API key value. So far I have been able to get the API gateway ID using the cli:

aws apigateway get-api-keys --query 'items[?name==`my-api-key-name`].id' --output text --region us-east-1

But I am unable to fetch the value of API key. I have tried the following cli, but no luck:

aws apigateway get-api-keys --query 'items[?name==`my-api-key-name`].value' --output text --region us-east-1

Can someone assist me on this please?

dmigo
  • 2,849
  • 4
  • 41
  • 62
Satya
  • 167
  • 3
  • 11

1 Answers1

7

You're missing --include-values key.

You can try this:

aws apigateway get-api-keys --query 'items[?name==`my-api-key-name`].value' --include-values --output text --region us-east-1

or this:

aws apigateway get-api-key --api-key <api-key-id> --include-value --query "value" --output text

Here you can find more info on that.

UPD: Included suggestion from @Anatolii Bivol to use --query "value"

dmigo
  • 2,849
  • 4
  • 41
  • 62
  • Thanks for looking into it @dmigo. The 'get-api-keys' does not throw an error, but it does not provide the API Key's value. The 'get-api-key' throws an error when trying to fetch the API Key value using the as it is expecting the API Key value itself. I have been able to fetch the API Key id using the 'get-api-keys' ; and then using terraform I am fetching the API Key's value by passing this api ID. – Satya Oct 21 '19 at 12:00
  • @Satya does `aws apigateway get-api-keys --query 'items[?name==\`my-api-key-name\`]' --include-values --output text --region us-east-1` return anything? – dmigo Oct 21 '19 at 12:17
  • 2
    My variation of this as a bash function https://gist.github.com/vladgolubev/08551d4b6555d52304f6b4e9bfcd7634 – Vlad Holubiev Apr 21 '21 at 15:45
  • 2
    `aws apigateway get-api-key --api-key {keyId} --include-value --query "value" --output text` – Anatol Bivol Dec 02 '21 at 12:08
  • My command above will get the value of the api key. Sorry can not edit comment after 5min. – Anatol Bivol Dec 02 '21 at 12:23