AWS CDK tips: How to add Resource Policy to Api Gateway

CoderDidit (Martin Kuzdovich)
1 min readMar 21, 2020

--

Photo by Markus Spiske on Unsplash

How to create a AWS CDK template for API gateway that will have a Resource Policy

I needed to implement something like that recently and i was struggling to find a simple example on internet, so i decided to share my solution

API Gateway Resource Policy can be very useful if you want to improve security of Api Gateway that endpoint type is Edge

More about AWS Api Gateway Endpoint types:

AWS API gateway with endpoint type is Edge is visible from public internet by default. What i wanted to achieve is to be able to whitelist ip ranges for my Api Gateway such that only chosen ones can hit my API

You can configure that by adding Api Gateway Resource Policy

Anyway, here is the example AWS CDK code in TypeScript:

aws-cdk version used here: 1.27.0

What do you think ? Let me know in comments below to help me improve this article

Thanks for reading!

--

--

CoderDidit (Martin Kuzdovich)

I am a Software Engineer 👨‍💻 that works remotely, builds his own projects, and shares the journey online