在传递CommaDelimitedList类型的参数值时看到AWS CLI Cloudformation错误

时间:2018-09-18 21:33:30

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

我看到了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

2 个答案:

答案 0 :(得分:3)

默认情况下,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"

答案 1 :(得分:0)

我也看到了错误,

  

参数验证失败:   参数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"