AWS APIの1つの値しか許可されない配列

AWS APIの1つの値しか許可されない配列:


はじめに

CloudFormationでALBを作成していたら、テンプレートの構文で気になるところがあった。


ListenerRuleのConditonsのValues

AWS::ElasticLoadBalancingV2::ListenerRuleのPropertyのConditionsのValuesが、配列になってるんですよね。
公式ドキュメントを見ても、ValuesはしっかりType: List of String valuesって書いてます。

Type: AWS::ElasticLoadBalancingV2::ListenerRule 
Properties: 
  Actions: 
    - Actions 
  Conditions: 
    - Field: String 
      Values: 
        - String # 配列になっている 
  ListenerArn: String 
  Priority: Integer 
通常は下記のように1つの値を入れるのだけど(実際いままではそうやってしか使っていなかった)、

配列になってるから2つ以上の値もいけるのか?と思って試してみた。

listenerRule: 
    Type: AWS::ElasticLoadBalancingV2::ListenerRule 
    Properties: 
      Actions: 
        - TargetGroupArn: 
            Ref: targetGroup 
          Type: forward 
      Conditions: 
        - Field: path-pattern 
          Values: 
            - hogehuga # パスパターンを記述 
      ListenerArn: 
        Ref: listener 
      Priority: 1 
パスパターンを2つ記述したテンプレート

listenerRule: 
    Type: AWS::ElasticLoadBalancingV2::ListenerRule 
    Properties: 
      Actions: 
        - TargetGroupArn: 
            Ref: targetGroup 
          Type: forward 
      Conditions: 
        - Field: path-pattern 
          Values: 
            - hogehuga 
            - foobaa # 配列なのでパスパターンを追加してみる 
      ListenerArn: 
        Ref: listener 
      Priority: 1 
が、ダメ・・・!

A condition can only have '1' values (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

Fieldがホストヘッダの場合でもやってみたが、結果は同じ。

listenerRule: 
    Type: AWS::ElasticLoadBalancingV2::ListenerRule 
    Properties: 
      Actions: 
        - TargetGroupArn: 
            Ref: targetGroup 
          Type: forward 
      Conditions: 
        - Field: host-header 
          Values: 
            - hoge.example.com # ホストヘッダの場合でもやってみた 
            - huga.example.com 
      ListenerArn: 
        Ref: listener 
      Priority: 1 
公式ドキュメントに"you can specify a single host name", "you can specify a single path pattern"と書いてあるのでダメなんだろうなとは思ってた。

APIのドキュメントのほうも、文字列の配列になっている。

Values.member.N 
The condition value. 
 
~略~ 
 
Type: Array of strings 
 
Required: No 


AWSサポートに問い合わせてみた

なんで配列なのかなと思って、AWSサポートに問い合わせてみた。

以下回答の抜粋

> 私が理解できていないだけで、2つ以上の値を設定する場面があったり、その方法があったりするのでしょうか? 
 
現時点では 2 つ以上の値を設定する場面はございません。 
 
配列となっている理由といたしましては、将来的に API の拡張が行われた際に、2 つ以上の値を指定できるように変更される可能性などが考えられます。 
なるほどなぁと思った(こなみ)

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)