<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Georgios Philippou</title>
    <description>The latest articles on DEV Community by Georgios Philippou (@giorgosph).</description>
    <link>https://dev.to/giorgosph</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2883568%2Ff08c4446-29bf-4a07-8456-7281991fef8a.png</url>
      <title>DEV Community: Georgios Philippou</title>
      <link>https://dev.to/giorgosph</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/giorgosph"/>
    <language>en</language>
    <item>
      <title>Setting Up ClamAV for AWS - File Scan</title>
      <dc:creator>Georgios Philippou</dc:creator>
      <pubDate>Wed, 19 Feb 2025 18:20:16 +0000</pubDate>
      <link>https://dev.to/giorgosph/setting-up-clamav-for-aws-file-scan-4m3c</link>
      <guid>https://dev.to/giorgosph/setting-up-clamav-for-aws-file-scan-4m3c</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;This guide outlines the step-by-step process to set up ClamAV as an AWS Lambda layer. The steps are performed in AWS CloudShell, which runs on the same environment as AWS Lambda. By following these instructions, you'll be able to create a ClamAV layer for scanning files uploaded to S3 or other storage services.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Install Required Binaries
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.1 Install ClamAV in CloudShell
&lt;/h3&gt;

&lt;p&gt;First, install ClamAV:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dnf &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; clamav clamav-update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1.2 Update ClamAV Virus Definitions
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;freshclam&lt;/code&gt; to download the latest virus signatures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;freshclam
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Construct the Lambda Layer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Prepare ClamAV Files
&lt;/h3&gt;

&lt;p&gt;Create a working directory for ClamAV files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;lambda_clamav
&lt;span class="nb"&gt;cd &lt;/span&gt;lambda_clamav
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy necessary binaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; /usr/bin/clamscan /usr/bin/freshclam &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2.2 Configure ClamAV
&lt;/h3&gt;

&lt;p&gt;Generate the ClamAV configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;clamconf &lt;span class="nt"&gt;-g&lt;/span&gt; freshclam.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; freshclam.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit &lt;code&gt;freshclam.conf&lt;/code&gt; to adjust settings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove the &lt;code&gt;Example&lt;/code&gt; line.&lt;/li&gt;
&lt;li&gt;Change &lt;code&gt;DatabaseDirectory&lt;/code&gt; from &lt;code&gt;/var/lib/clamav&lt;/code&gt; to &lt;code&gt;/tmp/&lt;/code&gt; (Lambda only allows write access to &lt;code&gt;/tmp&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Uncomment &lt;code&gt;DatabaseMirror database.clamav.net&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 Copy Required Shared Libraries
&lt;/h3&gt;

&lt;p&gt;Check dependencies for &lt;code&gt;clamscan&lt;/code&gt; and &lt;code&gt;freshclam&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ldd clamscan
ldd freshclam
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy all listed libraries to &lt;code&gt;lambda_clamav&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.4 Clean-Up Packages
&lt;/h3&gt;

&lt;p&gt;To save space, and to test the layer without any conflicts, remove ClamAV after copying the necessary files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;dnf remove &lt;span class="nt"&gt;-y&lt;/span&gt; clamav clamav-update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Test ClamAV in CloudShell
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Set the Library Path
&lt;/h3&gt;

&lt;p&gt;Note that you will have to set the &lt;code&gt;LD_LIBRARY_PATH&lt;/code&gt; within the Lambda function to point to the layer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/home/cloudshell-user/lambda_clamav:&lt;span class="nv"&gt;$LD_LIBRARY_PATH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.2 Update Virus Definitions in CloudShell
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./freshclam &lt;span class="nt"&gt;--config-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/home/cloudshell-user/lambda_clamav/freshclam.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.3 Perform a Test Scan
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./clamscan &lt;span class="nt"&gt;--database&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/tmp /path/to/test-file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Package and Publish the Layer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Package the ClamAV Files
&lt;/h3&gt;

&lt;p&gt;Navigate to the parent directory and zip the files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
zip &lt;span class="nt"&gt;-r&lt;/span&gt; lambda_clamav.zip lambda_clamav/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4.2 Publish the Layer to AWS Lambda
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda publish-layer-version &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--layer-name&lt;/span&gt; clamav-layer &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--zip-file&lt;/span&gt; fileb:///home/cloudshell-user/lambda_clamav.zip &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--compatible-runtimes&lt;/span&gt; &amp;lt;the-lambda-runtime&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--region&lt;/span&gt; &amp;lt;your-region&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lambda Configuration Considerations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Timeout&lt;/strong&gt;: Allow enough time for the scans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory (CPU Allocation)&lt;/strong&gt;: Set to &lt;strong&gt;2048 MB&lt;/strong&gt;, though actual usage may be lower. Test with sufficient resources and adjust as needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layer Path in Lambda&lt;/strong&gt;: The ClamAV layer will be accessible in &lt;strong&gt;&lt;code&gt;/opt/lambda_clamav&lt;/code&gt;&lt;/strong&gt; inside your Lambda function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Notes
&lt;/h2&gt;

&lt;p&gt;This guide should help you set up ClamAV for AWS Lambda efficiently. If you have questions or want to discuss the methodology I used within the Lambda function, feel free to reach out. 🚀&lt;/p&gt;

</description>
      <category>aws</category>
      <category>clamav</category>
      <category>lambda</category>
      <category>security</category>
    </item>
  </channel>
</rss>
