Cannot make requests from a lambda function to private API endpoint when the IAM Auth is enabled on the API endpoint.
I have set a an API gateway with private endpoint which invokes a lambda function A. I have another lambda function B, which call the private endpoint (runs inside vpc, connects to vpc endpoint to API gateway). Without having the IAM Auth enabled for this endpoint, I could make requests succesfully from my lambda function B to the API endpoint. When I enable IAM Auth for the endpoint,the requests from my lambda function B to private API endpoint was unsuccessful (Missing Authentication Token error).The lambda function B has an IAM role with all permission to invoke API endpoint. What am I missing here?
Lambda function:
import json
import requests
def lambda_handler(event, context):
url = "https://api-id.execute-api.region.amazonaws.com/dev/pets"
headers = {"content-type": "application/json"}
response = requests.get(url, headers=headers)
print(response.text)
Resource policy on API gateway:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:region:acc-id:api-id/*"
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:region:acc-id:api-id/*/*",
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": "vpce-xxxxxxx"
}
}
}
]
}
TIA!