【问题标题】:Aws cli cloudformation error seen on passing parameter value of type CommaDelimitedList在传递 CommaDelimitedList 类型的参数值时看到 Aws cli cloudformation 错误
【发布时间】:2019-02-22 23:32:22
【问题描述】:

我看到 CommaDelimitedList 参数值的类型无效错误。 CF 从控制台运行,没有任何错误。

AWS CLI 命令:

aws cloudformation create-stack --stack-name agkTestUserStack --template-body file://api_user.yaml --parameters ParameterKey=CustomUserName,ParameterValue="svc_TestUser" ParameterKey=GroupAssociations,ParameterValue="Dev,Test"

输出:

Parameter validation failed:
Invalid type for parameter Parameters[1].ParameterValue, value: [u'Dev', u'Test'], type: <type 'list'>, valid types: <type 'basestring'>

AWS CLI 版本:aws-cli/1.15.75 Python/2.7.9 Windows/8 botocore/1.10.74

api_user.yaml:

AWSTemplateFormatVersion: 2010-09-09
Parameters:
  CustomUserName:
    Type: String
    Description: Custom user name
    Default: ''
  GroupAssociations:
    Type: CommaDelimitedList
    Description: Comma-delimited list of groups to associate the user
    Default: ''
Conditions:
  NoGroups: !Equals 
    - !Join
        - ''
        - !Ref GroupAssociations
    - '' 
  NoUserName: !Equals 
    - !Ref CustomUserName 
    - ''
Resources:
  CustomUser:
    Type: 'AWS::IAM::User'
    Properties:
      UserName: !If
        - NoUserName
        - !Ref AWS::NoValue
        - !Ref CustomUserName
      Groups: !If
        - NoGroups 
        - !Ref AWS::NoValue
        - !Ref GroupAssociations 
Outputs:
  UserName:
    Description: User instance name
    Value: !Ref CustomUser
    Export:
      Name: UserName
  UserArn:
    Description: User instance ARN
    Value: !GetAtt CustomUser.Arn
    Export:
      Name: UserArn

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-cli


    【解决方案1】:

    默认情况下,aws cli 将逗号分隔值作为 List,因此您需要使用 \ 字符来转义逗号。请按照以下步骤重试。

    aws cloudformation create-stack --stack-name agkTestUserStack --template-body file://api_user.yaml --parameters ParameterKey=CustomUserName,ParameterValue="svc_TestUser" ParameterKey=GroupAssociations,ParameterValue="Dev\,Test"
    

    【讨论】:

      【解决方案2】:

      我也看到了错误,

      参数验证失败: 参数Parameters[2].ParameterValue的类型无效,值:[u'http://localhost:3000',u'https://subdomain.example.business.com'],类型:,有效类型:

      ...当我尝试错误地将逗号分隔的 URL 列表作为参数传递给我的模板时,例如:

      aws cloudformation create-stack --stack-name STACKNAME --template-body file://cognito-idp-saml.yaml --parameters ParameterKey=CallbackURLs,ParameterValue=http://localhost:3000,https://subdomain.example.business.com
      

      我的解决方法是将ParameterValue 的值用双引号括起来(如下所示)。

      当我提供 URL 的 CommaDelimetedList 时,用于转义逗号的 suggestion\, 对我不起作用。某些参数验证引发了错误。我猜\ 不是 URL 中的有效字符,但 String 属性(GroupAssociation)可能不关心值中是否包含 \ 字符,尽管我认为应用程序代码可能会。

      示例模板:

      Parameters:
        CallbackURLs:
          Type: CommaDelimitedList
      
      Resources:
        blahblah:
          Properties:
            SomeListProp: !Ref CallbackURLs
      

      正确传递列表参数的示例:

      aws cloudformation create-stack --stack-name STACKNAME --template-body file://cognito-idp-saml.yaml --parameters ParameterKey=CallbackURLs,ParameterValue="http://localhost:3000,https://subdomain.example.business.com"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-02-02
        • 2020-11-17
        • 2017-07-12
        • 1970-01-01
        • 2019-09-05
        • 2018-11-11
        • 1970-01-01
        相关资源
        最近更新 更多