Unable to create an AWS managed Active directory with AWS-CDK using python

Viewed 628

I am trying to create a managed AD with AWS-CDK using python. Following is the error, raise JSIIError(resp.error) from JavaScriptError(resp.stack) jsii.errors.JSIIError: Value did not match any type in union: Missing required properties for @aws-cdk/aws-directoryservice.CfnMicrosoftAD.VpcSettingsProperty: subnetIds, vpcId, Expected object reference, got {"$jsii.map":{"subnet_ids":["subnet-12345678","subnet-12345678"],"vpc_id":"vpc-12345678"}}.Below is the code from the main stack. PS : I am new to AWS-CDK.

 from aws_cdk import core as cdk
 from aws_cdk import aws_s3
 from aws_cdk import aws_directoryservice as ad
 from aws_cdk import core
 from aws_cdk import aws_ec2 as ec2

   class ManagedADStack (core.Stack): 
       def __init__(self, scope: cdk.Construct, construct_id: str,  
        **kwargs) -> None: 
        super().__init__(scope, construct_id, **kwargs) 
 
        AD = ad.CfnMicrosoftAD(self ,
          name= "corp.example.com",
          id= "d1234",
          password= "randompass",
          vpc_settings= {
             "subnet_ids": [ "subnet-123456789" ,  "subnet-987654321"  ],
              "vpc_id": "vpc-12345678" 
             }
           )
1 Answers

Hi Kartheek and welcome to AWS-CDK.

You can use the VpcSettingsProperty as a class:

AD = ad.CfnMicrosoftAD(self ,
  name= "corp.example.com",
  id= "d1234",
  password= "randompass",
  vpc_settings= ad.CfnMicrosoftAD.VpcSettingsProperty (
     subnet_ids= [ "subnet-123456789" ,  "subnet-987654321"  ],
     vpc_id= "vpc-12345678"
     )
   )
Related