<?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: Rameesha Khan</title>
    <description>The latest articles on DEV Community by Rameesha Khan (@rameeshakhan).</description>
    <link>https://dev.to/rameeshakhan</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%2F1254005%2Faef6685e-d95b-4d39-8082-10aa64761e37.png</url>
      <title>DEV Community: Rameesha Khan</title>
      <link>https://dev.to/rameeshakhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rameeshakhan"/>
    <language>en</language>
    <item>
      <title>Handle Python Packages in Lambda Environment</title>
      <dc:creator>Rameesha Khan</dc:creator>
      <pubDate>Thu, 11 Jan 2024 08:36:08 +0000</pubDate>
      <link>https://dev.to/rameeshakhan/handle-python-packages-in-lambda-environment-4akf</link>
      <guid>https://dev.to/rameeshakhan/handle-python-packages-in-lambda-environment-4akf</guid>
      <description>&lt;p&gt;I was working on a microservice in which I need to make a lambda service for a flask application. And I was like yeah so easy man! but as soon as I dive into the project, I faced problem with managing python packages. So I am here to tell you how to easily cope up with this problem.&lt;/p&gt;

&lt;p&gt;Follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First of all create a python project using serverless either lambda function or an API gateway or any other. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialize npm in the project by typing command&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`npm init`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
Install the plugin named &lt;em&gt;serverless-python-requirements&lt;/em&gt; by command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`npm i serverless-python-requirements`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
Add these lines in your yml file &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8lrh5k9pye8cgc7rxcsy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8lrh5k9pye8cgc7rxcsy.png" alt="Plugin Configuration in yml file " width="401" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, create a virtual environment for installing the packages. If you don't create a virtual environment it will install all the packages in the root directory and your folder structure would be a mess and it is necessary to have a virtual environment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
For creating a virtual environment: 
You can use either of the command. Here i am creating a virtual environment named &lt;em&gt;"venv"&lt;/em&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;virtualenv venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for &lt;code&gt;vitualenv&lt;/code&gt; you should have the pacakage or you can install by using command &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;pip install virtualenv&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now after running this command you will see a venv folder has been created into your directory. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
After creating virtual environment activate the environment by typing the command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;venv\Scripts\activate.bat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Additional Info: If you want to be out of the virtual env, type&lt;br&gt;
&lt;code&gt;venv\Scripts\deactivate.bat&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;when activated, you will see the environment name in the left side of the terminal.&lt;/p&gt;

&lt;p&gt;Now in this environment, you can install all the packages needed for your application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
After installing all the packages you have to make a requirments.txt file for listing down all the packages necessary for the application. For this you don't need to list all the packages manually, just type in the command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will list all the packages with their installed versions.&lt;/p&gt;

&lt;p&gt;Now you are almost right there, just one thing is needed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
After doing all the steps you have to install docker in your system and start that in your machine. Importantly don't forget to add these lines into your &lt;em&gt;yml&lt;/em&gt; file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0gy03xva7zwmv4lnh3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0gy03xva7zwmv4lnh3j.png" alt="Docker Configuration in yml file" width="402" height="86"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically what it will do is to tell the AWS SAM to use docker to install packages in a non-linux environment.&lt;/p&gt;

&lt;p&gt;At the time of deployment, It will first look into the requirments.txt file and install all the listed packages which will make them available for the application.&lt;/p&gt;

&lt;p&gt;And voila ! you are all set to depend on dependencies.&lt;/p&gt;

</description>
      <category>pythonpackages</category>
      <category>aws</category>
      <category>lambda</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
