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

已提问 2 年前1758 查看次数
1 回答
1
已接受的回答

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
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则