in src/qldb/JournalS3ExportReader.ts [126:176]
export async function readExport(
describeJournalExportResult: JournalS3ExportDescription,
s3Client: S3
): Promise<JournalBlock[]> {
const exportConfiguration: S3ExportConfiguration = describeJournalExportResult.S3ExportConfiguration;
const prefix: string = exportConfiguration.Prefix;
const bucketName: string = exportConfiguration.Bucket;
const request: ListObjectsV2Request = {
Bucket: bucketName,
Prefix: prefix
};
const response: ListObjectsV2Output = await s3Client.listObjectsV2(request).promise();
const objects: ObjectList = response.Contents;
log("Found the following objects for list from S3:");
objects.forEach(function(object) {
log(object.Key);
});
// Validate initial manifest file was written.
const expectedManifestKey: string = (`${prefix}${describeJournalExportResult.ExportId}.started.manifest`);
const initialManifest: string = filterForInitialManifest(objects, expectedManifestKey);
log(`Found the initial manifest with key: ${initialManifest}.`);
// Find the final manifest file, it should contain the exportId in it.
const completedManifestFileKey: string = filterForCompletedManifest(objects);
let getObjectRequest: GetObjectRequest = {
Bucket: bucketName,
Key: completedManifestFileKey
};
const completedManifestObject: string = (await s3Client.getObject(getObjectRequest).promise()).Body.toString();
const dataFileKeys: string[] = getDataFileKeysFromManifest(completedManifestObject);
log(`Found the following keys in the manifest files: ${JSON.stringify(dataFileKeys)}`);
const journalBlocks: JournalBlock[] = [];
for (const dataFileKey of dataFileKeys) {
log(`Reading file with S3 key ${dataFileKey} from bucket: ${bucketName}`);
getObjectRequest = {
Bucket: bucketName,
Key: dataFileKey
};
const s3Object: string = (await s3Client.getObject(getObjectRequest).promise()).Body.toString();
const blocks: JournalBlock[] = getJournalBlocks(s3Object);
compareKeyWithContentRange(dataFileKey, blocks[0], blocks[blocks.length-1]);
blocks.forEach(function(block) {
journalBlocks.push(block);
});
}
return journalBlocks;
}