Home > Software engineering >  AWS CDK add CreationPolicy to EC2 Instance
AWS CDK add CreationPolicy to EC2 Instance

Time:04-30

Question in the title, trying to figure out how to add a CreationPolicy to an ec2 instance in the cdk so that I can then send a cfn-signal command once the script finishes, to then mark the resource as create complete.

This is what I have so far, after creating the ec2 instance in the stack:

create_policy = CfnCreationPolicy(resource_signal=CfnResourceSignal(count=1, timeout="PT10M"))

I don't see a way in the docs to add that to the ec2 resource as a property. Just wondering what I should do next.

CodePudding user response:

Add a Creation Policy by setting a CfnInstance construct's cfn_options attribute.

If your EC2 instance is built with the L2 Instance construct, first use escape hatch syntax to reference its underlying L1 CfnInstance construct:

my_cfn_instance = my_instance.node.default_child

my_cfn_instance.cfn_options.creation_policy = create_policy
  • Related