Private API Gateway resource policy to allow invoke for both an IAM role & from a VPCE

Using this resource policy a private API Gateway can be restricted to be invoked by both an IAM role and a VPC endpoint.

The resource policy allows to invoke a Private API only using a particular IAM role and from VPC endpoint

Limit API invoke using both IAM Role and VPCE

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<account-id>:role/<iam-role-arn>"
            },
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:us-east-1:<account-id>:<api-id>/*"
        },
        {
            "Effect": "Deny",
            "Principal": {
                "AWS": "arn:aws:iam::<account-id>:role/<iam-role-arn>"
            },
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:us-east-1:<account-id>:<api-id>/*",
            "Condition": {
                "StringNotEquals": {
                    "aws:SourceVpce": "<vpce-id>"
                }
            }
        },
        {
            "Effect": "Deny",
            "Principal": {
                "AWS": "*"
            },
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:us-east-1:<account-id>:<api-id>/*",
            "Condition": {
                "StringNotEquals": {
                    "aws:PrincipalArn": "arn:aws:iam::<account-id>:role/<iam-role-arn>"
                }
            }
        }
    ]
}

                                


Created by:

Abhishek Agawane

Abhishek Agawane

Abhishek is a Security Consultant at Amazon Web Services with more than 9 years of industry experience. He helps organizations architect resilient, secure, and efficient cloud environments, guiding them through complex challenges and large-scale infrastructure transformations. He has helped numerous organizations enhance their cloud operations through targeted optimizations, robust architectures, and best-practice implementations.