I've been using Pants to package an AWS CDK applic...
# general
b
I've been using Pants to package an AWS CDK application into a PEX, which I then deploy to manage my AWS infrastructure. However, when I update from Pants 2.16.0a0 to 2.16.0.rc0, I consistently encounter the following error when running the PEX: "ModuleNotFoundError: No module named 'aws_cdk.asset_awscli_v1'" I've kept all third-party packages constrained to the same versions as before, so the only changes appear to be the Pants version and the PEX version used (2.1.126 -> 2.1.130). Interestingly, when I run the CDK application from a virtual environment exported by Pants, it works. Any ideas what could be causing this issue?
1
From reading the thread above more carefully, I figured out that adding
Copy code
venv_site_packages_copies=True
to the pex_binary config fixes the issue.
h
👍 1
a
@brave-hair-402 I'm thinking about using Pants for managing our CDK, how do you synth/diff/deploy a pex file? Is it fairly straight forward?
b
@acoustic-garden-40182, well. I still need to do some work on this to improve it. But right now my build file for the CDK part looks like this:
Copy code
python_sources()

resources(name="cdk_file", sources=["cdk.json"])

pex_binary(
    name="my_services-cdk",
    entry_point="app.py",
    execution_mode="venv",
    venv_site_packages_copies=True,
    dependencies=[":cdk_file"],
)
and then I run something like this in my CI/CD pipeline:
Copy code
- cd dist/src.my_services
          - unzip -p my_services-cdk.pex my_services/cdk.json > cdk.json
          - cdk deploy
I also had to change this line in cdk.json:
Copy code
"app": "./my_services-cdk.pex",
a
That's really helpful, thank you! How's it working out for you so far? Any problems?
b
Working fine. I had to spend some time refactoring the cdk code to use the docker images built by pants, instead of building them directly in cdk. But, no major issues.
a
That's good to hear. I suspect I'll need to refactor as well, I'm currently using DockerImageAssets, rather than pushing to ECR directly.