
Using this resource policy a private API Gateway can be restricted to be invoked by both an IAM role and a VPC endpoint.
{
"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>"
}
}
}
]
}