LoginSignup
3
1

More than 1 year has passed since last update.

Databricks on AWS デプロイ手順まとめ (顧客管理VPC)

Last updated at Posted at 2021-11-12

概要

AWS 上かつ顧客管理 VPC 上で稼働する Databricks の構築方法です。

詳細に解説されている記事が豊富にありますが (参考 URL 参照)、AWS ポータルの触り方を結構忘れていたので、Your VPC, custom で実装する手順を残しておきます。

手順

Cloudformation テンプレート

Cloudformation で構築します。
以下記事を参考にさせてもらいました。

YAML でテンプレートを書き、ローカル環境などに保存します。
今回は、

  • VPC=/22
  • Subnet=/25
  • Region=ap-northeast-1a

で設定しています。
リソース名称や設定を細かく設定したい方は適宜変更しましょう。

databricks-in-customer-managed-vpc-cloudformation-template.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Template for Databricks in Customer-managed VPC for ap-northeast-1

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/22
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: Databricks-VPC

  IGW:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: Databricks-IGW

  AttachIGW:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref VPC
      InternetGatewayId: !Ref IGW

  PrivateSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: ap-northeast-1a
      VpcId: !Ref VPC
      CidrBlock: 10.0.0.0/25
      Tags:
        - Key: Name
          Value: Databricks-Private-Subnet-a

  PrivateSubnetC:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: ap-northeast-1c
      VpcId: !Ref VPC
      CidrBlock: 10.0.1.0/25
      Tags:
        - Key: Name
          Value: Databricks-Private-Subnet-c

  PublicSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: ap-northeast-1a
      VpcId: !Ref VPC
      CidrBlock: 10.0.2.0/25
      Tags:
        - Key: Name
          Value: Databricks-Public-Subnet-a

  PublicSubnetC:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: ap-northeast-1c
      VpcId: !Ref VPC
      CidrBlock: 10.0.3.0/25
      Tags:
        - Key: Name
          Value: Databricks-Public-Subnet-c

  EIPA:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc

  NATGWA:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt EIPA.AllocationId
      ConnectivityType: public
      SubnetId: !Ref PublicSubnetA
      Tags:
        - Key: Name
          Value: Databricks-NATGW-a

  EIPC:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc

  NATGWC:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt EIPC.AllocationId
      ConnectivityType: public
      SubnetId: !Ref PublicSubnetC
      Tags:
        - Key: Name
          Value: Databricks-NATGW-c


  PublicRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: Databricks-Public-RouteTable

  PrivateRouteTableA:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: Databricks-Private-RouteTable-a

  PrivateRouteTableC:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: Databricks-Private-RouteTable-c


  PublicDefaultRoute:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref IGW

  PrivateDefaultRouteA:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTableA
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NATGWA

  PrivateDefaultRouteC:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTableC
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NATGWC


  PublicRouteTableAssocA:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PublicSubnetA
      RouteTableId: !Ref PublicRouteTable

  PublicRouteTableAssocC:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PublicSubnetC
      RouteTableId: !Ref PublicRouteTable

  PrivateRouteTableAssocA:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PrivateSubnetA
      RouteTableId: !Ref PrivateRouteTableA

  PrivateRouteTableAssocC:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PrivateSubnetC
      RouteTableId: !Ref PrivateRouteTableC


  SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupName: DataBricks-SecurityGroup
      GroupDescription: "Databricks SecurityGroup"
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: Databricks-SecurityGroup

Outputs:
  VPCID:
    Value: !Ref VPC
    Export: 
      Name: DataBricksVPCID

  PrivateSubnetIDA:
    Value: !Ref PrivateSubnetA
    Export: 
      Name: DataBricksPrivateSubnetIDA

  PrivateSubnetIDC:
    Value: !Ref PrivateSubnetC
    Export: 
      Name: DataBricksPrivateSubnetIDC

  SecurityGroupID:
    Value: !Ref SecurityGroup
    Export: 
      Name: DatabricksSecurityGroupID

スタックの作成

先ほど保存した YAML をつかって Cloudformation でスタックを作成します。

スタックの作成をクリック
image.png

YAML をアップロード、デザイナーで表示。
image.png

Databricks を稼働させる VPC 構成はこのような形に。
テンプレートは S3 に保存し、スタックの作成 (クラウドに↑アイコン)をクリック。
image.png

ステップ2へと進み、スタックの名称を指定。
image.png

ステップ3のオプション設定は行わず、ステップ4レビューへと進み、スタックの作成をクリックすると、リソースの構築が始まります。
image.png

