如何将类型为 IResolvable 的组件添加到 CfnImageRecipe CDK 资源?

How to add an component with type IResolvable to CfnImageRecipe CDK resource?

我看到这个错误:error TS2322: Type 'string' is not assignable to type 'ComponentConfigurationProperty | IResolvable' 当我尝试使用 CDK 创建 CfnImageRecipe 时。

代码如下:

    const imageRecipe = new imagebuilder.CfnImageRecipe(this, 'MediaRecipe', {
      name: 'MediaRecipe',
      components: ["arn:aws:imagebuilder:us-west-1:aws:component/amazon-cloudwatch-agent-linux/1.0.0"],
      parentImage: 'centos:latest',
      version: '1.0.0',
      workingDirectory: '/tmp'
    });

显然它不会接受刺痛,我只是找不到任何关于此的 体面的 文档。

这似乎对我有用(至少合成)。

import * as cdk from '@aws-cdk/core';
import {CfnImageRecipe} from '@aws-cdk/aws-imagebuilder';

export class TmpStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new CfnImageRecipe(this, 'example-id', {
      name: 'MediaRecipe',
      components: [
        { 
          componentArn:"arn:aws:imagebuilder:us-west-1:aws:component/amazon-cloudwatch-agent-linux/1.0.0"
        }
      ],
      parentImage: 'centos:latest',
      version: '1.0.0',
      workingDirectory: '/tmp'
    });
  }
}

你在用什么IDE?我正在使用 WebStorm,在 Typescript 中,很多都是为您提示的代码。它可能会让探索变得更容易一些。