Hi team, I need an AWS Lambda to be able to conne...
# ask-metaflow
a
Hi team, I need an AWS Lambda to be able to connect to the Metaflow metadata endpoint, but it seems you aren't able to write the Metaflow config to
~/.metaflowconfig/config.json
in Lambdas. I also tried setting the config values as env variables using
os.environ
but that didn't seem to work either. Any advice?
l
I’m not the best person to answer, but you can probably write your config to some other writable location and set the METAFLOW_HOME environment variable to that new dir so that your config is picked up from the right place
a
I'll give that a try, thanks!
I saved the metaflow config file in the lambda as
/tmp/config.json
and then set
METAFLOW_HOME
as
/tmp
. But it's still using local metaflow instead of the metadata service endpoint.
a
@acoustic-van-30942 I think you need to set
METAFLOW_HOME
to
/tmp/config.json
. I have a Docker image for my CI/CD tool that runs in PRs and I set mine to
ENV METAFLOW_HOME="/root/.metaflowconfig"
to get it to work.
a
Thanks so much Yudiesh. I will give it a try!
Sadly no luck.
a
Are you using a AWS Lambda specific Docker image such as
public.ecr.aws/lambda/python:3.9
?
a
No, I'm using our own custom security hardened image based on
alpine
a
Maybe you could try
ENV METAFLOW_HOME="/root/.config"
instead?
a
Also tried that but AWS Lambda doesn't have permissions to write to
root
. I think only
tmp
is allowed.
a
Got it, since you are using a custom Docker image with Lambda have you setup the runtime interface client with it? https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-clients
a
I have, yup
I wonder if passing in the metaflow config variables as
env
variables in the lambda config would work?
Okay the above worked! So one step closer. But now I can't access the Metaflow artifacts within the Lambda. Is there any way to populate these in the
/tmp
folder instead of my lambda's working dir?
Copy code
"errorMessage": "[Errno 30] Read-only file system: '/home/app/metaflow.s3.w1lswxfk'",
  "errorType": "OSError",
a
@acoustic-van-30942 you can try `METAFLOW_ARTIFACT_LOCALROOT`which was added in this PR.
thankyou 1
a
That did the trick! Thanks Yudiesh. So close to finishing the CI/CD pipeline. Any workaround for the conda env creation in the Lambda? I tried setting
CONDA_PKGS_DIRS
and
CONDA_ENVS_PATH
to
/tmp
, but still getting this error. It's still creating the cache files to
/home/sbx_user
, which isn't writeable.
Copy code
Creating Conda environment 'torch_model'...
CondaError: Error encountered while attempting to create cache directory.
Directory: /home/sbx_user1051/.cache/conda/notices
Exception: [Errno 30] Read-only file system: '/home/sbx_user1051'
a
I have the following Conda environment variables:
Copy code
ENV CONDA_DIR /opt/conda
ENV PATH=$CONDA_DIR/bin:$PATH
Gotta make sure that it downloads it to the CONDA_DIR:
Copy code
RUN apt-get update && \
  apt-get install -y \
  unzip \
  curl \
  jq \
  git \
  wget \
  && apt-get clean \
  && curl "<https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip>" -o "awscliv2.zip" \
  && unzip awscliv2.zip \
  && ./aws/install \
  && rm -rf awscliv2.zip \
  && rm -rf /var/lib/apt/lists/* \
  && wget --quiet <https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh> -O ~/miniconda.sh \
  && /bin/bash ~/miniconda.sh -b -p /opt/conda
a
Same for me too 🙂