如何在 aws dynamodb boto3 上正確使用日期過濾器

克里岡

我想檢索 dynamodb 表中的項目。然後我會將此數據添加到大查詢中表的最後一個數據下方。

client = boto3.client('dynamodb')
table = dynamodb.Table('table')
response = table.scan(FilterExpression=Attr('created_at').gt(max_date_of_the_table_in_big_query))

#first part
data = response['Items']

#second part
while response.get('LastEvaluatedKey'):
    response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
    data.extend(response['Items'])

df=pd.DataFrame(data)
df=df[['query','created_at','result_count','id','isfuzy']]

# load df to big query
.....

日期過濾器工作正常,但在 while 循環會話(第二部分)中,代碼檢索所有項目。在第一部分之後,我有 100 行。但在這段代碼之後

while response.get('LastEvaluatedKey'):
    response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
    data.extend(response['Items'])

我有 500.000 行。我只能使用第一部分。但我知道有 1 mb 的限制,這就是我使用第二部分的原因。我如何獲取給定日期範圍內的數據

爾米婭·埃斯坎德瑞

您的第一個掃描 API 調用有一個FilterExpression集合,它應用您的數據過濾器:

response = table.scan(FilterExpression=Attr('created_at').gt(max_date_of_the_table_in_big_query))

但是,第二次掃描 API 調用沒有一組,因此不會過濾您的數據:

response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])

將 應用於FilterExpression兩個調用:

while response.get('LastEvaluatedKey'):
    response = table.scan(
       ExclusiveStartKey=response['LastEvaluatedKey'], 
       FilterExpression=Attr('created_at').gt(max_date_of_the_table_in_big_query)    
    )
    data.extend(response['Items'])

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用boto3从DynamoDB检索所有项目?

如何使用 Boto3 for DynamoDB 修复“NoCredentialsError”

AWS Lambda Boto3 DynamoDB 并发

设置了MFA后,使用boto3访问aws dynamodb。获取ClientError

AWS DynamoDB-使用JSON文件作为输入通过Boto3加载数据

如何使用boto3标记AWS Lambda函数

使用Boto3的DynamoDB分页

使用Boto3更新DynamoDb

如何使用Boto3将项目添加到Dynamodb上的string_set

如何在Boto3中使用AWS Polly进行暂停

如何使用serverless.yml创建dynamodb表并使用python boto3删除其中的项目?

如何在给定主键列表的情况下使用 boto3 对 DynamoDB 运行批处理查询

如何使用boto3删除dynamodb中的所有项目

如何使用 boto3 在 DynamoDB 中獲取此字典列表?

我们如何使用boto3查询dynamodb的二级索引?

我不知道如何使用 Boto3 从我的 DynamoDB 表中查询某些数据

使用 boto3 复制 AWS 快照

使用boto3验证AWS凭证

如何在〜/ .aws / .credentials和〜/ .aws / .config文件中使用boto3列出本地配置文件?

DynamoDB-如何查询嵌套属性boto3

如何使用boto3更改由AWS Glue搜寻器创建的表的名称

如何使用 boto3 在 Python 中访问 AWS S3 Bucket

如何在不上传 zip 文件的情况下在 AWS Lambda 上获得 boto3 授权

Boto3:使用多个排序键值查询 DynamoDB

使用boto3将json批量上传到dynamodb

无法使用 boto3 从 DynamoDB StringSet 中删除项目

Boto3:在DynamoDB中使用“ NOT IN”进行扫描

如何在AWS中使用Boto3创建不具有公共访问权限的存储桶和对象?

如何在 CloudWatch Alarm Actions with python (boto3) 中使用变量作为参数传递 AWS 子账户的账户 ID?