constructor()

in lib/constructs/s3-data-set-enrollment.ts [57:135]


	constructor(scope: Construct, id: string, props: S3dataSetEnrollmentProps) {
		super(scope, id, props);
	
		const dataSetName = props.DataSetName;
		
		const s3AccessPolicy = new iam.Policy(this, 'dataSourceAccessPolicy');
		
		let s3TargetPaths = new Array<glue.CfnCrawler.S3TargetProperty>();
		let s3DataLakePaths = new Array<glue.CfnCrawler.S3TargetProperty>();
		
        const bucketListPolicy = new iam.PolicyStatement({
            actions: ["s3:ListBucket"],
            effect: iam.Effect.ALLOW,
            resources: [`arn:aws:s3:::${props.sourceBucket.bucketName}`]
        });   
		s3AccessPolicy.addStatements(bucketListPolicy);
		
		
        const prefixAccessPolicy = new iam.PolicyStatement({
            actions: ["s3:GetObject"],
            effect: iam.Effect.ALLOW,
            resources: [`arn:aws:s3:::${props.sourceBucket.bucketName}/*`]
        });    
        
        s3AccessPolicy.addStatements(prefixAccessPolicy);
		
        for(let bucketPrefix of props.sourceBucketDataPrefixes){
            s3TargetPaths.push({
                path: `s3://${props.sourceBucket.bucketName}${bucketPrefix}`
            });
            
            
            var prefixFolders = bucketPrefix.split('/')
            var tableFolderName = prefixFolders[prefixFolders.length-2]
            var tableFolderName = tableFolderName.toLowerCase().replace(/\./g,"_").replace(/-/g,"_");
            
            if(props.sourceBucketDataPrefixes.length > 1){
                s3DataLakePaths.push({
                    path: `s3://${props.dataLakeBucket.bucketName}/${dataSetName}/${tableFolderName}/`
                });                
            }else{
                s3DataLakePaths.push({
                    path: `s3://${props.dataLakeBucket.bucketName}/${dataSetName}/`
                });
            }
            

        }

        

		this.DataEnrollment = new DataSetEnrollment(this, `${props.DataSetName}-s3Enrollment`, {
		    dataLakeBucket: props.dataLakeBucket,
			dataSetName: dataSetName,
			SourceAccessPolicy: s3AccessPolicy,
			SourceTargets: {
                s3Targets: s3TargetPaths, 
            },
            MaxDPUs: props.MaxDPUs,
			GlueScriptPath: props.GlueScriptPath,
			DataLakeTargets: {
			    s3Targets: s3DataLakePaths
			},
			GlueScriptArguments: props.GlueScriptArguments,
			WorkflowCronScheduleExpression: props.WorkflowCronScheduleExpression
		});
	
       
        this.createCoarseIamPolicy();
        
        this.setupGlueRoleLakeFormationPermissions(this.DataEnrollment.DataSetGlueRole, props.DataSetName, props.sourceBucket, "src", props.ExistingLakeFormationResource ); 
        
        super.grantGlueRoleLakeFormationPermissions(this.DataEnrollment.DataSetGlueRole, props.DataSetName, 'src', this.SourceCfnResource);
        super.grantGlueRoleLakeFormationPermissions(this.DataEnrollment.DataSetGlueRole, props.DataSetName, 'dl', this.DatalakeCfnResource);
        
        this.grantCoarseIamRead(this.DataEnrollment.DataSetGlueRole);
        
        
	}