Apache Airflow ウェブサーバーのカスタムドメインの設定 - Amazon Managed Workflows for Apache Airflow

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Apache Airflow ウェブサーバーのカスタムドメインの設定

Amazon Managed Workflows for Apache Airflow (Amazon MWAA) では、マネージド Apache Airflow ウェブサーバーのカスタムドメインを設定できます。カスタムドメインを使用すると、Apache Airflow UI、Apache Airflow CLI、または Apache Airflow ウェブサーバーを使用して、環境の Amazon MWAA マネージド Apache Airflow ウェブサーバーにアクセスできます。

注記

カスタムドメインは、インターネットアクセスのないプライベートウェブサーバーでのみ使用できます。

Amazon MWAA のカスタムドメインのユースケース
  1. でクラウドアプリケーション間でウェブサーバードメインを共有する AWS — カスタムドメインを使用すると、生成されたサービスドメイン名ではなく、ウェブサーバーにアクセスするためのユーザーフレンドリーな URL を定義できます。このカスタムドメインを保存し、アプリケーションに環境変数として共有できます。

  2. プライベートウェブサーバーへのアクセス — インターネットにアクセスできない VPC 内のウェブサーバーのアクセスを設定する場合、カスタムドメインを使用すると URL リダイレクトのワークフローが簡素化されます。

カスタムドメインを設定する

カスタムドメイン機能を設定するには、Amazon MWAA 環境を作成または更新するときに、webserver.base_urlApache Airflow 設定を介してカスタムドメイン値を指定する必要があります。カスタムドメイン名には、次の制約が適用されます。

  • 値は、プロトコルまたはパスを含まない完全修飾ドメイン名 (FQDN) である必要があります。例えば your-custom-domain.com です。

  • Amazon MWAA は URL にパスを許可しません。例えば、 your-custom-domain.com/dags/は有効なカスタムドメイン名ではありません。

  • URL の長さは 255 文字に制限されています。

  • 空の文字列を指定すると、デフォルトでは、Amazon MWAA によって生成されたウェブサーバー URL を使用して環境が作成されます。

次の例は AWS CLI 、 を使用してカスタムウェブサーバードメイン名で環境を作成する方法を示しています。

$ aws mwaa create-environment \ --name my-mwaa-env \ --source-bucket-arn arn:aws:s3:::my-bucket \ --airflow-configuration-options '{"webserver.base_url":"my-custom-domain.com"}' \ --network-configuration '{"SubnetIds":["subnet-0123456789abcdef","subnet-fedcba9876543210"]}' \ --execution-role-arn arn:aws:iam::123456789012:role/my-execution-role

環境を作成または更新したら、カスタムドメイン経由でプライベートウェブサーバーにアクセスするためのネットワークインフラストラクチャを AWS アカウントで設定する必要があります。

デフォルトのサービス生成 URL に戻すには、プライベート環境を更新し、 webserver.base_url 設定オプションを削除します。

ネットワークインフラストラクチャをセットアップする

次の手順を使用して、 AWS アカウントのカスタムドメインで使用するために必要なネットワークインフラストラクチャを設定します。

  1. Amazon VPC エンドポイントネットワークインターフェイス (ENI) の IP アドレスを取得します。これを行うには、まず get-environmentを使用して環境WebserverVpcEndpointServiceの を検索します。

    $ aws mwaa get-environment --name your-environment-name

    成功すると、次のような出力が表示されます。

    {
        "Environment": {
            "AirflowConfigurationOptions": {},
            "AirflowVersion": "latest-version",
            "Arn": "environment-arn",
            "CreatedAt": "2024-06-01T01:00:00-00:00",
            "DagS3Path": "dags",
            .
            .
            .
            "WebserverVpcEndpointService": "web-server-vpc-endpoint-service",
            "WeeklyMaintenanceWindowStart": "TUE:21:30"
        }
    }

    WebserverVpcEndpointService 値を書き留めて、次の Amazon EC2 describe-vpc-endpoints コマンドweb-server-vpc-endpoint-serviceで に使用します。次のコマンド--filters Name=service-name,Values=web-server-vpc-endpoint-service-idで を使用します。

  2. Amazon VPC エンドポイントの詳細を取得します。このコマンドは、特定のサービス名に一致する Amazon VPC エンドポイントの詳細を取得し、エンドポイント ID と関連するネットワークインターフェイス IDs をテキスト形式で返します。

    $ aws ec2 describe-vpc-endpoints \ --filters Name=service-name,Values=web-server-vpc-endpoint-service \ --query 'VpcEndpoints[*].{EndpointId:VpcEndpointId,NetworkInterfaceIds:NetworkInterfaceIds}' \ --output text
  3. ネットワークインターフェイスの詳細を取得します。このコマンドは、前のステップで識別された Amazon VPC エンドポイントに関連付けられた各ネットワークインターフェイスのプライベート IP アドレスを取得します。

    $ for eni_id in $( aws ec2 describe-vpc-endpoints \ --filters Name=service-name,Values=service-id \ --query 'VpcEndpoints[*].NetworkInterfaceIds' \ --output text ); do aws ec2 describe-network-interfaces \ --network-interface-ids $eni_id \ --query 'NetworkInterfaces[*].PrivateIpAddresses[*].PrivateIpAddress' \ --output text done
  4. create-target-group を使用して新しいターゲットグループを作成します。このターゲットグループを使用して、ウェブサーバーの Amazon VPC エンドポイントの IP アドレスを登録します。

    $ aws elbv2 create-target-group \ --name new-target-group-namne \ --protocol HTTPS \ --port 443 \ --vpc-id web-server-vpc-id \ --target-type ip \ --health-check-protocol HTTPS \ --health-check-port 443 \ --health-check-path / \ --health-check-enabled \ --matcher 'HttpCode="200,302"'

    register-targets コマンドを使用して IP アドレスを登録します。

    $ aws elbv2 register-targets \ --target-group-arn target-group-arn \ --targets Id=ip-address-1 Id=ip-address-2
  5. ACM 証明書をリクエストします。既存の証明書を使用している場合は、このステップをスキップします。

    $ aws acm request-certificate \ --domain-name my-custom-domain.com \ --validation-method DNS
  6. Application Load Balancer を設定します。まず、ロードバランサーを作成し、次にロードバランサーのリスナーを作成します。前のステップで作成した ACM 証明書を指定します。

    $ aws elbv2 create-load-balancer \ --name my-mwaa-lb \ --type application \ --subnets subnet-id-1 subnet-id-2
    $ aws elbv2 create-listener \ --load-balancer-arn load-balancer-arn \ --protocol HTTPS \ --port 443 \ --ssl-policy ELBSecurityPolicy-2016-08 \ --certificates CertificateArn=acm-certificate-arn \ --default-actions Type=forward,TargetGroupArn=target-group-arn

    プライベートサブネットで Network Load Balancer を使用する場合は、ウェブサーバーにアクセスするための踏み台ホストまたはAWS VPN トンネルを設定します。

  7. ドメインの Route 53 を使用してホストゾーンを作成します。

    $ aws route53 create-hosted-zone --name my-custom-domain.com \ --caller-reference 1

    ドメインの A レコードを作成します。を使用してこれを行うには AWS CLI、 を使用してホストゾーン ID を取得しlist-hosted-zones-by-name、 でレコードを適用しますchange-resource-record-sets

    $ HOSTED_ZONE_ID=$(aws route53 list-hosted-zones-by-name \ --dns-name my-custom-domain.com \ --query 'HostedZones[0].Id' --output text)
    $ aws route53 change-resource-record-sets \ --hosted-zone-id $HOSTED_ZONE_ID \ --change-batch '{ "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "Name": "my-custom-domain.com", "Type": "A", "AliasTarget": { "HostedZoneId": "load-balancer-hosted-zone-id>", "DNSName": "load-balancer-dns-name", "EvaluateTargetHealth": true } } } ] }'
  8. Application Load Balancer が配置されているパブリックサブネットからの HTTPS トラフィックのみを許可することで、最小特権の原則に従ってウェブサーバー Amazon VPC エンドポイントのセキュリティグループルールを更新します。次の JSON をローカルに保存します。例えば、 などですsg-ingress-ip-permissions.json

    { "IpProtocol": "tcp", "FromPort": 443, "ToPort": 443, "UserIdGroupPairs": [ { "GroupId": "load-balancer-security-group-id" } ], "IpRanges": [ { "CidrIp": "public-subnet-1-cidr" }, { "CidrIp": "public-subnet-2-cidr" } ] }

    次の Amazon EC2 コマンドを実行して、進入セキュリティグループのルールを更新します。の JSON ファイルを指定します--ip-permissions

    $ aws ec2 authorize-security-group-ingress \ --group-id <security-group-id> \ --ip-permissions file://sg-ingress-ip-permissions.json

    次の Amazon EC2 コマンドを実行して、出力ルールを更新します。

    $ aws ec2 authorize-security-group-egress \ --group-id webserver-vpc-endpoint-security-group-id \ --protocol tcp \ --port 443 \ --source-group load-balancer-security-group-id

Amazon MWAA コンソールを開き、Apache Airflow UI に移動します。ここで使用されている Application Load Balancer ではなくプライベートサブネットに Network Application Load Balancer を設定する場合は、次のいずれかのオプションを使用してウェブサーバーにアクセスする必要があります。