await deletePartitionForUpdate()

in source/lambda/query_runner/index.js [42:114]


                await deletePartitionForUpdate(requestType, resourceProperties)   
            }
            await QueryRunner(requestType, resourceProperties);
        }
        // send anonymous metrics
        else if (resourceType === 'Custom::SendAnonymousUsageData') {
            await SendAnonymousUsageData(requestType, resourceProperties);
        }

        // send cfn response
        if (requestType === 'Create' || requestType === 'Update' || requestType == 'Delete') {
            return await cfn.send(event, context, 'SUCCESS');
        }
    }
    catch (err) {
        LOGGER.log('ERROR', err);
        if (requestType === 'Create' || requestType === 'Update' || requestType == 'Delete') {
            await cfn.send(event, context, 'FAILED', err.message + `\nMore information in CloudWatch Log Stream: ${context.logStreamName}`);
        }
    }
};

/**
 * Run Athena queries
 */
let QueryRunner = async (requestType, resourceProperties) => {
    try {
        LOGGER.log('INFO', 'Start query runner lambda function');
        let queryString = ''
        const athenaDB = resourceProperties['MetricsDBName']
        const athenaTable = resourceProperties['MetricsTableName']
        const athenaCodeBuildTable = resourceProperties['CodeBuildMetricsTableName']
        const athenaWorkGroup = resourceProperties['AthenaWorkGroup']
        const dataDuration = resourceProperties['DataDuration']
        const repositoryList = resourceProperties['RepositoryList']
        const athenaViews = ['code_change_activity_view', 'code_deployment_detail_view', 'recovery_time_detail_view', 'code_pipeline_detail_view', 'code_build_detail_view']

        // Create Athena views at stack creation or update
        if (requestType === 'Create' || requestType === 'Update') {
            LOGGER.log('INFO', 'Add Athena Partition and Build Athena Views');

            // First run query to add athena partitions to devops metrics table as needed
            queryString = buildAthenaQuery.buildAddAthenaPartitionQuery(athenaDB, athenaTable);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);

            // First run query to add athena partitions to codebuild metrics table as needed
            queryString = buildAthenaQuery.buildAddAthenaPartitionQuery(athenaDB, athenaCodeBuildTable);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);

            // Run query to build view for codecommit events
            queryString = buildAthenaQuery.buildCodeChangeActivityQuery(athenaDB, athenaTable, repositoryList, dataDuration);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);

            // Run query to build view for canary alarm events
            queryString = buildAthenaQuery.buildRecoveryTimeQuery(athenaDB, athenaTable, dataDuration);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);

            // Run query to build view for deployment events
            queryString = buildAthenaQuery.buildDeploymentQuery(athenaDB, athenaTable, dataDuration);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);

            // Run query to build view for codepipeline events
            queryString = buildAthenaQuery.buildCodePipelineQuery(athenaDB, athenaTable, dataDuration);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);

            // Run query to build view for codebuild events
            queryString = buildAthenaQuery.buildCodeBuildQuery(athenaDB, athenaCodeBuildTable, dataDuration);
            await exeAthenaQuery.executeAthenaQuery(athenaDB, athenaWorkGroup, queryString);
        }
        // Drop Athena views at stack deletion
        else if (requestType === 'Delete') {
            LOGGER.log('INFO', 'Delete Athena Views');
            for (let i in athenaViews) {