Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aws cli cloudformation error seen on passing parameter value of type CommaDelimitedList

I am seeing an invalid-type error for a CommaDelimitedList parameter value. The CF runs without any errors from the console.

AWS CLI command:

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

Output:

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

AWS CLI version: 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
like image 510
Sensei Avatar asked Sep 18 '18 21:09

Sensei


2 Answers

By default, aws cli takes comma seperated value as List, hence you need to escape commas by using \ character. Please retry as per below.

aws cloudformation create-stack --stack-name agkTestUserStack --template-body file://api_user.yaml --parameters ParameterKey=CustomUserName,ParameterValue="svc_TestUser" ParameterKey=GroupAssociations,ParameterValue="Dev\,Test"
like image 117
sayboras Avatar answered Sep 20 '22 13:09

sayboras


I was also seeing the error,

Parameter validation failed: Invalid type for parameter Parameters[2].ParameterValue, value: [u'http://localhost:3000', u'https://subdomain.example.business.com'], type: , valid types:

...when I tried to INCORRECTLY pass a comma separated list of URLs as a parameter to my template, e.g.:

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

The fix for me was to wrap the value of ParameterValue in double-quotes (shown below).

The suggestion to escape the comma i.e. \, did not work for me when I provided a CommaDelimetedList of URLs. Some parameter valdation threw an error. I guess \ is not a valid character in a URL but a String property (GroupAssociation) might not care if it has a \ character in the value, although I would think the application code might.

Example template:

Parameters:
  CallbackURLs:
    Type: CommaDelimitedList

Resources:
  blahblah:
    Properties:
      SomeListProp: !Ref CallbackURLs

Example CORRECTLY passing the list parameters:

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"
like image 41
cyrf Avatar answered Sep 22 '22 13:09

cyrf