【问题标题】:Object literal may only specify known properties, and 'allAwsRegions' does not exist in type 'IResolvable'对象字面量只能指定已知属性,并且“IResolvable”类型中不存在“allAwsRegions”
【发布时间】:2021-02-18 14:27:04
【问题描述】:

我目前正在使用 AWS-CDK 做一些工作,并且我正在尝试创建一个配置聚合器来聚合我所有区域配置日志的存储。我将区域作为源而不是帐户来执行此操作,因为我不允许/无法配置组织。这是我在尝试将道具添加到下面的代码时当前收到的错误。

Object literal may only specify known properties, and 'allAwsRegions' does not exist in type 'IResolvable | (IResolvable | AccountAggregationSourceProperty)[]'.ts(2322)

这是我的代码:

     const awsRegion = Aws.ACCOUNT_ID.toString()
      const awsAccountID = Aws.ACCOUNT_ID.toString()


const globalAggregatorAuth = newconfig.CfnAggregationAuthorization(this,'globalAggregatorAuth',{
        authorizedAwsRegion: awsRegion,
        authorizedAccountId: awsAccountID,
      } )
    const globalAggregator = new config.CfnConfigurationAggregator(this, 'globalAggregator', {
            configurationAggregatorName: 'globalAggregator',
            accountAggregationSources: { 
              accountIds: awsAccountID,
    
            }
        });

当我尝试使用道具 accountIds 并给它一个“awsAccountID”值时,上面的错误目前正在出现,该值是从您在上面看到的变量中分配的值。我以前没有遇到过这样的问题,非常感谢帮助!!!

【问题讨论】:

    标签: typescript aws-cdk aws-config


    【解决方案1】:

    根据the documentation

    accountIds  string[]    CfnConfigurationAggregator.AccountAggregationSourceProperty.AccountIds.
    

    换句话说,你需要像这样传入一个字符串数组:

    const globalAggregator = new config.CfnConfigurationAggregator(this, 'globalAggregator', {
        configurationAggregatorName: 'globalAggregator',
        accountAggregationSources: [{ 
            accountIds: [awsAccountID],   
        }]
    });
    

    【讨论】:

    • 当我添加时,我仍然得到如上所示的错误。
    • 输入'{ accountIds: string[]; }' 不可分配给类型 'IResolvable | (IResolvable | AccountAggregationSourceProperty)[] |不明确的'。对象字面量只能指定已知属性,并且 'accountIds' 不存在于类型 'IResolvable | (IResolvable | AccountAggregationSourceProperty)[]'.ts(2322)
    • @aroe 我在审核后更新了答案。我认为accountAggregationSources 也需要是一个数组。
    • 完美 我也发现了这一点,很奇怪,但它有效!谢谢!
    猜你喜欢
    • 2021-09-27
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 2018-09-06
    相关资源
    最近更新 更多