LoginSignup
5
0

More than 5 years have passed since last update.

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

Posted at

はじめに

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 つ以上の値を指定できるように変更される可能性などが考えられます。

なるほどなぁと思った(こなみ)

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0