Skip to content

Encrypt event eem as function #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-lambda-stream",
"version": "1.1.5",
"version": "1.1.6",
"description": "Create stream processors with AWS Lambda functions.",
"keywords": [
"aws",
Expand Down
3 changes: 2 additions & 1 deletion src/utils/encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ export const encryptEvent = ({
return _(Promise.resolve(uow));
}

const eemMetadata = typeof eem === 'function' ? eem(uow[sourceField], uow) : eem;
const p = encryptObject(uow[sourceField], {
masterKeyAlias,
regions,
...eem, // fields and overrides
...eemMetadata, // fields and overrides
AES,
})
// .tap(debug)
Expand Down
73 changes: 73 additions & 0 deletions test/unit/utils/encryption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,79 @@ describe('utils/encryption.js', () => {
.done(done);
});

it('should encrypt an event - trigger function w/ eem function', (done) => {
const events = toDynamodbRecords([
{
timestamp: 1572832690,
keys: {
pk: '1',
sk: 'thing',
},
newImage: {
pk: '1',
sk: 'thing',
discriminator: 'thing',
name: 'n1',
description: 'd1',
status: 's1',
},
},
]);

fromDynamodb(events)
.through(encryptEvent({
eem: (event, _uow) => {
if (event.raw.new.discriminator === 'thing') {
return {
fields: ['name', 'description'],
};
}
return {
fields: [],
};
},
masterKeyAlias: 'alias/aws-kms-ee',
AES: false,
}))
.collect()
.tap((collected) => {
// console.log(JSON.stringify(collected, null, 2));

expect(collected.length).to.equal(1);
expect(collected[0].event).to.deep.equal({
id: '0',
type: 'thing-created',
partitionKey: '1',
timestamp: 1572832690000,
tags: {
region: 'us-west-2',
},
raw: {
new: {
pk: '1',
sk: 'thing',
discriminator: 'thing',
name: 'Im4xIg==',
description: 'ImQxIg==',
status: 's1',
},
old: undefined,
},
eem: {
masterKeyAlias: 'alias/aws-kms-ee',
dataKeys: {
'us-west-2': MOCK_GEN_DK_RESPONSE.CiphertextBlob.toString('base64'),
},
fields: [
'name',
'description',
],
},
});
})
.done(done);
});

it('should decrypt an event - listener function', (done) => {
const events = toKinesisRecords([
{
Expand Down