デプロイが完了したら VPC コンソールに移動し、以下パラメータを控えておきます。

image.png

Network Configrations 作成

Databricks の Admin コンソールに移り、network configration を設定します。別のWSとこれを共有することはないので、一意に識別しやすい名称を付けておきましょう

Network Configration 名称例
databricks-in-customer-managed-vpc-nw-config-01

先ほど拾ったパラメータも入力、Add をクリック

image.png

以下で完了
image.png

Credential configuration 作成

先ほどと同様に WS をデプロイするための権限も設定していきます。config の名称を入れ、External ID は控えておきます。まだ Add は押しません。

Network Configration 名称例
databricks-in-customer-managed-vpc-credential-config-01

image.png

AWS IAM コンソールに移り、ロールを作成をクリック
image.png

アプリケーションからのアクセスを許可する必要があるので、このロールを利用できる Databricks の AWS アカウントID (414351767826) を指定、External ID を入力。ロール名をいれてロールの作成をクリック。

Credential configuration 名称例
databricks-in-customer-managed-vpc-credential-01

image.png

作成したロールを選択し、インラインポリシーを記述。

image.png

書き換える必要のある変数は4つです。

変数 概要
ACCOUNTID 顧客の AWS アカウント ID
VPCID Cloudformation で作成した VPC の ID
REGION Databricks WS をデプロイするリージョン
SECURITYGROUPID Cloudformation で作成した SG の ID

インラインポリシーのひな形はこちら。

databricks-ws-inline-policy

