Skip to content

Commit

Permalink
feat: add eventbridge scheduler rule
Browse files Browse the repository at this point in the history
  • Loading branch information
edelwud committed Mar 16, 2023
1 parent 8ac7443 commit de3d01d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/dynamodb-s3-export.stack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Stack, StackProps } from "aws-cdk-lib";
import { AttributeType, Table } from "aws-cdk-lib/aws-dynamodb";
import { Rule, Schedule } from "aws-cdk-lib/aws-events";
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
import {
BlockPublicAccess,
Bucket,
Expand Down Expand Up @@ -34,6 +36,14 @@ export class DynamoDBS3ExportStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new Rule(this, "ExportInitiator", {
schedule: Schedule.cron({
minute: "0",
hour: "2",
}),
targets: [new LambdaFunction(this.exportLambda)],
});

this.dataTable.grantReadData(this.exportLambda);
this.destinationBucket.grantWrite(this.exportLambda);
}
Expand Down
5 changes: 3 additions & 2 deletions src/services/export.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const handler = async () => {
);

const csvTransform = transform((data: Record<string, AttributeValue>[]) => {
console.log("DATA:", data);
return data;
return data.map((record) =>
Object.keys(record).map((field) => JSON.stringify(record[field]))
);
});

const upload = new Upload({
Expand Down

0 comments on commit de3d01d

Please sign in to comment.