首页 > 解决方案 > 如何将 IResolvable 类型的组件添加到 CfnImageRecipe CDK 资源?

问题描述

我看到了这个错误: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'
    });

显然它不会接受刺痛,我只是找不到任何像样的文档。

标签: typescriptamazon-web-servicesaws-cdk

解决方案


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

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 中,很多都是为您提示的代码。它可能会使探索变得更容易一些。


推荐阅读