import * as AWS from 'aws-sdk' ; import { updateHistoryEntry } from '../utils/historyTable' ; import { CrawlContext } from '../crawler/types' ; import { deleteContextTable } from '../utils/contextTable' ; const kendra = new AWS . Kendra ( ) ; export interface KendraDataSourceDetails { indexId : string ; dataSourceId : string ; } /**
 * This step is run at the end of our step function state machine, once all discovered urls have been visited.
 * Clear the context database and sync the kendra data source.
 */ export const completeCrawl = async ( crawlContext , kendraDataSourceDetails ? ) => { console . log ( 'Deleting context table' , crawlContext . contextTableName ) ; await deleteContextTable ( crawlContext . contextTableName ) ; console . log ( 'Writing end timestamp to history table' ) ; await updateHistoryEntry ( crawlContext . crawlId , { endTimestamp : new Date ( ) . toISOString ( ) , } ) ; if ( kendraDataSourceDetails ) { console . log ( 'Starting kendra sync job' ) ; await kendra . startDataSourceSyncJob ( { IndexId : kendraDataSourceDetails . indexId , Id : kendraDataSourceDetails . dataSourceId , } ) . promise ( ) ; } console . log ( 'Crawl complete!' ) ; return { } ; } ;