in typescript/src/export/exportSubscriptions-v2.ts [14:63]
export async function handler(): Promise<string> {
const bucket = process.env['ExportBucket'];
const s3BucketOwner = process.env['BucketOwner'];
const account = process.env['AccountId'];
const app = process.env['App'];
const stage = process.env['Stage'];
const className = process.env['ClassName'];
if (!bucket) throw new Error('Variable ExportBucket must be set');
if (!account) throw new Error('Variable AccountId must be set');
if (!s3BucketOwner) throw new Error('Variable BucketOwner must be set');
if (!app) throw new Error('Variable App must be set');
if (!stage) throw new Error('Variable Stage must be set');
if (!className) throw new Error('Variable ClassName must be set');
let tableArn = null;
switch (className) {
case 'subscriptions':
console.log('Reading subscription from subscriptions');
tableArn = `arn:aws:dynamodb:eu-west-1:${account}:table/${app}-${stage}-${className}`;
break;
case 'user-subscriptions':
console.log('Reading user subscription from user subscription');
tableArn = `arn:aws:dynamodb:eu-west-1:${account}:table/${app}-${stage}-${className}`;
break;
default:
throw new Error(`Invalid ClassName value ${className}`);
}
if (!tableArn) throw new Error('Variable TableArn must be set');
const params = {
TableArn: tableArn,
S3Bucket: bucket,
S3BucketOwner: s3BucketOwner,
S3Prefix: prefix_creator(stage),
ExportFormat: 'DYNAMODB_JSON',
};
return aws
.exportTableToPointInTime(params)
.promise()
.then((result) => {
console.log(`Exporting subscription data to ${bucket}`);
return `Dynamo export started, with status: ${result.ExportDescription?.ExportStatus}`;
})
.catch((err) => {
throw new Error('Failed to start dynamo export');
});
}