AWSGlue爬虫-DynamoDB导出-获取模式中的属性名称而不是结构
创始人
2024-09-25 16:01:13
0

要获取 DynamoDB 表的属性名称,在 AWS Glue 中使用以下代码示例:

import boto3

# 创建 DynamoDB 客户端
ddb = boto3.client('dynamodb')

# 定义 DynamoDB 表名
table_name = 'your DynamoDB table name'

# 获取表描述
table_desc = ddb.describe_table(TableName=table_name)

# 获取属性名称列表
attribute_names = [attr['AttributeName'] for attr in table_desc['Table']['AttributeDefinitions']]

print(attribute_names)

然后,您可以将此列表传递给 AWS Glue 转换作业中的 DynamoDB 输入源,以获取仅包含属性名称的模式。使用以下代码示例:

import boto3
import sys
from awsglue.transforms import *
from awsglue.dynamicframe import DynamicFrame

# 创建 DynamoDB 客户端
ddb = boto3.client('dynamodb')

# 定义 DynamoDB 表名
table_name = 'your DynamoDB table name'

# 获取表描述
table_desc = ddb.describe_table(TableName=table_name)

# 获取属性名称列表
attribute_names = [attr['AttributeName'] for attr in table_desc['Table']['AttributeDefinitions']]

# 创建动态帧
dynamic_frame = glueContext.create_dynamic_frame.from_options(
   "dynamodb",
   connection_options={
       "dynamodb.input.tableName": table_name,
       "dynamodb.throughput.read.percent": "0.5",
       "dynamodb.splits": "100"
   },
   format_options={
       "dynamodb": {
           "json": "true"
       }
   },
   transformation_ctx="dyn_glue_table"
)

# 获取只包含属性名称的 schema
schema = StructType([StructField(name, StringType(), True) for name in attribute_names])

# 将动态帧转换为包含模式的动态帧
df_with_schema = DynamicFrame.fromDF(dynamic_frame.toDF(), glueContext, "df_with_schema").withSchema(schema)

print(df_with_schema.schema())

相关内容

热门资讯

第3分钟辅助!we poker... 第3分钟辅助!we poker辅助器v3.3,wepoker透视功能下载,机巧教程(有挂透视)1、超...
第8分钟辅助!wepoker怎... 第8分钟辅助!wepoker怎么开辅助,黑侠破解wepoker,课程教程(今日头条)1、上手简单,内...
第十分钟辅助!如何下载wpk透... 第十分钟辅助!如何下载wpk透视版,pokerworld软件,策略教程(有挂分享)如何下载wpk透视...
九分钟辅助!wepoker辅助... 九分钟辅助!wepoker辅助真的假的,cloudpoker作弊,手筋教程(证实有挂)1、每一步都需...
第十分钟辅助!wejoker辅... 第十分钟辅助!wejoker辅助器怎么卖,wepoker免费透视脚本,窍门教程(有挂方式)1、进入游...
十分钟辅助!wepoker-h... 十分钟辅助!wepoker-h5下载,pokernow辅助控制,绝活教程(有挂实锤)1、点击下载安装...
5分钟辅助!aapoker辅助... 5分钟辅助!aapoker辅助器怎么用,wepoker模拟器哪个好用,模板教程(有挂辅助)wepok...
八分钟辅助!wpk官网下载链接... 八分钟辅助!wpk官网下载链接,wpk透视怎么安装,教程书教程(有挂分享)该软件可以轻松地帮助玩家将...
9分钟辅助!wepoker怎么... 9分钟辅助!wepoker怎么买辅助,wepoker安装教程,课程教程(有挂方略)1、wepoker...
第七分钟辅助!hh poker... 第七分钟辅助!hh poker插件下载,wepoker科技辅助器,教程书教程(有挂教程)wepoke...