This directory contains the CloudFormation template for the AttachmentAV Bucket Scan solution. It uses the same architecture like the CDK construct and also takes the Lambda function's code from there.
- AWS CLI configured with appropriate credentials
- AttachmentAV API key stored in AWS Systems Manager Parameter Store
Deploy the stack directly using the AWS CLI:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name bucket-scan-cfn \
--capabilities CAPABILITY_IAM \
--parameter-overrides ApiKeyParameterName=/attachmentav/api-key| Parameter | Description |
|---|---|
ApiKeyParameterName |
SSM Parameter name containing the AttachmentAV API key |
| Parameter | Default | Description |
|---|---|---|
TriggerStrategy |
S3_EVENT |
Trigger strategy: S3_EVENT or EVENTBRIDGE |
TagObjectWithScanResult |
true |
Tag objects with scan results: true or false |
DeleteInfectedObject |
false |
Delete infected objects: true or false |
S3KeyPrefix |
(empty) | S3 key prefix filter for triggering scans |
S3KeySuffix |
(empty) | S3 key suffix filter for triggering scans |
ApiUrl |
https://eu.developer.attachmentav.com |
AttachmentAV API base URL |
TenantId |
(empty) | AttachmentAV tenant ID for callback verification |
Deploy with minimal settings:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name bucket-scan-cfn \
--capabilities CAPABILITY_IAM \
--parameter-overrides ApiKeyParameterName=/attachmentav/api-keyDeploy with a custom stack name:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name prod-malware-scanner \
--capabilities CAPABILITY_IAM \
--parameter-overrides ApiKeyParameterName=/attachmentav/api-keyConfigure the scanner to only process PDF files in the uploads/ directory:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name bucket-scan-cfn \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
ApiKeyParameterName=/attachmentav/api-key \
S3KeyPrefix=uploads/ \
S3KeySuffix=.pdfEnable automatic deletion of infected files:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name bucket-scan-cfn \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
ApiKeyParameterName=/attachmentav/api-key \
DeleteInfectedObject=trueDeploy with EventBridge instead of S3 Event notifications:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name bucket-scan-cfn \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
ApiKeyParameterName=/attachmentav/api-key \
TriggerStrategy=EVENTBRIDGEDeploy with all options configured:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name prod-scan \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
ApiKeyParameterName=/attachmentav/api-key \
TriggerStrategy=S3_EVENT \
TagObjectWithScanResult=true \
DeleteInfectedObject=false \
S3KeyPrefix=documents/ \
S3KeySuffix=.pdf \
ApiUrl=https://us.developer.attachmentav.com \
TenantId=your-tenant-idNote: The
build.shscript is only used during the development process of this repository to update thetemplate.yamlfile with the latest Lambda function code as inline code.
- Node.js and npm installed
- esbuild installed globally or in the project (
npm install -g esbuild)
The build.sh script:
- Compiles TypeScript Lambda functions from
../lib/using esbuild - Inlines the bundled JavaScript code directly into
template.yamlusing CloudFormation'sZipFilesyntax - Updates the template in place (can be run multiple times)
To rebuild the template with updated Lambda code:
./build.shThis is typically only needed when:
- Lambda function source code in
../lib/has been modified - You're maintaining or contributing to this repository
After successful deployment, the stack provides important outputs:
- BucketName: Name of the S3 bucket being monitored
- ScannerFunctionArn: ARN of the scanner Lambda function
- CallbackFunctionArn: ARN of the callback Lambda function
- TriggerStrategy: The trigger strategy being used
View stack outputs:
aws cloudformation describe-stacks \
--stack-name bucket-scan-cfn \
--query 'Stacks[0].Outputs' \
--output table- Uses native S3 event notifications
- Lower latency
- Directly invokes Lambda function
- Recommended for most use cases
- Routes S3 events through Amazon EventBridge
- More flexible for complex event routing
- Allows additional event consumers
- Slightly higher latency
Ensure the SSM parameter exists:
aws ssm get-parameter --name /attachmentav/api-key --with-decryptionThe CloudFormation stack requires CAPABILITY_IAM because it creates IAM roles. Ensure your AWS credentials have
sufficient permissions to create IAM resources.