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?

1 Answer 1

9

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"

Sign up to request clarification or add additional context in comments.

5 Comments

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 <api-key-id> 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 does aws apigateway get-api-keys --query 'items[?name==`my-api-key-name`]' --include-values --output text --region us-east-1 return anything?
My variation of this as a bash function gist.github.com/vladgolubev/08551d4b6555d52304f6b4e9bfcd7634
aws apigateway get-api-key --api-key {keyId} --include-value --query "value" --output text
My command above will get the value of the api key. Sorry can not edit comment after 5min.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.