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

Sen*_*sei 5 amazon-web-services aws-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"
Run Code Online (Sandbox Code Playgroud)

输出:

Parameter validation failed:
Invalid type for parameter Parameters[1].ParameterValue, value: [u'Dev', u'Test'], type: <type 'list'>, valid types: <type 'basestring'>
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Apo*_*eus 6

默认情况下,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"
Run Code Online (Sandbox Code Playgroud)