Hey folks, I’m struggling with configuring pants t...
# general
m
Hey folks, I’m struggling with configuring pants to include my Alembic
./migrations/
directory in a pants-built
python_aws_lambda_function()
— so that I can have that lambda execute my migrations. Details in 🧵 — I’d appreciate your help!
✅ 1
✅ 1
I have a directory with
lamda_function.py
&
BUILD
files, plus a
migrations/
directory, which is exactly as Alembic sets it out. I’ve tried both of these two variants of my `BUILD`:
Copy code
python_sources(
    name="lambda",
    dependencies=[":migrations"], # <- variant 1: put the dependency on :migrations here, and not below
)

python_aws_lambda_function(
    handler="lambda_function.py:handler",
    dependencies=[":migrations"], # <- variant 2: put the dependency on :migrations here, and not above
)

poetry_requirements(
    name="poetry",
)

files(
    name="migrations",
    description="Alembic migration files",
    sources=["migrations/*.py", "migrations/**/*.py"],
)
But in both cases
pants package ::
builds a zip file without the directory
migrations
or any of its contents. I’m a bit lost, as I thought this is what the
files
target is intended for, but I have a hunch that may only pull the files into the build, and not necessarily into the lambda! (I’ll keep researching) How can I get the contents of the
migrations
directory along side wherever my
lambda_function.py
ends up? (mirroring how things are set up in my repo)
I’m a fool 😂 It’s Python and already in my pants-recognised sources! I ended up switching to this:
Copy code
python_sources(
    name="lambda",
)

python_aws_lambda_function(
    handler="lambda_function.py:handler",
    dependencies=[
        "./migrations:migrations",
        "./migrations/versions:versions",
    ]
)

poetry_requirements(
    name="poetry",
)
And making sure I have
BUILD
files containing
python_sources()
in both my
./migrations/
and
./migrations/versions
directories (exactly as auto created by
pants tailor ::
)
🎉 1
This pulls them into the right place in my built lambda 😊
h
Glad this worked out!
🙇‍♂️ 1
m
Hey @happy-kitchen-89482, I spotted a similar case where I’m missing data I’d find useful — do you think the
whatever.docker-info.json
should also be including architecture information? Mine has the form (I’m using the git sha as a tag)
Copy code
{
  "version": 1,
  "image_id": "sha256:…",
  "registries": [
    {
      "alias": null,
      "address": "<account_id>.dkr.ecr.eu-west-2.amazonaws.com",
      "repository": "<repo_name>",
      "tags": [
        {
          "template": "01b835632a5216176bd4c2f09b4ef69e9aea9628",
          "tag": "01b835632a5216176bd4c2f09b4ef69e9aea9628",
          "uses_local_alias": false,
          "name": "<account_id>.dkr.ecr.eu-west-2.amazonaws.com/<repo_name>:01b835632a5216176bd4c2f09b4ef69e9aea9628"
        }
      ]
    }
  ]
}
which doesn’t state the architecture anywhere. Even when specifying the platform directly:
Copy code
docker_image(
    name="api",
    dependencies = [":api_lambda"],
    # Only add a registry if the ECR_DOMAIN is not empty; this is a bit of a dance btw
    registries=[r for r in [env("ECR_DOMAIN", default="")] if r],
    repository="whatever",
    # Similarly here, it would be great to have access to the GIT SHA without having to pre-load an env var
    image_tags=[l for l in [env("GIT_SHA", default="")] if l],
    instructions=[
        "FROM public.ecr.aws/lambda/python:3.13-arm64",
        "COPY src.lambdas.api ${LAMBDA_TASK_ROOT}",
        "CMD [\"lambda_function.handler\"]",
    ],
    build_platform=["arm64"],
)
I’d love to be able to pull the architecture info from the
docker-info.json
, just like with the stuff above! Were you expecting this to work with the work you already completed?
h
I see no harm in adding it if it's not in there already (sounds like it isn't and my quick perusal of the source confirms)
💪 1
m
That’d be very helpful — if you had a chance! I’m happy to have a crack at it myself, but it may be a little while until I get the chance 😊
h
I don't think I'll be able to get to it for a bit. If you open an issue though, at least we won't forget.
👍 1