簡體   English   中英

在傳遞CommaDelimitedList類型的參數值時看到AWS CLI Cloudformation錯誤

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

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

默認情況下,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] .ParameterValue,值:[U ' 的http://本地主機: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時\\,轉義逗號\\,建議對我不起作用。 某些參數驗證引發錯誤。 我想\\不是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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM