Created
April 6, 2023 13:46
-
-
Save oieduardorabelo/75e571173f173cbb246896e70321e895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { | |
FirehoseTransformationHandler, | |
FirehoseTransformationResultRecord, | |
} from "aws-lambda"; | |
function base64Encode(str: string): string { | |
return Buffer.from(str).toString("base64"); | |
} | |
function base64Decode(str: string): string { | |
return Buffer.from(str, "base64").toString("utf-8"); | |
} | |
async function transformRecord(record: any) { | |
const data = JSON.parse(base64Decode(record.data)); | |
// do something with data | |
console.log(data); | |
const result: FirehoseTransformationResultRecord = { | |
recordId: record.recordId, | |
result: "Ok", // 'Ok' | 'Dropped' | 'ProcessingFailed' | |
data: base64Encode(JSON.stringify(data)), | |
}; | |
return result; | |
} | |
export const handler: FirehoseTransformationHandler = async (event) => { | |
const results = await Promise.all(event.records.map(transformRecord)); | |
return { | |
records: results, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment