Creating Dev and Prod deployments using CDK

0

HI Guys,

New to AWS CDK, so please bear with me. I am trying to create multi-deployment CDK, wherein the Dev should be deployed to Account A and prod to Acocunt B.

I have created 2 stacks with the respective account numbers and so on.

mktd_dev_stack = Mktv2Stack(app, "Mktv2Stack-dev",

    env=cdk.Environment(account='#####', region='us-east-1'),
    stack_name = "myStack-Dev",
    
    # For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
    )

the Prod is similar with the Prod account and different name. When I run them I plan on doing

cdk deploy Mktv2Stack-dev

and simiar for prod.

I am using the cdk 2.xx on Python

What my question is, does this setup give me an ability to pass a parameter, say details which is a dict object of names and criteria for resources that will be set up ? Or is there a way for me to pass parameter/dict from app.py to my program_name.py so that I can look up values from the dict and set them to resources accordingly.

Regards Tanmay

feita há 2 anos1753 visualizações
1 Resposta
1
Resposta aceita

Hi and welcome :),

Yes, you can pass additional arguments to the class. See the following class definition as an example:

class Mktv2Stack(cdk.Stack):
    def __init__(
        self,
        scope: cdk.Construct,
        id_: str,
        *,
        database_dynamodb_billing_mode: dynamodb.BillingMode,
        api_lambda_reserved_concurrency: int,
        **kwargs: Any,
    ):

You can then call it from app.py as follows:

Mktv2Stack(
    app,
    "Mktv2Stack-dev",
    env=cdk.Environment(account=ACCOUNT, region=REGION),
    api_lambda_reserved_concurrency=constants.DEV_API_LAMBDA_RESERVED_CONCURRENCY,
    database_dynamodb_billing_mode=constants.DEV_DATABASE_DYNAMODB_BILLING_MODE,
)

I'd recommend to look at the Recommended AWS CDK project structure for Python applications blog post and Best practices for developing and deploying cloud infrastructure with the AWS CDK for additional examples and details.

AWS
Alex_P
respondido há 2 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas