データアナリティクス事業本部の鈴木です。
RedshiftからGlue Data Catalogへの自動マウントの一般提供開始がアナウンスされたので、Redshift Serverlessで試してみました!
この記事の内容
下記のQuerying the AWS Glue Data Catalogにて紹介されているように、Amazon Redshift RA3ノードタイプクラスタおよびAmazon Redshift Serverlessが、Glue Data Catalogへのクエリをサポートしました。
今回は、ガイドに記載の内容を簡単にですが試してみました。
この機能を使うことで、S3バケットにあるデータへクエリするための外部スキーマが不要になります。
また、プレビュー版でApache Icebergテーブルへのクエリのサポートもアナウンスされており、データレイク側で新たにサポートしているテーブルフォーマットに対しても今後対応が進むことが期待されます。
やってみた
Redshift Serverlessインスタンスの作成
以下のテンプレートをデプロイして、Redshift Serverlessインスタンスを作成しました。
CloudFormationテンプレート
AWSTemplateFormatVersion: "2010-09-09"
Description: "Redshift Serverless and VPC"
Parameters:
Env:
Type: "String"
Default: "test"
ProjectName:
Type: "String"
CidrBlock:
Description: Please type the CidrBlock.
Type: String
Default: 192.168.0.0/22
BaseCapacity:
Type: Number
Default: 8
EnhancedVpcRouting:
Type: String
AllowedValues:
- true
- false
Default: false
PubliclyAccessible:
Type: String
AllowedValues:
- true
- false
Default: true
AdminUsername:
Type: String
Default: awsuser
AdminUserPassword:
Type: String
Description: Must be 8-64 characters long. Must contain at least one uppercase letter, one lowercase letter and one number. Can be any printable ASCII character except “/”, ““”, or “@”.
NoEcho: true
MinLength: 8
MaxLength: 64
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Sub ${CidrBlock}
EnableDnsSupport: True
EnableDnsHostnames: True
InstanceTenancy: default
Tags:
- Key: Name
Value: !Sub ${ProjectName}-redshiftserverless-${Env}-VPC
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Application
Value:
Ref: AWS::StackId
- Key: Network
Value: Public
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: VPC
InternetGatewayId:
Ref: InternetGateway
PublicRouteTable:
Type: AWS::EC2::RouteTable
DependsOn: AttachGateway
Properties:
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub |
${ProjectName}-redshiftserverless-${Env}-public-rtb
- Key: Application
Value:
Ref: AWS::StackId
PublicRoute:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId:
Ref: PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: InternetGateway
Subnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
CidrBlock: !Select [ 0, !Cidr [ !GetAtt VPC.CidrBlock, 4, 8 ]]
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: VPC
AvailabilityZone: !Select [ 1, !GetAZs ]
CidrBlock: !Select [ 1, !Cidr [ !GetAtt VPC.CidrBlock, 4, 8 ]]
Subnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: VPC
AvailabilityZone: !Select [ 2, !GetAZs ]
CidrBlock: !Select [ 2, !Cidr [ !GetAtt VPC.CidrBlock, 4, 8 ]]
Subnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: Subnet1
RouteTableId:
Ref: PublicRouteTable
Subnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: Subnet2
RouteTableId:
Ref: PublicRouteTable
Subnet3RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: Subnet3
RouteTableId:
Ref: PublicRouteTable
RedshiftServerlessSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId:
Ref: VPC
GroupDescription: Marker security group for Application server.
Tags:
- Key: Name
Value: !Sub |
${ProjectName}-redshiftserverless-${Env}-sg
RedshiftServerlessRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/"
RoleName: !Sub "${ProjectName}-${Env}-redshift-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- redshift.amazonaws.com
Action: sts:AssumeRole
MaxSessionDuration: 3600
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AmazonAthenaFullAccess"
- "arn:aws:iam::aws:policy/AmazonS3FullAccess"
- "arn:aws:iam::aws:policy/AWSGlueConsoleFullAccess"
- "arn:aws:iam::aws:policy/AmazonRedshiftAllCommandsFullAccess"
Description: "Allows Redshift clusters to call AWS services on your behalf."
Tags:
- Key: "Name"
Value: !Sub "${ProjectName}-redshiftserverless-${Env}-redshift-role"
RedshiftServerlessWorkGroup:
Type: AWS::RedshiftServerless::Workgroup
Properties:
WorkgroupName: !Sub "${ProjectName}-${Env}-redshift-wg"
BaseCapacity: !Ref BaseCapacity
EnhancedVpcRouting: !Ref EnhancedVpcRouting
NamespaceName: !Ref RedshiftServerlessNamespace
PubliclyAccessible: !Ref PubliclyAccessible
SecurityGroupIds:
- !Ref RedshiftServerlessSecurityGroup
SubnetIds:
- !Ref Subnet1
- !Ref Subnet2
- !Ref Subnet3
RedshiftServerlessNamespace:
Type: AWS::RedshiftServerless::Namespace
Properties:
NamespaceName: !Sub "${ProjectName}-${Env}-redshift-ns"
AdminUsername: !Ref AdminUsername
AdminUserPassword: !Ref AdminUserPassword
DbName: !Sub "${ProjectName}-db"
IamRoles:
- !GetAtt RedshiftServerlessRole.Arn
過去のブログで使用しているテンプレートになります。
データベースへの接続
Redshift query editor v2で、Federated user
にて接続しました。使用しているIAMユーザーはGlueデータカタログが確認できるものを使用しました。
このように、データベースの配下にawsdatacatalog
が確認できました。
開いてみると、確かにGlue Data Catalogの中身が確認できました。
現状はテーブルのみが見えるようでした。
※ 何回かRedshift query editor v2で更新してみましたたが、このままでした。
クエリの発行
ガイドを参考にいくつかクエリを発行してデータカタログのテーブルが検索できるか試してみました。
データの検索
Redshift query editor v2のクエリエディタから、以下のようにクエリを実行しました。
SELECT *
FROM awsdatacatalog.Glueデータベース名.Glueテーブル名
例えば以下のようになりました。
DataCatalogの確認
SHOW
コマンドで以下を確認してみました。
- Glueデータベース
- Glueテーブル
- Glueテーブルのカラム
SHOW SCHEMAS FROM DATABASE awsdatacatalog;
SHOW TABLES FROM SCHEMA awsdatacatalog.myschema;
SHOW COLUMNS FROM TABLE awsdatacatalog.myglue.mytable;
最後に
自動的にマウントされるようになったGlue Data Catalogへ、Redshift Serverlessから検索および定義の確認を試してみました。
ゆくゆくはデータレイク側のより新しいテーブルフォーマットと連携してより便利に利用できるようになることが楽しみですね。
ご興味がある方は、ぜひテンプレートを使ってRedshift Serverlessで試してみて頂ければと思います!