export async function onEvent()

in lib/lambda/createQldbTables/index.ts [39:77]


export async function onEvent(
    event: lambda.CloudFormationCustomResourceEvent, 
    context: lambda.Context,
): Promise<Result> {
    console.log(`Processing request: `, event);

    const qldbClientConfigOptions = {
        region: "ap-southeast-2",
    };

    const qldbDriver = new qldb.QldbDriver(event.ResourceProperties.LedgerName, qldbClientConfigOptions);

    let result = {};

    // set up logics for different Customer Resource events.
    try {
        if (event.RequestType === 'Create') {
            const props = JSON.stringify(event.ResourceProperties);
            console.log(`Create new resource with props ${props}`);
            result = await onCreate(event, qldbDriver);
        } else if (event.RequestType === 'Update') {
            const physicalId = event.PhysicalResourceId;
            const props = JSON.stringify(event.ResourceProperties);
            console.log(`Update resource ${physicalId} with props ${props}`);
            result = await onUpdate(event, qldbDriver);
        } else if (event.RequestType === 'Delete') {
            const physicalId = event.PhysicalResourceId;
            const props = JSON.stringify(event.ResourceProperties);
            console.log(`Delete resource ${physicalId} with props ${props}, but do not delete QLDB tables to avoid data loss`);
            result = await onDelete(event, qldbDriver);
        }
    } catch(e) {
        console.log(e);
        throw e;
    }

    return result;

};