Skip to content

Instantly share code, notes, and snippets.

@oieduardorabelo
Created April 6, 2023 13:46
Show Gist options
  • Save oieduardorabelo/75e571173f173cbb246896e70321e895 to your computer and use it in GitHub Desktop.
Save oieduardorabelo/75e571173f173cbb246896e70321e895 to your computer and use it in GitHub Desktop.
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