Hello, I am trying to add a `.env` file to a `pyth...
# general
c
Hello, I am trying to add a
.env
file to a
python_awslambda
. We are already using a macro so because we have some docker lambdas and some just zips. I believe I have it set up right, but I'm wondering if I should be seeing the
.env
file inside the zip or is this just something that pex handles? If I run
pants package
and then unzip the
/dist/lambda.zip
I don't see the file in there.
l
Tony, can you post a link to a repo where the issue can be reproduced (ideal if you can make one), or paste relevant bits of your BUILD file(s) and/or pants.toml?
c
Private repo so I can't post that. Let me gather some examples of my BUILD files and folder structure though. If that won't work, I can create an example repo.
šŸ‘ 1
I might have been lead to my problem simply by running pants tailor... Here is what the folder structure looks like:
Copy code
ā”œā”€ā”€ service
│   ā”œā”€ā”€ lambda_code
│   │   ā”œā”€ā”€ infrastructure.py
│   │   └── runtime
│   │       ā”œā”€ā”€ BUILD
│   │       └── lambda_function.py
ā”œā”€ā”€ config
│   ā”œā”€ā”€ __init__.py
│   └── .dev.env
And in my macro, I was adding the file like this:
Copy code
file(
        name="env",
        source=f"config/.{env('STAGE')}.env",
    )
but that seems to point to
service/lambda_code/runtime/config/.dev.env
So I need to figure out how to get the file path correctly
l
Tony, the documentation in https://www.pantsbuild.org/docs/assets#files warns that an asset added with
file
would not be added to an archive like a python_awslambda. Could this be the issue?
c
Oh yes. That's certainly relevant too. I will switch to
resource
Is there a way to traverse up a directory from the BUILD file though?
If you look at my folder structure example, the config is not in the same directory as my BUILD
l
we should move the BUILD up šŸ™‚
to the parent
or probably have BUILDs in both.
c
I probably need both
šŸ‘ 1
l
You'll also need to read the file in a slightly different way in your consuming code once you mark it as a resource. but all of that is very nicely documented in the docs/assets page
c
because there is sometimes multiple services:
Copy code
ā”œā”€ā”€ service
│   ā”œā”€ā”€ lambda_code
│   │   ā”œā”€ā”€ infrastructure.py
│   │   └── runtime
│   │       ā”œā”€ā”€ BUILD
│   │       └── lambda_function.py
ā”œā”€ā”€ service2
│   ā”œā”€ā”€ lambda_code
│   │   ā”œā”€ā”€ infrastructure.py
│   │   └── runtime
│   │       ā”œā”€ā”€ BUILD
│   │       └── lambda_function.py
ā”œā”€ā”€ config
│   ā”œā”€ā”€ __init__.py
│   └── .dev.env
and both services would need the config
l
šŸ‘ šŸ‘
c
Thanks for the help!