Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@akhkyamada

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

More than 1 year has passed since last update.

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

やりたいこと

  • 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

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

1
Help us understand the problem. What is going on with this article?
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
akhkyamada
φ(..)メモメモ

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?