简体   繁体   English

AWS CDK 自定义资源创建

[英]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.

相关问题 AWS CDK - 安全组创建 Typescript - AWS CDK - SecurityGroup creation Typescript AWS CDK - S3 到 Lambda:创建 S3EventSource 且存储桶返回 `Property '_resource' is missing in type` 错误 - AWS CDK - S3 to Lambda: creation of the S3EventSource with bucket returning `Property '_resource' is missing in type` error 添加对自定义资源 cdk 的依赖 - add dependency on custom resource cdk 在创建 RDS 实例后运行 AWS CDK 自定义资源以进行数据库设置 - Running AWS CDK custom resource for database setup after RDS instance is created TypeScript:AWS CDK 使用循环设置资源标签 - TypeScript: AWS CDK setting resource tags with loop AWS CDK - 如何将多个 http 方法添加到同一资源 - AWS CDK - How to add multiple http methods to the same resource AWS CDK IAM Typescript:遍历要分配的自定义策略数组 - AWS CDK IAM Typescript: iterating over an array of custom policies to assign 如何使用 AWS CDK 检查自定义 VPC 是否已存在? - How to check if a custom VPC already exist using AWS CDK? aws cdk appsync Schema Creation Status is FAILED with details: 保存架构时发生内部故障 - aws cdk appsync Schema Creation Status is FAILED with details: Internal Failure while saving the schema AWS CDK PatchBaseline - TypeScript - AWS CDK PatchBaseline - TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM