简体   繁体   中英

How to copy AWS Glue table structure to AWS Redshift

I created new Database and the Table structure using AWS Glue without using crawler and can do the same thing, I mean create the table structure using crawler. That's not the problem, what I want is to create the same table structure in AWS Redshift based on AWS Glue table metadata .

Manually I did it with Django with Python, I get the meta data of the table and create the "CREATE TABLE ..." command and execute it. It works, I have this alternative solution already. Can we do this from AWS side or using AWS SDKs such as Boto3 ? I don't need any of the data inside table, just want to create the empty table in the AWS Redshift. Is this possible?

I also checked the AWS Redshift Spectrum. If I can create this table in AWS Redshift, then using spectrum command I can fetch data from S3 or any other resources. So do that I need the Table first.

Given you populated your Glue table with the proper schema, and all its partitions, you should be able to run queries on it with Redshift Spectrum without having to create an actual table with the CREATE TABLE... statement.

From your RedShift client/editor, create an external (Spectrum) schema pointing to your data catalog database containing your Glue tables (here, named spectrum_db ). iam_role value should be the ARN of your Redshift cluster IAM role, to which you would have added the glue:GetTable action policy.

create external schema spectrum_schema from data catalog 
database 'spectrum_db' 
iam_role 'arn:aws:iam::123456789012:role/MySpectrumRole'
create external database if not exists;

You should now be able to run queries over your external Glue tables. Only constraint doing so is that your can't SELECT * over your tables:

SELECT ... FROM spectrum_schema.Your_table

From there you should be able to move data from Spectrum to Standard Redshift more easily.

Reference(s):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM