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

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!

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Alvin’s Dew Drop Daily — Issue #68

Improve Your Code Instantly With One Simple Rule

Software Engineering Bootcamp

Create an Auto Scaling Group using the AWS Command Line Interface

Break the rules of light and make n

Happy Camping with FileMaker Pro

Localization in a better way

How Google Search Might Exist Forever

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CoderDidit (Martin Kuzdovich)

CoderDidit (Martin Kuzdovich)

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

More from Medium

AWS HTTP API directly to SQS with User Agent and IP Address

Setting up AWS CLI and CDK CLI

Simple pub-sub system on AWS

INTERACTIVE WEBPAGE THROUGH APIGATEWAY USING DYNAMODB