Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geo Restriction for API Gateway and Lambda

We have an AWS lambda function and is mapped to API gateway.

I want to enable Geo restriction on our API which is a feature in cloud front. Want it so that my lambda doesn't get hit from countries where we are not providing my services.

I believe API Gateway uses Cloud front by default but I am not able to see any related cloud front Distribution.

Was wondering what is the way to enable Geo Restriction while using API Gateway and AWS Lambda.

like image 613
Anant Bhandarkar Avatar asked Jul 29 '26 04:07

Anant Bhandarkar


1 Answers

While it seems API Gateway is using CloudFront. It is not possible to configure Geo restrictions on API Gateway itself (At least as of now). You can create a distribution with CloudFront and point the origin to API Gateway and have your Geo restriction enabled.

Additionally, you can also enable x-API-key to protect your endpoint from API-Gateway from CloudFront.

One more way of controlling from code is through analyzing CloudFront-Viewer-Country header.

like image 133
Kannaiyan Avatar answered Jul 31 '26 00:07

Kannaiyan



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!