Reputation: 7986
I'm using the following lambda to export the QLDB data. Howerver, the export files only contain the hashes, it doesn't contain the actual document data.
The lambda:
def handler(event, context):
ledger_name = event['LedgerName']
bucket = event ['S3Bucket']
bucket_prefix = event['BucketPrefix']
role_arn = os.getenv('ROLE_ARN') or event['RoleArn']
output_format = event.get('OutputFormat') or 'ION_TEXT'
export_count = event['ExportCount']
if export_count < 1:
export_count = 1
s3Config = {
'Bucket': bucket,
'Prefix': bucket_prefix,
'EncryptionConfiguration': {
'ObjectEncryptionType': 'SSE_S3'
}
}
qldb = boto3.client('qldb')
digest_result = qldb.get_digest(Name=ledger_name)
address_ion = simpleion.loads(digest_result['DigestTipAddress']['IonText'])
block_cnt = int(address_ion['sequenceNo'] / export_count)
start_time = datetime.datetime(1900, 1, 1)
export_ids = []
for i in range(0, export_count):
if i == (export_count - 1):
end_time = datetime.datetime.utcnow().replace(microsecond=0)
else:
address_ion['sequenceNo'] = IonPyInt.from_value(IonType.INT, block_cnt * (i + 1))
address_str = simpleion.dumps(address_ion,
binary=False,
omit_version_marker=True)
block_response = qldb.get_block(Name=ledger_name,
BlockAddress={'IonText': address_str})
block = simpleion.loads(block_response['Block']['IonText'])
end_time = block['blockTimestamp'].replace(microsecond=0, tzinfo=None)
# see https://docs.aws.amazon.com/cli/latest/reference/qldb/export-journal-to-s3.html
export_response = qldb.export_journal_to_s3(Name=ledger_name,
OutputFormat=output_format,
InclusiveStartTime=start_time,
ExclusiveEndTime=end_time,
RoleArn=role_arn,
S3ExportConfiguration=s3Config)
print("response: {}".format(export_response))
export_ids.append(export_response['ExportId'])
start_time = end_time
The exported file:
{
"blockAddress": {
"strandId": "J3hZuXNPYEG1CXNZhZH5Mf",
"sequenceNo": 12
},
"transactionId": "K5ZsAl4Oli1EcM38HHB7wb",
"blockTimestamp": "2024-12-24T17:16:35.577Z",
"blockHash": "13lvDEfqeoRMU6cZrj7DJvxN7G3gvuc/NDyTHxwG6Es=",
"entriesHash": "754VaEFcWkv7DaGq7iOR5wGvnCuShaMBApmLhA7OWgg=",
"previousBlockHash": "k3qo2OqGyWBQ4dXOdBd75dqj39R4vIhswQbllEfFEck=",
"entriesHashList": [
"EqC/O3Fhs9Jd0aN3os6AC8bWuKfo4oD40H5bN+oXub8=",
"HJymp6NR63Tt8gwjERsmS2daNx9oSdIya43u9dUHZoI=",
"Adsngx5Fehz2dNAwbULFZADhd9C1o3zuC9ckXrPQm7w="
],
"revisions": [
{
"hash": "Du9RDX99jgUNNgYf2VJvcPHLH/QOQI04+IshjCocJ94="
},
{
"hash": "xwjgpfJQYdf6Gq9z7GKKr7lckK3UhaD0vFsDROTbZFM="
}
]
}
Upvotes: 0
Views: 16