in exercises/node-javascript/encryption-context-start/store.js [36:62]
async function store(fileStream, encryptionContext = {}) {
/* The encryption context can not step on the Dynamo DB indexing structure. */
needs(
!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));
// ENCRYPTION-CONTEXT-START: Set Encryption Context on Encrypt
const Body = fileStream.pipe(encryptStream(encryptKeyring));
const file = await s3
.upload({ Bucket, Key, Body, Metadata: encryptionContext })
.promise();
for (Item of [PointerItem, ...ContextItems]) {
await ddb.put({ Item, TableName }).promise();
}
return file;
}