简体   繁体   English

如何在外部在 Amazon Glue 中创建数据目录?

[英]How to create a data catalog in Amazon Glue externally?

I want to create a data catalog externally in Amazon Glue.我想在 Amazon Glue 中创建外部数据目录。 Is there any way?有什么办法吗?

AWS Glue Data Catalog consists of meta information about various data sources within AWS, eg S3, DynamoDB etc. Instead of using Crawlers or AWS Console, you can populate data catalog directly with AWS Glue API related to different structures, like Database, Table etc. AWS provides several SDKs for different languages, eg boto3 for python with easy to use object-oriented API. AWS Glue 数据目录包含有关 AWS 中各种数据源的元信息,例如 S3、DynamoDB 等。您可以直接使用与不同结构(如数据库、表等)相关的AWS Glue API填充数据目录,而不是使用爬虫或 AWS 控制台。 AWS 为不同语言提供了多个 SDK,例如用于boto3的 boto3 和易于使用的面向对象的 API。 So as long as you know how your data structure, you can use methods所以只要你知道你的数据结构如何,就可以使用方法

Create Database definition:创建数据库定义:

from pprint import pprint
import boto3

client = boto3.client('glue')
response = client.create_database(
    DatabaseInput={
        'Name': 'my_database',  # Required
        'Description': 'Database created with boto3 API',
        'Parameters': {
            'my_param_1': 'my_param_value_1'
        },
    }
)
pprint(response)

# Output
{
    'ResponseMetadata': {
        'HTTPHeaders': {
            'connection': 'keep-alive',
            'content-length': '2',
            'content-type': 'application/x-amz-json-1.1',
            'date': 'Fri, 11 Oct 2019 12:37:12 GMT',
            'x-amzn-requestid': '12345-67890'
        },
        'HTTPStatusCode': 200,
        'RequestId': '12345-67890',
        'RetryAttempts': 0
    }
}

在此处输入图像描述

Create Table definition:创建表定义:

response = client.create_table(
    DatabaseName='my_database',
    TableInput={
        'Name': 'my_table',
        'Description': 'Table created with boto3 API',
        'StorageDescriptor': {
            'Columns': [
                {
                    'Name': 'my_column_1',
                    'Type': 'string',
                    'Comment': 'This is very useful column',
                },
                {
                    'Name': 'my_column_2',
                    'Type': 'string',
                    'Comment': 'This is not as useful',
                },
            ],
            'Location': 's3://some/location/on/s3',
        },
        'Parameters': {
            'classification': 'json',
            'typeOfData': 'file',
        }
    }
)

pprint(response)

# Output
{
    'ResponseMetadata': {
        'HTTPHeaders': {
            'connection': 'keep-alive',
            'content-length': '2',
            'content-type': 'application/x-amz-json-1.1',
            'date': 'Fri, 11 Oct 2019 12:38:57 GMT',
            'x-amzn-requestid': '67890-12345'
        },
        'HTTPStatusCode': 200,
        'RequestId': '67890-12345',
        'RetryAttempts': 0
    }
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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