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년 전1669회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