in exercises/node-typescript/add-esdk-complete/src/store.ts [36:62]
export async function store(fileStream: Readable, encryptionContext: EC = {}) {
/* The encryption context can not step on the Dynamo DB indexing structure. */
assert(
!encryptionContext[partition_key] && !encryptionContext[sort_key],
`Can't use DB key names ${partition_key} or ${sort_key} as Encryption Context keys!`
);
const Key = uuid.v4();
const PointerItem = ddbItem(Key, object_target, encryptionContext);
const ContextItems = Object.keys(encryptionContext)
.map(canonicalContextKey)
.map(canonicalKey => ddbItem(canonicalKey, Key));
// ADD-ESDK-COMPLETE: Add Encryption to store
const Body = fileStream.pipe(encryptStream(encryptKeyring));
const file = await s3
.upload({ Bucket, Key, Body, Metadata: encryptionContext })
.promise();
for (const Item of [PointerItem, ...ContextItems]) {
await ddb.put({ Item, TableName }).promise();
}
return file;
}