How to speed up deploying with the Python CDK

0

Hi, we have a small application which is written as a set of Python Lambdas and the infrastructure is defined by the CDK. When we deploy it is now taking up to 12 minutes. Is there a way to speed this up? Possible deploy one lambda at a time?

We tried all of these options: https://cdkworkshop.com/30-python/30-hello-cdk/300-cdk-watch.html

It looks like it is the synthesis that is taking the time.

  • what are the components that are deployed ? Are you using CDK pipeline ?

3 Answers
0

Hi, if not done yet, you should probably split your cdk project in several stacks. Then , you can use 'cdk synth <stackname>' and 'cdk deploy <stackname>' to deploy one one stack.

It is usually efficient to do so when the lower levels of your infrastructure are stabilized and you need only to update the lambda definitions or their code.

It is part of CDK best practices to work with several stacks in a single CDK project: https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html

**Separate your application into multiple stacks as dictated by deployment requirements**

There is no hard and fast rule to how many stacks your application needs. 
You'll usually end up basing the decision on your deployment patterns. 
Keep in mind the following guidelines:

It's typically more straightforward to keep as many resources in the same 
stack as possible, so keep them together unless you know you want them 
separated.

Consider keeping stateful resources (like databases) in a separate stack 
from stateless resources. You can then turn on termination protection on 
the stateful stack. This way, you can freely destroy or create multiple copies 
of the stateless stack without risk of data loss.

Stateful resources are more sensitive to construct renaming—renaming 
leads to resource replacement. Therefore, don't nest stateful resources
 inside constructs that are likely to be moved around or renamed (unless 
the state can be rebuilt if lost, like a cache). This is another good reason
 to put stateful resources in their own stack.
profile pictureAWS
EXPERT
answered 10 months ago
0

Hi. There is a possibility that you are facing this bug. https://github.com/aws/jsii/issues/3389

If possible, deploying cdk sample app, which created by cdk init sample-app --language LANGUAGE with Python and TypeScript, then see the difference of cdk synth time.

If there is a significant difference, consider to change language may faster than solving this problem directly. //TypeScript will faster than any other language due to CDK architecture

profile picture
EXPERT
answered 10 months ago
0

I would need a little more information from you to diagnose the issue properly. It is possible that the problem is related to Python packages, and the lambda layer might be causing the extended CDK deployment time. I believe I have encountered a similar problem in the past, but I can't recall the solution off the top of my head. Nonetheless, I hope this information helps you navigate in the right direction.

Luke
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions