import { Stack , StackProps , Construct } from '@aws-cdk/core' ; import { CfnIndex , CfnDataSource } from '@aws-cdk/aws-kendra' ; import { Bucket } from '@aws-cdk/aws-s3' ; import { PolicyStatement , Effect } from '@aws-cdk/aws-iam' ; import { Table } from '@aws-cdk/aws-dynamodb' ; import WebCrawlerStepLambdas from '../constructs/webcrawler/web-crawler-step-lambdas' ; import { AttributeType } from '@aws-cdk/aws-dynamodb' ; import WebCrawlerStateMachine from '../constructs/webcrawler/web-crawler-state-machine' ; import { WEB_CRAWLER_STATE_MACHINE_NAME } from '../constructs/webcrawler/constants' ; export interface KendraInfrastructureProps { dataSourceBucket : Bucket ; kendraIndex : CfnIndex ; kendraDataSource : CfnDataSource ; } export interface WebCrawlerStackProps extends StackProps { kendra ? : KendraInfrastructureProps ; } /**
 * This stack deploys the serverless webcrawler
 */ export class WebCrawlerStack extends Stack { constructor ( scope , id , props ) { super ( scope , id , props ) ; const historyTable = new Table ( this , 'CrawlerHistoryTable' , { partitionKey : { name : 'crawlId' , type : AttributeType . STRING , } , } ) ; const contextTableNamePrefix = 'web-crawler-context' ; const createContextTablePolicy = ( actions ) => new PolicyStatement ( { effect : Effect . ALLOW , actions : actions . map ( ( action ) => `dynamodb:${ action }` ) , resources : [ this . formatArn ( { service : 'dynamodb' , resource : 'table' , resourceName : `${ contextTableNamePrefix }*` , } ) ] , } ) ; const webCrawlerStateMachineArn = this . formatArn ( { service : 'states' , resource : 'stateMachine' , resourceName : WEB_CRAWLER_STATE_MACHINE_NAME , sep : ':' , } ) ; const { steps } = new WebCrawlerStepLambdas ( this , 'WebCrawlerStepLambdas' , { region : this . region , contextTableNamePrefix , createContextTablePolicy , kendra : props . kendra , historyTable , webCrawlerStateMachineArn , } ) ; new WebCrawlerStateMachine ( this , 'WebCrawlerStateMachine' , { steps } ) ; } }