-
Notifications
You must be signed in to change notification settings - Fork 0
/
postMeeting.ts
66 lines (61 loc) · 1.95 KB
/
postMeeting.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*eslint import/no-unresolved: 0 */
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import {
DynamoDBDocumentClient,
UpdateCommand,
UpdateCommandInput,
UpdateCommandOutput,
} from '@aws-sdk/lib-dynamodb';
const ddbClient = new DynamoDBClient({ region: 'us-east-1' });
const marshallOptions = {
convertEmptyValues: false,
removeUndefinedValues: true,
convertClassInstanceToMap: false,
};
const unmarshallOptions = {
wrapNumbers: false,
};
const translateConfig = { marshallOptions, unmarshallOptions };
const ddbDocClient = DynamoDBDocumentClient.from(ddbClient, translateConfig);
var outputTable = process.env.OUTPUT_TABLE;
import { Handler } from 'aws-cdk-lib/aws-lambda';
import { S3Event } from 'aws-lambda';
export const lambdaHandler: Handler = async (event: S3Event): Promise<null> => {
console.info(JSON.stringify(event));
const keyInfo: Array<string> = event.Records[0].s3.object.key.split('/');
const mediaPipelineId: string = keyInfo[keyInfo.length - 3];
const keyType: string = keyInfo[keyInfo.length - 2];
const key: string = event.Records[0].s3.object.key;
await updateOutputTable(mediaPipelineId, keyType, key);
return null;
};
async function updateOutputTable(
mediaPipelineId: string,
keyType: string,
key: string,
) {
const updateOutputTableInput: UpdateCommandInput = {
TableName: outputTable,
Key: { mediaPipelineId: mediaPipelineId },
UpdateExpression: 'SET #kt = :k, #ts = :ts',
ExpressionAttributeNames: {
'#kt': keyType,
'#ts': 'timestamp',
},
ExpressionAttributeValues: {
':k': key,
':ts': Date.now() / 1e3,
},
};
console.log(`info to put: ${JSON.stringify(updateOutputTableInput)}`);
try {
const data: UpdateCommandOutput = await ddbDocClient.send(
new UpdateCommand(updateOutputTableInput),
);
console.log('Success - item added or updated', data);
return data;
} catch (err) {
console.log('Error', err);
return false;
}
}