<p>您可以通过多种方式从dynamodb导出数据</p>
<p>最简单的方法是全表扫描:</p>
<pre><code>dynamodb = boto3.client('dynamodb')
response = dynamodb.scan(
TableName=your_table,
Select='ALL_ATTRIBUTES')
data = response['Items']
while 'LastEvaluatedKey' in response:
response = dynamodb.scan(
TableName=your_table,
Select='ALL_ATTRIBUTES',
ExclusiveStartKey=response['LastEvaluatedKey'])
data.extend(response['Items'])
# save your data as csv here
</code></pre>
<p>但如果你想每x天做一次,我建议你:</p>
<p>使用上面的代码从表中创建第一个转储</p>
<p>然后,您可以为lambda函数创建dynamodb触发器,该函数将接收所有表更改(插入、更新、删除),然后您可以将数据附加到csv文件中。代码类似于:</p>
<pre><code>def lambda_handler(event, context):
for record in event['Records']:
# get the changes here and save it
</code></pre>
<p>因为您只会收到表更新,所以不必担心lambda的15分钟执行时间</p>
<p>您可以在此处阅读有关dynamodb流和lambda的更多信息:<a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.html" rel="nofollow noreferrer">DynamoDB Streams and AWS Lambda Triggers</a></p>
<p>如果你想处理你的数据,你可以创建一个<a href="https://aws.amazon.com/pt/glue/" rel="nofollow noreferrer">aws glue</a>或<a href="https://aws.amazon.com/emr/" rel="nofollow noreferrer">EMR cluster</a></p>