[英]AWS CDK Custom Resource Creation
I have a custom resource in AWS YAML format, for which I want to create AWS CDK code.我有一个 AWS YAML 格式的自定义资源,我想为其创建 AWS CDK 代码。 I am able to add condition and ServiceToken using AWS CDK CfnCustomResource but I can't add properties.我可以使用 AWS CDK CfnCustomResource 添加条件和 ServiceToken,但无法添加属性。
YAML Template YAML 模板
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.相应的 AWS CDK 打字稿代码正在运行。
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.我想添加 YAML 模板的属性,我该怎么做。
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 而不是 cfn.CfnCustomResource (它最有可能与 lambda 函数或 SNS 主题一起使用)。 cdk.cfnResource will let me defined any custom properties. cdk.cfnResource 会让我定义任何自定义属性。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.