Package: cdk-serverless-clamscan
cdk-serverless-clamscanAnaws-cdkconstruct that usesClamAV®to scan newly uploaded objects to Amazon S3 for viruses. The construct provides a flexible interface for a system to act based on the results of a ClamAV virus scan. Check out thisblogpostfor a guided walkthrough.Pre-RequisitesDocker:The ClamAV Lambda functions utilizes acontainer imagethat is built locally usingdocker bundlingExamplesThis project usesprojenand thus all the constructs follow language specific standards and naming patterns. For more information on how to translate the following examples into your desired language read the CDK guide onTranslating TypeScript AWS CDK code to other languagesExample 1. (Default destinations with rule target)typescriptimport{RuleTargetInput}from'aws-cdk-lib/aws-events';import{SnsTopic}from'aws-cdk-lib/aws-events-targets';import{Bucket}from'aws-cdk-lib/aws-s3';import{Topic}from'aws-cdk-lib/aws-sns';import{Stack,StackProps}from'aws-cdk-lib';import{Construct}from'constructs';import{ServerlessClamscan}from'cdk-serverless-clamscan';exportclassCdkTestStackextendsStack{constructor(scope:Construct,id:string,props?:StackProps){super(scope,id,props);constbucket_1=newBucket(this,'rBucket1');constbucket_2=newBucket(this,'rBucket2');constbucketList=[bucket_1,bucket_2];constsc=newServerlessClamscan(this,'rClamscan',{buckets:bucketList,});constbucket_3=newBucket(this,'rBucket3');sc.addSourceBucket(bucket_3);constinfectedTopic=newTopic(this,'rInfectedTopic');sc.infectedRule?.addTarget(newSnsTopic(infectedTopic,{message:RuleTargetInput.fromEventPath('$.detail.responsePayload.message',),}),);}}pythonfromaws_cdkimport(Stack,aws_eventsasevents,aws_events_targetsasevents_targets,aws_s3ass3,aws_snsassns)fromcdk_serverless_clamscanimportServerlessClamscanfromconstructsimportConstructclassCdkTestStack(Stack):def__init__(self,scope:Construct,construct_id:str,**kwargs)->None:super().__init__(scope,construct_id,**kwargs)bucket_1=s3.Bucket(self,"rBucket1")bucket_2=s3.Bucket(self,"rBucket2")bucketList=[bucket_1,bucket_2]sc=ServerlessClamscan(self,"rClamScan",buckets=bucketList,)bucket_3=s3.Bucket(self,"rBucket3")sc.add_source_bucket(bucket_3)infected_topic=sns.Topic(self,"rInfectedTopic")ifsc.infected_rule!=None:sc.infected_rule.add_target(events_targets.SnsTopic(infected_topic,message=events.RuleTargetInput.from_event_path('$.detail.responsePayload.message'),))Example 2. (Bring your own destinations)typescriptimport{SqsDestination,EventBridgeDestination,}from'aws-cdk-lib/aws-lambda-destinations';import{Bucket}from'aws-cdk-lib/aws-s3';import{Queue}from'aws-cdk-lib/aws-sqs';import{Stack,StackProps}from'aws-cdk-lib';import{Construct}from'constructs';import{ServerlessClamscan}from'cdk-serverless-clamscan';exportclassCdkTestStackextendsStack{constructor(scope:Construct,id:string,props?:StackProps){super(scope,id,props);constbucket_1=newBucket(this,'rBucket1');constbucket_2=newBucket(this,'rBucket2');constbucketList=[bucket_1,bucket_2];constqueue=newQueue(this,'rQueue');constsc=newServerlessClamscan(this,'default',{buckets:bucketList,onResult:newEventBridgeDestination(),onError:newSqsDestination(queue),});constbucket_3=newBucket(this,'rBucket3');sc.addSourceBucket(bucket_3);}}pythonfromaws_cdkimport(Stack,aws_lambda_destinationsaslambda_destinations,aws_s3ass3,aws_sqsassqs)fromcdk_serverless_clamscanimportServerlessClamscanfromconstructsimportConstructclassCdkTestStack(Stack):def__init__(self,scope:Construct,construct_id:str,**kwargs)->None:super().__init__(scope,construct_id,**kwargs)bucket_1=s3.Bucket(self,"rBucket1")bucket_2=s3.Bucket(self,"rBucket2")bucketList=[bucket_1,bucket_2]queue=sqs.Queue(self,"rQueue")sc=ServerlessClamscan(self,"rClamScan",buckets=bucketList,on_result=lambda_destinations.EventBridgeDestination(),on_error=lambda_destinations.SqsDestination(queue),)bucket_3=s3.Bucket(self,"rBucket3")sc.add_source_bucket(bucket_3)Operation and MaintenanceWhen ClamAV publishes updates to the scanner you will see “Your ClamAV installation is OUTDATED” in your scan results. While the construct creates a system to keep the database definitions up to date, you must update the scanner to detect all the latest Viruses.Update the docker images of the Lambda functions with the latest version of ClamAV by re-runningcdk deploy.API ReferenceSeeAPI.md.ContributingSeeCONTRIBUTINGfor more information.LicenseThis project is licensed under the Apache-2.0 License.