Updating /etc/hosts File in Lambda Container

0

I've created a lambda container image from an aws public image "public.ecr.aws/lambda/python:3.9". I need to modify the /etc/hosts file, but it doesn't seem like that is possible since the file is read only. How can a build the container image to have the hosts file modify before deploying it to the lambda?

已提問 2 年前檢視次數 2099 次
2 個答案
0

Why are you trying to modify the /etc/hosts file for a container image that will be used to run a lambda function?

profile pictureAWS
專家
已回答 2 年前
profile picture
專家
已審閱 25 天前
  • I am trying to reach one of our domains that is public facing but locked down with a sign in page, but its also available internally with no signing page if your on the vpc, This container will be running some automation test against the site.

  • If you configure the lambda function to be VPC enabled, then the lambda will access this service using an ENI that is created by lambda inside the VPC. So to your domain it should appear like it is coming from a private IP address inside the VPC subnet. It should be no different from if you were to run the same code from an EC2 machine inside the VPC.

  • Yes, I added the lambda to be VPC enabled, the issue is when the test tries to run and go to the my.domain.com the lambda , resolves the domain to the public IP address since that is what we have in our DNS registrar. We also have the ability to hit the my.domain.com internally using the private IP. So ideally I would like the lambda to resolve the domain to the internal IP and since it already has access in our vpc it should work.

0

You can't change /etc/hosts when the function is running as the entire Lambda file system is read only, with the exception of the /tmp.

Saying that, you can modify it at build time. Just add a line COPY my_hosts_file /etc/hosts to the Dockerfile.

profile pictureAWS
專家
Uri
已回答 2 年前
profile picture
專家
已審閱 25 天前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南