Lambda function can access the internet from Function URL but not from API Gateway

0

My lambda function runs express and is not part of a VPC. I added a Function URL and when I invoke the API the lambda function can connect to a public internet endpoint as part of its processing. But if I access the function using my API Gateway URL the express server is unable to connect to internet resources. The API Gateway doesn't have any VPC Links. Is this expected and if so why is that?

Thanks

2개 답변
1

Hi,

As described on the AWS documentation, by default Lambda functions have access to the public internet except if they have been configured with access to one of your VPCs. That is, the fact that a Lambda Function is invoked through the API Gateway has no impact on whether it can access the Internet or not.

The documentation also clarifies that network connectivity errors can result from issues with your VPC's routing configuration, security group rules, AWS Identity and Access Management (IAM) role permissions, or network address translation (NAT), or from the availability of resources such as IP addresses or network interfaces.

profile picture
전문가
답변함 한 달 전
profile pictureAWS
전문가
Uri
검토됨 한 달 전
0
수락된 답변

When you invoke a function using a Function URL, the Lambda service manages the network connection. Since your function is not in a VPC, it inherits the public internet access of the Lambda service itself. This allows your function to connect to public internet endpoints during execution.

However, Imagine if you invoke a function through an API Gateway endpoint, the network access is handled differently. By default, API Gateway operates in a private VPC endpoint by default, even without explicit VPC Links. This means it cannot directly access public internet resources unless specifically configured. Consequently, your Lambda function's Express server, invoked via API Gateway, won't be able to connect to the internet.

Let me know, if your query is resolved!

profile picture
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
  • Thanks - very clear explanation!

  • This is not completely true. It doesn't matter if you invoke the function using Function URL or API Gateway. In both cases the function runs in the service VPC and has access to the internet. Only if you attach the function to a VPC you will loose internet access.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