Hi, we’re integrating Pants into an existing AWS C...
# general
h
Hi, we’re integrating Pants into an existing AWS CDK monorepo and could use some advice or reference examples. Our repo contains multiple CDK projects. Each project includes: • CDK stacks (infrastructure) • Python Lambda functions • Containerized services deployed to ECS Today, CDK builds Lambda assets and Docker images itself. Our goal is to move that responsibility to Pants: • Pants builds Lambda zip artifacts • Pants builds Docker images • CDK only references the built artifacts (image URI or asset path) and handles deployment Questions: 1. Is there a reference repo showing Pants working alongside AWS CDK (especially with Lambda)? 2. What’s the recommended separation of responsibilities between Pants (build) and CDK (deploy)? How do you avoid conflicts with CDK asset bundling? 3. What’s the best way to run
cdk synth/diff/deploy
from Pants so it uses the same hermetic environment and dependencies? ◦ Wrap CDK as a
pex_binary
? ◦ Use
pants run
targets? ◦ Define a custom plugin? 4. Has anyone structured a mono-repo with multiple CDK stacks + services under Pants? How did you define targets and dependency boundaries? We’re trying to keep builds hermetic and reproducible while avoiding duplication between CDK’s asset system and Pants’ packaging. Any examples or architectural guidance would be much appreciated. Thanks!
h
Hi! I have not used CDK personally, but from 5 minutes of reading it looks like you can point CDK at prebuilt lambda .zip files or docker images (potentially published by Pants to ECR). You can have Pants run
cdk deploy
etc either by writing a custom plugin or, probably more easily, using the
ad-hoc tool
functionality: https://www.pantsbuild.org/2.31/docs/ad-hoc-tools/integrating-new-tools-without-plugins @broad-processor-92400 might have experience, he's done a lot of work with lambdas.
w
At my #dayjob we went with cdk calling pants via subprocess. Unfortunately not share-able code but the idea is to collect all wanted package artefacts referenced in cdk code and execute pants ~once with all the targets inside the cdk script.
a
We mostly use containers and container-based lambda's due to the specific dependencies we need. Our current flow is to have pants build and push those to ecr, and have cdk reference them via tag/digest from env vars. We're not managing cdk itself with pants though. I'm hoping to work on a cdk plugin/backend for pants at some point in the future. I'd like to be able to identify which stacks/apps need to be deployed based on changes in pants-managed code i.e. using
--changed-since
rather than doing a full cdk diff of all the stacks in an app, trying to figure out expected vs unexpected changes etc. If I come up with anything I'll drop you a message, I'm happy to collaborate.
h
That's really helpful. I got some good pointers from here. I will try out the suggested approaches and keep you posted. Thank you! @worried-painter-31382 @acoustic-garden-40182 @happy-kitchen-89482