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 年前檢視次數 1763 次
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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南