You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS CloudFormation中向嵌套堆栈传递CommaDelimitedList参数

解决AWS CloudFormation父模板调用子模块时的Value of property Parameters must be an object with String (or simple type) properties错误

问题场景

在AWS CloudFormation中从父模板调用子模块时,触发错误:

"Value of property Parameters must be an object with String (or simple type) properties"

父模板(Parent.yml)

AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  DirsToCreate:
    Type: List<String>
    Default: "test/injury_code,testing/cmd_injury_code,upload/exclusion"
    Description: "Comma delimited directories to create."

  ExportedSecretValue:
    Type: String
    Description: Glue Data Load db user's credential

  dataLoadType:
    Type: String
    Default: icd
    Description: Specify the type of data load

  prefix:
    Type: String
    Default: test/checking
    Description: S3 Key value 

Resources:
  IcdData:
    Type: VN::Glue::Test::MODULE
    Properties:
      DirsToCreate: !Join
        - ','
        - !Ref DirsToCreate
      dataLoadType: !Ref dataLoadType
      prefix: !Ref prefix
      ExportedSecretValue: !Ref ExportedSecretValue

嵌套堆栈模板(Nested-stack.yml)

AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  DirsToCreate:
    Type: CommaDelimitedList
    Description: "Comma delimited list of directories to create."

  dataLoadType:
    Type: String
    Description: Specify the type of data load ICD or DCD

  prefix:
    Type: String
    Description: S3 Key value for ICD or DCD

  ExportedSecretValue:
    Type: String
    Description: Glue Data Load db user's credential

Resources:
 S3CustomResource:
   Type: Custom::S3CustomResource
   Properties:
     ServiceToken: !GetAtt CreateS3FoldersLambda.Arn
     the_bucket: !Ref DataS3Bucket
     dirs_to_create: !Ref DirsToCreate

错误原因

父模板中DirsToCreate参数类型为List<String>,通过!Join拼接成字符串后传递给子模板,但子模板期望接收CommaDelimitedList类型参数。CloudFormation要求传递给嵌套模块的参数必须是字符串或简单类型,这种类型不匹配导致了错误。

解决方案

方案1:统一参数类型,直接传递列表引用

将父模板的DirsToCreate参数类型改为CommaDelimitedList,与子模板保持一致,直接传递原始引用无需拼接:

# 父模板修改后的参数与资源部分
Parameters:
  DirsToCreate:
    Type: CommaDelimitedList
    Default: "test/injury_code,testing/cmd_injury_code,upload/exclusion"
    Description: "Comma delimited directories to create."

Resources:
  IcdData:
    Type: VN::Glue::Test::MODULE
    Properties:
      DirsToCreate: !Ref DirsToCreate
      dataLoadType: !Ref dataLoadType
      prefix: !Ref prefix
      ExportedSecretValue: !Ref ExportedSecretValue

方案2:保留父模板类型,调整子模板接收逻辑

如果必须保留父模板的List<String>类型,可将子模板的DirsToCreate改为String类型,接收拼接后的字符串,再在子模板内部拆分为列表:

# 子模板修改后的参数部分
Parameters:
  DirsToCreate:
    Type: String
    Description: "Comma delimited list of directories to create."

# 子模板自定义资源部分修改
Resources:
 S3CustomResource:
   Type: Custom::S3CustomResource
   Properties:
     ServiceToken: !GetAtt CreateS3FoldersLambda.Arn
     the_bucket: !Ref DataS3Bucket
     dirs_to_create: !Split [",", !Ref DirsToCreate]

内容的提问来源于stack exchange,提问作者gcpdev-guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 22:31:08