Help us understand the problem. What is going on with this article?

Cloudformationでcognitoを作ったときにハマったメモ

またくだらないことでハマったのでメモ。
今思えば、普通に頭悪い。

やりたいこと

  • Cloudformation使いたい
  • ALBにCognito組み合わせたい

具体的には
1. ALBを叩きに来たアクセスをCognitoに飛ばしたい
2. Cognitoの認証をパスしたら、ALBの後ろにいるEC2へforwardさせたい

とりあえずyaml書く。

ALBとCognitoの連携は、ElasticLoadBalancingV2Listenerで指定。

(中略)
  hogeALBLISTENER:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties: 
      #Certificates: 
      #  - Certificate
      DefaultActions: 
        - AuthenticateCognitoConfig: 
              UserPoolArn: "arn:aws:cognito-idp:ap-northeast-1:xxxxx:userpool/hoge"
              UserPoolClientId: "hogeid"
              UserPoolDomain: "https://hoge.auth.amazoncognito.com"
          Type: 
            - "authenticate-cognito"
            - "forward"
          TargetGroupArn: !Ref 'hogeALBTG'

      LoadBalancerArn: !Ref 'hogeALB'
      Port: 443
      Protocol: "HTTP"

…これじゃ通らない。
今見ると、書き方がひどすぎる。。。
「cognitoの認証をパスしたら、targetgroupに向けてforwardして」を1行で書いて通るわけがない。

通る書き方

(中略)
  hogeALBLISTENER:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties: 
      Certificates: 
        - CertificateArn: "arn:aws:acm:ap-northeast-1:xxxxxxxx:certificate/hogehoge"
      DefaultActions: 
        - AuthenticateCognitoConfig: 
              UserPoolArn: "arn:aws:cognito-idp:ap-northeast-1:xxxxxxx:userpool/hogehoge"
              UserPoolClientId: "hogehoge"
              UserPoolDomain: "hogehoge.auth.com"
          Order: 1
          Type: "authenticate-cognito"
        - TargetGroupArn: !Ref 'hogeALBTG'
          Order: 2
          Type: "forward"

      LoadBalancerArn: !Ref 'hogeALB'
      Port: 443
      Protocol: "HTTPS"

ちゃんと段階踏ませる書き方をすれば通る。

  1. Cognitoで認証させる → Order :1
  2. 通ったらtargetgroupへforwardさせる → Order :2

リファレンス読んで書いてたけど、あっちこっち飛ばされたらよくわからなくなる…

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした