aws / aws-lambda-base-images

Apache License 2.0
648 stars 107 forks source link

C# function runs in local docker container fails when deployed as lambda #16

Open avvi00 opened 3 years ago

avvi00 commented 3 years ago

Hello,

Thank you for providing these base images.

I've created a custom image from public.ecr.aws/lambda/dotnet:core3.1.2021.06.02.11 for my lambda function.

My issue is that the function runs successfully on my local docker, but when its deployed to AWS lambda it fails.

The function simply creates a Chrome webdriver and tries to open a page. As mentioned it runs perfectly on my local docker (multiple continuous invocations), but when deployed as a Lambda, it fails with the following error:

[1623074722.885][SEVERE]: CreatePlatformSocket() failed: Address family not supported by protocol (97) 

Is there some sort of constraint in terms of opening ports etc, that is not present in the base image but is there in the AWS cloud container sandbox?

Docker version: v20.10.5 Platform: Windows 10

I have attached my full source code.

Instructions

Local run

Extract the zip

docker build .
docker run -p 9000:8080 lm-selenium
irm "http://localhost:9000/2015-03-31/functions/function/invocations" -Body '""' -Method Post

This will return "Google"

AWS run

Now deploy the image into a new ECR repository (called my-repo for example):

(Get-ECRLoginCommand).Password | docker login --username AWS --password-stdin zzzzz.dkr.ecr.ap-southeast-2.amazonaws.com
docker tag lm-selenium:latest zzzzz.dkr.ecr.ap-southeast-2.amazonaws.com/my-repo:latest
docker push zzzzz..dkr.ecr.ap-southeast-2.amazonaws.com/my-repos:latest

Create a new lambda function from the image: image

Run the lambda:

lambda-selenium-docker.zip

Why is the same error not occurring in the locally deployed container?

Thanks Avner

timdinhdotcom commented 2 years ago

keep in mind that serverless lambda can't connect to the Internet unless you configured run within your VPC and has NAT gateway.

SoccerBoyMalloy commented 1 year ago

Did you resolve this? I'm running into the same exact issue with public.ecr.aws/lambda/dotnet:6 and newer versions of Chrome and ChromeDriver. It works locally, but I get the same exact error when running in my Lambda:

[SEVERE]: CreatePlatformSocket() failed: Address family not supported by protocol (97)

I verified that it's not a networking issue by successfully hitting the same exact endpoint with an HttpClient.GetAsync(...) call.