はじめに
こんにちは、KCCS デジタルプラットフォーム部の林です。
私たちの部門ではDatabricksを活用したデータ分析基盤の構築や技術検証を行なっています。
データ分析基盤の構築を行う際に他のシステム(AWSアカウント)と連携を行う要件で閉域接続のみアクセスが許可されているということがあります。
VPC内で稼働する汎用コンピュートであればPrivateLinkを構築して閉域接続することが可能ですが、Serverless Computeを利用している場合はPrivateLinkを経由して別のAWSアカウントのリソースへアクセスすることができませんでした。
しかし、最近のアップデートによりServerless ComputeでもPrivateLinkを使用した接続がサポートされるようになりました。
https://docs.databricks.com/aws/en/release-notes/product/2025/august#privatelink-connections-from-serverless-compute-to-resources-in-your-vpc-through-an-nlb-is-generally-available
今回はこの機能を利用してワークスペースが存在しているAWSアカウントとは別のAWSアカウントに存在するS3へServerless ComputeからPrivateLink経由でアクセスしてみたいと思います。
アーキテクチャ概要
この構成では、Databricks Serverless ComputeからS3への通信が完全にAWSのプライベートネットワーク内で完結します。
構築手順
以下のドキュメントを参考に設定していきます。
https://docs.databricks.com/aws/en/security/network/serverless-network-security/pl-to-internal-network
なお、AWSリソースの作成手順については概要だけ記載し、詳細な内容については割愛します。
Step 1: S3 VPC Interface Endpoint の作成
まず、VPC内にS3用のInterface Endpointを作成します。
-
VPC コンソールでEndpoint作成
# AWS CLIでの作成例 aws ec2 create-vpc-endpoint \ --vpc-id vpc-xxxxxxxxx \ --service-name com.amazonaws.region.s3 \ --vpc-endpoint-type Interface \ --subnet-ids subnet-xxxxxxxxx \ --security-group-ids sg-xxxxxxxxx \ --policy-document file://s3-endpoint-policy.json -
セキュリティグループの設定
- インバウンド: HTTPS (443) をNLBからのトラフィックを許可
- アウトバウンド: 必要に応じてS3への通信を許可
-
DNS設定の確認
- プライベートDNS名が有効になっていることを確認
-
*.s3.region.vpce.amazonaws.comの名前解決が正常に動作することを確認
Step 2: Network Load Balancer (NLB) の作成
S3 Interface EndpointへのトラフィックをルーティングするInternal NLBを作成します。
-
NLB作成
aws elbv2 create-load-balancer \ --name databricks-s3-nlb \ --scheme internal \ --type network \ --subnets subnet-xxxxxxxxx subnet-yyyyyyyyy -
Target Group作成
aws elbv2 create-target-group \ --name s3-endpoint-targets \ --protocol TCP \ --port 443 \ --vpc-id vpc-xxxxxxxxx \ --target-type ip -
S3 Interface EndpointのIPアドレスをTarget Groupに登録
# Interface EndpointのIPアドレスを取得 aws ec2 describe-network-interfaces \ --filters "Name=description,Values=*s3*" \ --query 'NetworkInterfaces[*].PrivateIpAddress' # Target Groupに登録 aws elbv2 register-targets \ --target-group-arn arn:aws:elasticloadbalancing:region:account:targetgroup/s3-endpoint-targets/xxxxxxxxx \ --targets Id=10.0.1.100,Port=443 Id=10.0.2.100,Port=443 -
Listener作成
aws elbv2 create-listener \ --load-balancer-arn arn:aws:elasticloadbalancing:region:account:loadbalancer/net/databricks-s3-nlb/xxxxxxxxx \ --protocol TCP \ --port 443 \ --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:region:account:targetgroup/s3-endpoint-targets/xxxxxxxxx
Step 3: VPC Endpoint Service の作成
NLBを使用してVPC Endpoint Serviceを作成します。
-
VPC Endpoint Service作成
aws ec2 create-vpc-endpoint-service-configuration \ --network-load-balancer-arns arn:aws:elasticloadbalancing:region:account:loadbalancer/net/databricks-s3-nlb/xxxxxxxxx \ --acceptance-required -
Databricks IAMロールの許可設定
aws ec2 modify-vpc-endpoint-service-permissions \ --service-id vpce-svc-xxxxxxxxx \ --add-allowed-principals arn:aws:iam::565502421330:role/private-connectivity-role-ap-northeast-1 -
PrivateLinkトラフィックの設定確認
- "Enforce inbound rules on PrivateLink traffic" が Off になっていることを確認
Step 4: Databricks Network Connectivity Configuration (NCC)の作成
Databricks側でNetwork Connectivity Configurationを作成します。
-
NCCオブジェクトの作成
- Databricks Account Console → Cloud resources → Network → Network Connectivity Configurations
- "Add Network Connectivity Configuration" をクリック
- 名前を入力(例:
s3-privatelink-ncc) - リージョンを選択(ワークスペースと同じリージョン)
-
Private Endpoint Ruleの作成
- 作成したNCC → Private endpoint rules タブ → "Add private endpoint rule"
- VPC Endpoint Service名を入力:
com.amazonaws.vpce.region.vpce-svc-xxxxxxxxx - FQDN設定:
*.s3.region.vpce.amazonaws.com - VPC Endpoint IDをコピーして保存
Step 5: VPC Endpoint接続の承認
AWS側でDatabricksからの接続要求を承認します。
-
接続要求の確認
aws ec2 describe-vpc-endpoint-connections \ --filters "Name=service-id,Values=vpce-svc-xxxxxxxxx" -
接続の承認
aws ec2 accept-vpc-endpoint-connections \ --service-id vpce-svc-xxxxxxxxx \ --vpc-endpoint-ids vpce-xxxxxxxxx
Step 6: 接続状態の確認
Databricks側で接続が正常に確立されたことを確認します。
-
NCC詳細ページで状態確認
- Private endpoint rules タブで Status が
ESTABLISHEDになることを確認 - 接続確立まで数分かかる場合があります
- Private endpoint rules タブで Status が
-
接続テスト
ノートブックからS3に対して接続確認を実施する(この時点ではまだワークスペースにNCCの適用はされていない)- Serverless ComputeでVPC Endpointを経由しない場合
import boto3 import os from botocore.exceptions import ClientError, NoCredentialsError def get_s3_files(bucket_name): # 環境変数を設定 os.environ['AWS_ACCESS_KEY_ID'] = "access_key_id" os.environ['AWS_SECRET_ACCESS_KEY'] = "secret_access_key" os.environ['AWS_DEFAULT_REGION'] = "region" try: s3_client = boto3.client('s3') response = s3_client.list_objects_v2(Bucket=bucket_name) if 'Contents' not in response: print(f"バケット '{bucket_name}' は空です") return print(f"バケット '{bucket_name}' のファイル一覧:") for obj in response['Contents']: print(obj['Key']) except NoCredentialsError: print("エラー: AWS認証情報が設定されていません") except ClientError as e: print(f"エラー: {e}") if __name__ == "__main__": get_s3_files("bucket-name") #接続先バケット名バケット 'bucket-name' のファイル一覧 test.txt※バケット内の情報が表示される
- Serverless ComputeでVPC Endpointを経由した場合
import boto3 import os from botocore.exceptions import ClientError, NoCredentialsError def get_s3_files(bucket_name,): # 環境変数を設定 os.environ['AWS_ACCESS_KEY_ID'] = "access_key_id" os.environ['AWS_SECRET_ACCESS_KEY'] = "secret_access_key" os.environ['AWS_DEFAULT_REGION'] = "region" # VPCエンドポイント設定 AWS_REGION = "region" vpc_endpoint_url = f"https://endpoint_url" #接続先エンドポイントのURL try: s3_client = boto3.client( 's3', region_name=AWS_REGION, endpoint_url=vpc_endpoint_url ) response = s3_client.list_objects_v2(Bucket=bucket_name) if 'Contents' not in response: print(f"バケット '{bucket_name}' は空です") return print(f"バケット '{bucket_name}' のファイル一覧:") for obj in response['Contents']: print(obj['Key']) except NoCredentialsError: print("エラー: AWS認証情報が設定されていません") except ClientError as e: print(f"エラー: {e}") if __name__ == "__main__": get_s3_files("buket-name") #接続先バケット名※この時点ではまだエンドポイントへアクセスできず、タイムアウトになる
- 汎用コンピュートでVPC Endpointを経由した場合
バケット 'bucket-name' のファイル一覧 test.txt※汎用コンピュートはVPC内で稼働しているため、Endpointへアクセスが可能
Step 7: WorkspaceへのNCC適用
作成したNCCをDatabricks Workspaceに適用します。
-
Workspace設定の更新
- Account Console → Workspaces → 対象ワークスペース選択
- "Update Workspace" をクリック
- Network Connectivity Configuration で作成したNCCを選択
- 複数のワークスペースに適用する場合は、各ワークスペースで同様の操作を実行
- 設定の反映まで数分かかることがあります
-
接続テスト
Serverless ComputeでVPC Endpointを経由した場合バケット 'bucket-name' のファイル一覧 test.txt※Serverless ComputeでもVPC endpoint経由でS3へのアクセスが可能になる
まとめ
NCCを利用することにより、Serverless ComputeからVPC Endpointを経由したアクセスが可能になりました。
今回はS3で確認しましたが、構成的にはVPC Endpointが指定できれば他のリソースでも同様に利用できると思われるので、セキュリティを保ちながら様々なリソースへアクセスすることができそうです。
