Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI command to execute the API Gateway

I am trying to execute API gateway using AWS CLI in EC2 instance. I did not find any command in AWS CLI documentation. Has anyone used CLI before to execute API gateway endpoint?

Thank

like image 921
snowcoder Avatar asked Mar 11 '26 16:03

snowcoder


2 Answers

This is now possible with AWS CLI version 2.

https://docs.aws.amazon.com/cli/latest/reference/apigateway/test-invoke-method.html

Here's an example test POST using a file as the request body:

aws --region us-west-2 apigateway test-invoke-method --rest-api-id abcd1234 --resource-id abcd12 --http-method POST --path-with-query-string '/records/create' --body file://test-body.json
like image 53
SimpleSam5 Avatar answered Mar 14 '26 05:03

SimpleSam5


Sadly, there is no such API call in CLI or SDK. You have to use external tools to invoke your API.

Examples are, curl, postman or requests package in python.

For example, if you protect your API through aws_iam you can use AWSRequestsAuth in python to construct valid AWS IAM request. In postman you can also provide IAM credentials for the request to such API.

like image 37
Marcin Avatar answered Mar 14 '26 07:03

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!