How can I securely call a Python FastAPI deployed as a Lambda function, located inside a VPC, from an ECS frontend

0

How can I securely call a Python FastAPI deployed as a Lambda function, located inside a VPC, from an ECS frontend app also within the same VPC? Additionally, I want to use the function URL instead of an API Gateway to avoid the 30-second timeout limitation for specific endpoints. What steps do I need to follow to achieve this setup while maintaining the Lambda function's private accessibility within the VPC?

4 Respostas
1

First, invoking a Lambda function is always done using the public invoke API. Lambda has no way to limit the invocation from within a VPC only. When you attach a function to a VPC it only means that the network traffic originated by the Lambda function is sent inside the VPC.

Second, when you create a Lambda Function URL you actually create a public endpoint. This means that your ECS task will need to access the internet in order to invoke it (either by giving it internet access or by using a NAT gateway). You can protect the endpoint with IAM, so your task will need the appropriate IAM Role to invoke it.

Other options were mentioned above: Use the Lambda Invoke API directly from the ECS task (you will need a Lambda VPC endpoint to access that API), use a Private REST API Gateway to trigger the lambda (with the 30 second limit), or use an ALB as the front-end for the function.

profile pictureAWS
ESPECIALISTA
Uri
respondido há 10 meses
profile picture
ESPECIALISTA
avaliado há um mês
0

Hi Lalit, One option is to invoke the lambda function using AWS SDK's from the Frontend ECS application.

AWS
respondido há 10 meses
0
profile picture
respondido há 10 meses
0

Function url expose a public endpoint, so http client is not an option.

You should either use SDK, if you just want to reuse the function url(more details for authentication here: https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#:~:text=Function%20URLs%20are%20dual%20stack,must%20have%20lambda%3AInvokeFunctionUrl%20permissions.).

Alternatives are an internal ALB or private api gateway.

profile picture
ESPECIALISTA
respondido há 10 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas