Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scan): add support for specifying the scan function timeout #1340

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v5.0.0
hooks:
- id: check-json
- id: trailing-whitespace
exclude: ^API.md||.github/$
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.25.0
rev: v8.56.0
hooks:
- id: eslint
files: \.[jt]sx?$
Expand Down
15 changes: 15 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export interface ServerlessClamscanProps {
* @see https://docs.aws.amazon.com/lambda/latest/operatorguide/computing-power.html
*/
readonly scanFunctionMemorySize?: number;
/**
* Optionally set the timeout for the scan function. (Default: 15 minutes).
*/
readonly scanFunctionTimeout?: Duration;
/**
* The Lambda Destination for files marked 'CLEAN' or 'INFECTED' based on the ClamAV Virus scan or 'N/A' for scans triggered by S3 folder creation events marked (Default: Creates and publishes to a new Event Bridge Bus if unspecified).
*/
Expand Down Expand Up @@ -428,7 +432,7 @@ export class ServerlessClamscan extends Construct {
vpc: vpc,
vpcSubnets: { subnets: vpc.isolatedSubnets },
allowAllOutbound: false,
timeout: Duration.minutes(15),
timeout: props.scanFunctionTimeout ?? Duration.minutes(15),
memorySize: props.scanFunctionMemorySize ?? 10240,
reservedConcurrentExecutions: props.reservedConcurrency,
environment: {
Expand Down
19 changes: 18 additions & 1 deletion test/ServerlessClamscan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { ABSENT, anything, arrayWith, objectLike, stringLike } from '@aws-cdk/assert';
import { Size, Stack } from 'aws-cdk-lib';
import { Duration, Size, Stack } from 'aws-cdk-lib';
import { PerformanceMode, ThroughputMode } from 'aws-cdk-lib/aws-efs';
import { EventBus } from 'aws-cdk-lib/aws-events';
import { SqsDestination, EventBridgeDestination } from 'aws-cdk-lib/aws-lambda-destinations';
Expand Down Expand Up @@ -959,3 +959,20 @@ test('expect EFS throughput mode to be set as configured', () => {
ThroughputMode: 'provisioned',
});
});

test('expect scan function timeout default to be 15 minutes', () => {
const stack = new Stack();
new ServerlessClamscan(stack, 'default', {});
expect(stack).toHaveResourceLike('AWS::Lambda::Function', {
Timeout: 900,
});
});

test('expect scan function timeout to be set as configured', () => {
const stack = new Stack();
new ServerlessClamscan(stack, 'default', { scanFunctionTimeout: Duration.minutes(5) });
expect(stack).toHaveResourceLike('AWS::Lambda::Function', {
Timeout: 300,
});
});

Loading