简体   繁体   中英

AWS CDK Custom Resource Creation

I have a custom resource in AWS YAML format, for which I want to create AWS CDK code. I am able to add condition and ServiceToken using AWS CDK CfnCustomResource but I can't add properties.

YAML Template

MyAmi:
Condition: UseGI
Properties:
  ServiceToken:
    Fn::ImportValue: !Join ['', [!If [ MyProd, '', 'qa-'], Prod-LookupAmiFunction]]
  AMI: {Ref: AMI}      
  appId: {Ref: AppId}
  envType: {Ref: EnvType}
  osType: {Ref: OSType}
Type: Custom::MyAmi

Corresponding AWS CDK typescript code which is working.

const MyAmi= new cfn.CfnCustomResource(this, 'MyAmi', {
  serviceToken : "DSDS"  # Just a random value but it is working



});MyAmi.cfnOptions.condition = UsemE

I want to add properties of YAML template, how could I do it.

I got it. actually, I should have used cdk.cfnResource instead of cfn.CfnCustomResource ( which most likely to work with lambda function or with SNS topic). cdk.cfnResource will let me defined any custom properties.

const MyAmi= new cdk.CfnResource(this, 'MyAmi', {
 type : "Custom::MyAmi",
 properties : {

  ServiceToken : cdk.Fn.importValue(cdk.Fn.join('',[cdk.Fn.conditionIf('MyProd','','qa-').toString(),'Prod-LookupAmiFunction'])),
  bizUnit: BizUnit,
  AMI: AMI,      
  appId: AppId,
  envType: EnvType

 });LookupAmi.cfnOptions.condition = UsemE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM