By using AWS re:Post, you agree to the Terms of Use

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 Answers
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 picture
EXPERT
answered 2 months ago
  • 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 picture
EXPERT
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions