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 のカスタムドメインのユースケース
-
AWS のクラウドアプリケーション間でウェブサーバードメインを共有する — カスタムドメインを使用すると、生成されたサービスドメイン名の代わりに、ウェブサーバーにアクセスするためのユーザーフレンドリーな URL を定義できます。このカスタムドメインを保存し、アプリケーション内の環境変数として共有できます。
-
プライベートウェブサーバーへのアクセス — インターネットアクセスなしで VPC 内のウェブサーバーのアクセスを設定する場合、カスタムドメインを使用すると、URL リダイレクトのワークフローが簡素化されます。
カスタムドメインを設定する
カスタムドメイン機能を設定するには、Amazon MWAA 環境を作成または更新するときに、webserver.base_url Apache Airflow 設定を通してカスタムドメイン値を指定する必要があります。カスタムドメイン名には、次の制約が適用されます。
-
値は、プロトコルやパスのない完全修飾ドメイン名 (FQDN) である必要があります。例えば、
your-custom-domain.comです。 -
Amazon MWAA は URL 内のパスを許可しません。例えば、
your-custom-domain.com/dags/は有効なカスタムドメイン名ではありません。 -
URL の長さは、255 文字の ASCII 文字に制限されています。
-
空の文字列を指定すると、デフォルトで環境は Amazon MWAA によって生成されたウェブサーバー URL で作成されます。
次の例を使用して、AWS CLI を使用してカスタムウェブサーバードメイン名を持つ環境を作成します。
aws mwaa create-environment \ --name my-mwaa-env \ --source-bucket-arn arn:aws:s3:::amzn-s3-demo-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 アカウント のカスタムドメインで使用するために必要なネットワークインフラストラクチャを設定します。
-
Amazon VPC エンドポイントネットワークインターフェイス (ENI) の IP アドレスを取得します。これを行うには、まず
get-environmentを使用して環境の WebserverVpcEndpointServiceを検索します。aws mwaa get-environment --nameyour-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 EC2describe-vpc-endpointsコマンドのweb-server-vpc-endpoint-serviceに使用します。次のコマンドの--filters Name=service-name,Values=。web-server-vpc-endpoint-service-id -
Amazon VPC エンドポイントの詳細を取得します。このコマンドは、特定のサービス名に一致する Amazon VPC エンドポイントの詳細を取得し、エンドポイント ID と関連するネットワークインターフェイス ID をテキスト形式で返します。
aws ec2 describe-vpc-endpoints \ --filters Name=service-name,Values=web-server-vpc-endpoint-service\ --query 'VpcEndpoints[*].{EndpointId:VpcEndpointId,NetworkInterfaceIds:NetworkInterfaceIds}' \ --output text -
ネットワークインターフェイスの詳細を取得します。このコマンドは、前のステップで識別された 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 -
create-target-groupを使用して、新しい対象グループを作成します。このターゲットグループを使用して、ウェブサーバーの Amazon VPC エンドポイントの IP アドレスを登録します。aws elbv2 create-target-group \ --namenew-target-group-namne\ --protocol HTTPS \ --port 443 \ --vpc-idweb-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-arntarget-group-arn\ --targets Id=ip-address-1Id=ip-address-2 -
ACM 証明書をリクエストします。既存の証明書を使用している場合は、このステップをスキップします。
aws acm request-certificate \ --domain-namemy-custom-domain.com\ --validation-method DNS -
Application Load Balancer を設定します。まず、ロードバランサーを作成し、ロードバランサーのリスナーを作成します。前のステップで作成した ACM 証明書を指定します。
aws elbv2 create-load-balancer \ --namemy-mwaa-lb\ --type application \ --subnetssubnet-id-1subnet-id-2aws elbv2 create-listener \ --load-balancer-arnload-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 を使用する場合は、ウェブサーバーにアクセスするための 踏み台ホスト または Site-to-Site VPN トンネル を設定します。
-
ドメインの Route 53 を使用してホストゾーンを作成します。
aws route53 create-hosted-zone --name my-custom-domain.com \ --caller-reference 1ドメインの A レコードを作成します。AWS CLI を使用してこれを行うには、
list-hosted-zones-by-nameを使用してホストゾーン ID を取得し、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 } } } ] }' -
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 コマンドを実行して、セキュリティグループの Ingress ルールを更新します。
--ip-permissionsの JSON ファイルを指定します。aws ec2 authorize-security-group-ingress \ --group-id <security-group-id> \ --ip-permissions file://sg-ingress-ip-permissions.json次の Amazon EC2 コマンドを実行して、Egress ルールを更新します。
aws ec2 authorize-security-group-egress \ --group-idwebserver-vpc-endpoint-security-group-id\ --protocol tcp \ --port 443 \ --source-groupload-balancer-security-group-id
Amazon MWAA コンソールを開き、Apache Airflow UI に移動します。ここで使用する Application Load Balancer ではなく、プライベートサブネットに Network Load Balancer を設定する場合は、次のいずれかのオプションを使用してウェブサーバーにアクセスする必要があります。