pythonaws-cloudformationaws-cdkchalice

How to deploy by stage with Chalice using CDK


I can't find any examples of how to deploy by stages (environments) when deploying a Chalice app with CDK, as spelled out here? https://aws.github.io/chalice/tutorials/cdk.html

I found https://aws.github.io/chalice/topics/stages.html, but can't find any reference to CDK.

What I want to do is deploy two different cloud formation stacks, pivoting by stage. I'd like a dev cf stack, as well as a prod stack. Each should have the same shape for their resources, but of course each resource should be distinct and namespaced according to stage.


Solution

  • with an example app like follows:

    from aws_cdk import core as cdk
    from stacks.vpc_stack import VpcStack
    from stacks.rds_stack import RdsStack
    from stacks.chalice_stack import ChaliceStack
    
    app = cdk.App()
    vpc_stack = VpcStack(app, 'vpc-cdk')
    rds_stack = RdsStack(app, 'rds-cdk', vpc_stack.vpc)
    chalice = ChaliceStack(app, 'chalice-cdk', rds_stack.rds_db)
    
    app.synth()
    

    from the command line you can deploy selectively like this:

    cdk deploy chalice-cdk