'Can you call AWS CDK in python without CLI?

Is it possible to run the AWS CDK lifecycle directly in python (or any other language), without using the cli? e.g.

app.py

    app = cdk.App()
    Stack(app, ..)
    app.synth()

    app.deploy()

run python

    python app.py   //instead of cdk deploy...

this could be useful to prepare temporary test scenarios.



Solution 1:[1]

What's possible as of today:

Programatically synth templates without cdk synth?

Yes. CDK's testing constructs work this way. Tests assert against a programatically synth-ed template.

template = Template.from_stack(processor_stack)

template.resource_count_is("AWS::SNS::Subscription", 1)

Programatically deploy apps without cdk deploy?

Not in the way the OP describes, but you can get close with the CDK's CI/CD constructs. The CDK Pipelines construct synths and deploys CDK apps programatically. Build a pipeline that builds and tears-down a testing environment on each push to your remote repository. Alternatively, a standalone CodeBuild Project can be used with commands to cdk deploy an app and perform tests when triggered by an event.

Also worth mentioning is cdk watch for rapid local development iterations. It automatically deploys incremental changes as you code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fedonev