stack_ctx¶
Stack Context Management for AWS CDK Deployments
This module provides utilities for managing stack contexts across multiple environments, enabling flexible and consistent infrastructure deployment.
- class cdk_mate.stack_ctx.StackCtx(construct_id: str = REQ, stack_name: str = REQ, aws_account_id: str = REQ, aws_region: str = REQ, bsm: BotoSesManager | None = None)[source]¶
Represents the configuration and deployment context for an AWS CDK stack.
This dataclass encapsulates all necessary information for deploying a stack across different environments, providing a flexible and reusable approach to infrastructure management.
- Parameters:
construct_id – Unique identifier for the CDK construct
stack_name – Descriptive name of the stack (used in AWS CloudFormation)
aws_account_id – AWS Account ID where the stack will be deployed
aws_region – AWS Region where the stack will be deployed
bsm – Optional Boto Session Manager for AWS credentials
- classmethod make_stack_ctx_kwargs(stack_name: str, bsm: BotoSesManager) Dict[str, Any][source]¶
Create a new StackCtx instance.
- to_stack_kwargs() dict[str, Any][source]¶
Generate keyword arguments for CDK stack initialization. Your stack definition should look like this:
import aws_cdk as cdk from constructs import Construct class MyStack( cdk.Stack, ): def __init__( self, scope: Construct, id: str, stack_name: str, env: cdk.Environment, ... ): super().__init__( scope=scope, id=id, stack_name=stack_name, env=env, ... ) ...
- cdk_synth(dir_cdk: T_PATH_ARG | None = None, **kwargs: Dict[str, Any])[source]¶
Synthesize the stack using AWS CDK CLI.
- Parameters:
dir_cdk – Optional directory path for CDK synthesis context
- cdk_diff(dir_cdk: T_PATH_ARG | None = None, **kwargs: Dict[str, Any])[source]¶
Show the differences between the current stack and the deployed stack.
- Parameters:
dir_cdk – Optional directory path for CDK diff context
- cdk_mate.stack_ctx.cdk_diff_many(stack_ctx_list: list[StackCtx], dir_cdk: T_PATH_ARG | None = None, **kwargs: Dict[str, Any])[source]¶
Show the differences between multiple stacks and their deployed versions.
- Parameters:
stack_ctx_list – List of stack contexts to compare
dir_cdk – Optional directory path for CDK context
- cdk_mate.stack_ctx.cdk_deploy_many(stack_ctx_list: list[StackCtx], dir_cdk: T_PATH_ARG | None = None, prompt: bool = False, **kwargs: Dict[str, Any])[source]¶
Deploy multiple stacks in a single operation.
- Parameters:
stack_ctx_list – List of stack contexts to deploy
dir_cdk – Optional directory path for CDK deployment context
prompt – Whether to prompt for approval before deployment
- cdk_mate.stack_ctx.cdk_destroy_many(stack_ctx_list: list[StackCtx], dir_cdk: T_PATH_ARG | None = None, prompt: bool = False, **kwargs: Dict[str, Any])[source]¶
Destroy multiple stacks in a single operation.
- Parameters:
stack_ctx_list – List of stack contexts to destroy
dir_cdk – Optional directory path for CDK deployment context
prompt – Whether to prompt for approval before destruction