This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
forked from bluesentry/bucket-antivirus-function
-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (61 loc) · 2.36 KB
/
lambda.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Test with LocalStack
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt update && sudo apt install -y make wget
- name: build docker image
run: make archive
- name: Start LocalStack
uses: LocalStack/setup-localstack@main
with:
image-tag: 'latest'
install-awslocal: 'true'
- name: Run tests against localstack
run: |
awslocal s3 mb s3://antivirus-definitions
awslocal s3 mb s3://test-bucket
wget https://secure.eicar.org/eicar_com.zip
awslocal s3 cp eicar_com.zip s3://test-bucket/eicar_com.zip
awslocal lambda create-function \
--function-name update-clamav \
--runtime python3.12 \
--handler update.lambda_handler \
--role arn:aws:iam::123456789012:role/lambda-role \
--zip-file fileb://./build/lambda.zip \
--timeout 120 \
--environment "Variables={AV_DEFINITION_S3_BUCKET=antivirus-definitions}"
sleep 30
awslocal lambda invoke \
--function-name update-clamav \
--invocation-type RequestResponse \
--log-type Tail \
--payload '{}' \
response.json \
--query 'LogResult' | tr -d '"' | base64 -d
awslocal lambda create-function \
--function-name scan-clamav \
--runtime python3.12 \
--handler scan.lambda_handler \
--role arn:aws:iam::123456789012:role/lambda-role \
--zip-file fileb://./build/lambda.zip \
--timeout 120 \
--environment "Variables={AV_DEFINITION_S3_BUCKET=antivirus-definitions,AV_DELETE_INFECTED_FILES=True}"
sleep 30
awslocal lambda invoke \
--function-name scan-clamav \
--invocation-type RequestResponse \
--log-type Tail \
--payload '{"Records": [{"s3": {"bucket": {"name": "test-bucket"}, "object": {"key": "eicar_com.zip"}}}]}' \
response.json \
--query 'LogResult' | tr -d '"' | base64 -d
result=$(awslocal s3 ls s3://test-bucket)
if [ -z "$result" ]; then
echo "Bucket is empty"
else
echo "Bucket is not empty"
exit 1
fi