This directory contains an example CDK stack demonstrating how to deploy the AttachmentAVBucketScan construct.
- AWS Account: You need an AWS account with appropriate permissions
- AWS CLI: Configured with your credentials (
aws configure) - attachmentAV API Key: Sign up at attachmentav.com to get an API key
- Node.js: Installed and working
- CDK Bootstrap: Your AWS account must be bootstrapped for CDK
From the repository root:
npm install
npm run buildStore your attachmentAV API key in SSM Parameter Store:
aws ssm put-parameter \
--name "/attachmentav/api-key" \
--value "YOUR_ATTACHMENTAV_API_KEY_HERE" \
--type "SecureString" \
--description "attachmentAV API key for malware scanning"npx cdk bootstrapFrom the integration directory:
cd integration
npx cdk synthnpx cdk deployThis will:
- Create an S3 bucket with versioning enabled
- Create scanner and callback Lambda functions
- Set up S3 event notifications to trigger scans
- Create an IAM user for generating presigned URLs
- Configure all necessary permissions
After deployment, CDK will output the bucket name. You can also view outputs with:
npx cdk deploy --outputs-file outputs.jsonaws s3 cp test-file.txt s3://BUCKET_NAME/test-file.txtReplace BUCKET_NAME with the bucket name from the stack outputs.
View scanner Lambda logs:
aws logs tail /aws/lambda/AttachmentAVExampleStack-AttachmentAVScannerScannerFunction* --followView callback Lambda logs:
aws logs tail /aws/lambda/AttachmentAVExampleStack-AttachmentAVScannerCallbackFunction* --followaws s3api get-object-tagging \
--bucket BUCKET_NAME \
--key test-file.txtEdit stacks/example-stack.ts to customize:
- Trigger strategy: Change to
TriggerStrategy.EVENTBRIDGEfor EventBridge-based triggers - File filtering: Add
s3KeyPrefixors3KeySuffixto scan only specific files - Tagging: Set
tagObjectWithScanResult: falseto disable tagging - Auto-delete: Set
deleteInfectedObject: trueto automatically delete infected files - API endpoint: Add
apiUrlto use a different attachmentAV region
To delete all resources:
npx cdk destroyThis will remove:
- The S3 bucket (and all objects due to
autoDeleteObjects: true) - All Lambda functions
- The IAM user and access keys
- SSM parameters created by the construct
- All other AWS resources created by the stack
Note: The API key SSM parameter (/attachmentav/api-key) must be deleted manually:
aws ssm delete-parameter --name "/attachmentav/api-key"npx cdk diff- Compare deployed stack with current statenpx cdk ls- List all stacks in the appnpx cdk synth- Synthesize CloudFormation templatenpx cdk deploy- Deploy the stacknpx cdk destroy- Delete the stacknpx cdk doctor- Check CDK setup
Make sure you created the SSM parameter as described in step 2 of Setup.
Ensure your AWS credentials have sufficient permissions to create:
- S3 buckets
- Lambda functions
- IAM roles and users
- SSM parameters
- EventBridge rules (if using EventBridge trigger)
- Check CloudWatch Logs for errors
- Verify S3 event notifications are configured:
aws s3api get-bucket-notification-configuration --bucket BUCKET_NAME - Ensure the file matches any prefix/suffix filters you configured