Dilantha
Dilantha

Reputation: 1634

Ip whitelisting in AWS proxy API gateway using SAM template

Im trying to create a ip whitelist to allow access to the APi gateway. I need to do it using the sam template. Could not find any documentation regarding this. Can anyone please point me out to anything related ?

Thanks

Upvotes: 2

Views: 2238

Answers (2)

Shubham Jain
Shubham Jain

Reputation: 471

The real problem isn't about white listing using AWS SAM template, but rather how do you do it all. Once you finalise a method in general, it can be generalised into a template. I personally think creating a separate VPC for your API gateway should be a good solution. Or you could block traffic from within your application logic or AWS WAF.

EDIT : Therefore, No I don't think it could be done just via a SAM template for API gateway resource.

Upvotes: 2

Noel Llevares
Noel Llevares

Reputation: 16037

You can use AWS_IAM as your Authorization for your endpoint.

AWS_IAM Example

You can then create an IAM Policy like this which allows you to specify the IP Address.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "execute-api:Invoke"
            ],
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": "xxx.xx.xx.xx/32"
                }
            },
            "Resource": "arn:aws:execute-api:*:*:*"
        }
    ]
}

Article: http://benfoster.io/blog/aws-api-gateway-ip-restrictions

Upvotes: 3

Related Questions