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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With