Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Aamzon API Gateway accept requests only from specific host

So my problem is I have a lambda function created in AWS Lambda and is linked to the api gateway. So I want to make sure the request to the lambda function only happens throug my domain www.example.com

In this domain I make a request to run the serverless lambda function to perform a specific task.

Is there a way to ensure the api request is accepted only from my domain or host.

Also I make use of Python 2.7 to write the lambda function if there is any alternative please do suggest me, I am new to python and AWS Lambda.

like image 270
Varun K Nair Avatar asked Mar 15 '17 05:03

Varun K Nair


People also ask

How do I restrict access to private APIs to a specific VPC?

To restrict access to your private API to specific VPCs and VPC endpoints, you must add aws:SourceVpc and aws:SourceVpce conditions to your API's resource policy. For example policies, see Example: Allow private API traffic based on source VPC or VPC endpoint.

How do I deny a specific IP address from accessing API gateway?

To get started, head over to the Resources tab of your REST API as seen below. Navigate to the Resource Policy section of API gateway to add our IAM policy. To blacklist or block an IP address, you want to enter the following IAM Policy Statement. Make sure to replace the IP address with the one you want to block.


1 Answers

If you are worried about browsers making requests to your api on www.example.com, that shouldn't happen if you don't have CORS headers that allow other domains to make requests. But outside of a browser, anyone can still make requests to your APt.

You can however authenticate api calls. This can be a simple api key thats on your client or temporary credentials (call STS to get credentials for a role) to call your api. But with effort someone (look at your source code and replicate the calling mechanism) can still call your api. You could increase the level of effort required, if you only allow authenticated users (authenticated using some name/password and enforced on api gateway) to make api calls.

If you are worried about being over billed, you can setup a usage plan on your api key and restrict it to x number of calls a day/week/month.

API Gateway supports multiple authentication mechanisms

  • IAM Auth https://aws.amazon.com/premiumsupport/knowledge-center/iam-authentication-api-gateway/
  • API Key http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-setup-api-key-with-console.html
  • Cognito user pools http://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html
like image 121
Abhigna Nagaraja Avatar answered Oct 19 '22 14:10

Abhigna Nagaraja