inline_polisy
{
    "Version": "2012-10-17",
    "Statement": [
        {
        "Sid": "NonResourceBasedPermissions",
        "Effect": "Allow",
        "Action": [
            "ec2:CancelSpotInstanceRequests",
            "ec2:DescribeAvailabilityZones",
            "ec2:DescribeIamInstanceProfileAssociations",
            "ec2:DescribeInstanceStatus",
            "ec2:DescribeInstances",
            "ec2:DescribeInternetGateways",
            "ec2:DescribeNatGateways",
            "ec2:DescribeNetworkAcls",
            "ec2:DescribePrefixLists",
            "ec2:DescribeReservedInstancesOfferings",
            "ec2:DescribeRouteTables",
            "ec2:DescribeSecurityGroups",
            "ec2:DescribeSpotInstanceRequests",
            "ec2:DescribeSpotPriceHistory",
            "ec2:DescribeSubnets",
            "ec2:DescribeVolumes",
            "ec2:DescribeVpcAttribute",
            "ec2:DescribeVpcs",
            "ec2:CreateTags",
            "ec2:DeleteTags",
            "ec2:RequestSpotInstances"
        ],
        "Resource": [
            "*"
        ]
        },
        {
        "Sid": "InstancePoolsSupport",
        "Effect": "Allow",
        "Action": [
            "ec2:AssociateIamInstanceProfile",
            "ec2:DisassociateIamInstanceProfile",
            "ec2:ReplaceIamInstanceProfileAssociation"
        ],
        "Resource": "arn:aws:ec2:REGION:ACCOUNTID:instance/*",
        "Condition": {
            "StringEquals": {
            "ec2:ResourceTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Sid": "AllowEc2RunInstancePerTag",
        "Effect": "Allow",
        "Action": "ec2:RunInstances",
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:volume/*",
            "arn:aws:ec2:REGION:ACCOUNTID:instance/*"
        ],
        "Condition": {
            "StringEquals": {
            "aws:RequestTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Sid": "AllowEc2RunInstanceImagePerTag",
        "Effect": "Allow",
        "Action": "ec2:RunInstances",
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:image/*"
        ],
        "Condition": {
            "StringEquals": {
            "aws:ResourceTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Sid": "AllowEc2RunInstancePerVPCid",
        "Effect": "Allow",
        "Action": "ec2:RunInstances",
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:network-interface/*",
            "arn:aws:ec2:REGION:ACCOUNTID:subnet/*",
            "arn:aws:ec2:REGION:ACCOUNTID:security-group/*"
        ],
        "Condition": {
            "StringEquals": {
            "ec2:vpc": "arn:aws:ec2:REGION:ACCOUNTID:vpc/VPCID"
            }
        }
        },
        {
        "Sid": "AllowEc2RunInstanceOtherResources",
        "Effect": "Allow",
        "Action": "ec2:RunInstances",
        "NotResource": [
            "arn:aws:ec2:REGION:ACCOUNTID:image/*",
            "arn:aws:ec2:REGION:ACCOUNTID:network-interface/*",
            "arn:aws:ec2:REGION:ACCOUNTID:subnet/*",
            "arn:aws:ec2:REGION:ACCOUNTID:security-group/*",
            "arn:aws:ec2:REGION:ACCOUNTID:volume/*",
            "arn:aws:ec2:REGION:ACCOUNTID:instance/*"
        ]
        },
        {
        "Sid": "EC2TerminateInstancesTag",
        "Effect": "Allow",
        "Action": [
            "ec2:TerminateInstances"
        ],
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:instance/*"
        ],
        "Condition": {
            "StringEquals": {
            "ec2:ResourceTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Sid": "EC2AttachDetachVolumeTag",
        "Effect": "Allow",
        "Action": [
            "ec2:AttachVolume",
            "ec2:DetachVolume"
        ],
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:instance/*",
            "arn:aws:ec2:REGION:ACCOUNTID:volume/*"
        ],
        "Condition": {
            "StringEquals": {
            "ec2:ResourceTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Sid": "EC2CreateVolumeByTag",
        "Effect": "Allow",
        "Action": [
            "ec2:CreateVolume"
        ],
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:volume/*"
        ],
        "Condition": {
            "StringEquals": {
            "aws:RequestTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Sid": "EC2DeleteVolumeByTag",
        "Effect": "Allow",
        "Action": [
            "ec2:DeleteVolume"
        ],
        "Resource": [
            "arn:aws:ec2:REGION:ACCOUNTID:volume/*"
        ],
        "Condition": {
            "StringEquals": {
            "ec2:ResourceTag/Vendor": "Databricks"
            }
        }
        },
        {
        "Effect": "Allow",
        "Action": [
            "iam:CreateServiceLinkedRole",
            "iam:PutRolePolicy"
        ],
        "Resource": "arn:aws:iam::*:role/aws-service-role/spot.amazonaws.com/AWSServiceRoleForEC2Spot",
        "Condition": {
            "StringLike": {
            "iam:AWSServiceName": "spot.amazonaws.com"
            }
        }
        },
        {
        "Sid": "VpcNonresourceSpecificActions",
        "Effect": "Allow",
        "Action": [
            "ec2:AuthorizeSecurityGroupEgress",
            "ec2:AuthorizeSecurityGroupIngress",
            "ec2:RevokeSecurityGroupEgress",
            "ec2:RevokeSecurityGroupIngress"
        ],
        "Resource": "arn:aws:ec2:REGION:ACCOUNTID:security-group/SECURITYGROUPID",
        "Condition": {
            "StringEquals": {
                "ec2:vpc": "arn:aws:ec2:REGION:ACCOUNTID:vpc/VPCID"
            }
        }
        }
    ]
    }

ポリシーの記述まで終わったら ロール ARN をコピーし、
image.png

Databricks コンソールの Role ARN にペースト、Add をクリック
image.png

これで Credential Configuration の設定は完了
image.png

Storage configuration 作成

最後にストレージの設定をします。Databricks の DBFS がここに収まる形です。

ストレージ名称とバケット名を入力、Generate Bucket Policy をクリックし、出力された JSON をコピーしたら、Add をクリック。

databricks-in-customer-managed-vpc-storage-01

image.png

AWS S3 コンソールへ移り、先ほど指定したバケット名で S3 を構築
image.png

バケットのバージョニングは有効化推奨です。
image.png

構築したバケットのアクセス許可からバケットポリシーの編集と進み、
image.png

先ほどコピーした JSON をペースト、変更の保存をクリックして完了です。
image.png

WS デプロイ

最後のステップです。

Workspace から Create Workspace と進み、
image.png

ワークスペースの名称、URL を入力、ここまでで作成した Configration 3つを選択、Save をクリック
image.png

ステータスが running になれば完成
2021-11-12_13h18_23.png

作成した WS を選択すると明細を確認できます。URL をクリックすると、
image.png

Databricks のルートアカウントでアクセスできます。
image.png

備考:デプロイがうまくいかない場合に確認すること

Credential Configuration の設定が以下で正しいかチェック
image.png

Service Control Policy でクロスアカウントアクセスを Deny しているかどうかチェック
もし Deny されているようなら Databricks がクロスアカウントの役割を引き受けられるようにホワイトリストでの登録が必要
image.png

参考 URL

トラブルシュートが必要な時は Databricks 弥生さんの記事群が参考になります。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1