<?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>Forem: Pranjali Shirke</title>
    <description>The latest articles on Forem by Pranjali Shirke (@pranjalishirkeworkspace).</description>
    <link>https://forem.com/pranjalishirkeworkspace</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%2F1015480%2F12a64bd8-99ef-46eb-a11e-def43cb3556a.png</url>
      <title>Forem: Pranjali Shirke</title>
      <link>https://forem.com/pranjalishirkeworkspace</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pranjalishirkeworkspace"/>
    <language>en</language>
    <item>
      <title>Mocking AWS services for local development using LocalStack</title>
      <dc:creator>Pranjali Shirke</dc:creator>
      <pubDate>Mon, 30 Jan 2023 06:31:45 +0000</pubDate>
      <link>https://forem.com/epam_india_python/mocking-aws-services-for-local-development-using-localstack-mk9</link>
      <guid>https://forem.com/epam_india_python/mocking-aws-services-for-local-development-using-localstack-mk9</guid>
      <description>&lt;h1&gt;
  
  
  Introduction to LocalStack
&lt;/h1&gt;

&lt;p&gt;During local development, it can be expensive to use an AWS services license and to ensure the resources used stay within the allocated limits. LocalStack is an alternative that can remove the dependency on AWS services during local development and allow you to mock the services offline.&lt;/p&gt;

&lt;p&gt;LocalStack is a cloud service emulator that runs in a single container on your laptop. It is an open-source mock for real AWS services. LocalStack allows us to test or develop applications that need AWS without connecting with AWS. &lt;/p&gt;

&lt;p&gt;LocalStack has various flavors – Community, Pro, and Enterprise. Pro and Enterprise require us to purchase license, but the Community Edition option is free for personal usage. Some differences between Community and Paid versions (Pro onwards) onwards are as follows: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhs6qkxr477cyq3rpu7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhs6qkxr477cyq3rpu7c.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Installing LocalStack
&lt;/h1&gt;

&lt;p&gt;Here, I am going to install LocalStack using docker-compose. &lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;We need to install the following packages: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker, docker-compose and npm &lt;/li&gt;
&lt;li&gt;pip install botocore boto3 localstack awscli&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In AWS credentials, we can add mock access id and access key.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[localstack] &lt;br&gt;
aws_access_key_id = Test &lt;br&gt;
aws_secret_access_key = Test &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Getting LocalStack Up and Running
&lt;/h2&gt;

&lt;p&gt;To start using the LocalStack, we need to paste the below content in a file and save the file as docker-compose.yaml.&lt;/p&gt;

&lt;p&gt;Docker-compose.yaml  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8l4ojud9nl1j8xkp873r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8l4ojud9nl1j8xkp873r.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can add more configurations as needed in the docker-compose.yaml file. For more information on Docker compose extra configurations, refer &lt;a href="https://docs.localstack.cloud/references/configuration/" rel="noopener noreferrer"&gt;https://docs.localstack.cloud/references/configuration/&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Next, through the terminal / command prompt, navigate to the folder containing the docker-compose.yaml file and type docker-compose up -d to start the LocalStack.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bqep2q7b4zsue4f6o3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bqep2q7b4zsue4f6o3y.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once done, check if all the services are running by hitting the following url on browser: &lt;a href="http://localhost:4566/health" rel="noopener noreferrer"&gt;http://localhost:4566/health&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2631a2j7sqge77gv4nck.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2631a2j7sqge77gv4nck.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  LocalStack implementation examples:
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;All the code samples are developed and tested using community version of LocalStack.&lt;br&gt;&lt;br&gt;
Little to no changes are required if you have an existing code that uses AWS services. In the community version, we need to add endpoint_url parameter when making the AWS calls. Here, the endpoint_url points to the localhost.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  S3 (Simple Storage Service) with LocalStack
&lt;/h2&gt;

&lt;p&gt;In community versions, we do not have access to the s3 storage location in local system. Though the files persist in the docker container as long as the session persists. &lt;/p&gt;

&lt;p&gt;LocalStack document for reference: &lt;a href="https://docs.localstack.cloud/user-guide/aws/s3/" rel="noopener noreferrer"&gt;https://docs.localstack.cloud/user-guide/aws/s3/&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  S3 Sample Code
&lt;/h3&gt;

&lt;p&gt;We have created S3Storage Class &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcl54i96gjcfvm2ssobjn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcl54i96gjcfvm2ssobjn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Calling the methods from main python file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgu9dc6a9klns99s2ih14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgu9dc6a9klns99s2ih14.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Output:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4z0wqctnho2peirotq5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4z0wqctnho2peirotq5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To see the files in the created buckets on the browser, go to &lt;a href="http://localhost:4566/%7Byour-bucket-name%7D" rel="noopener noreferrer"&gt;http://localhost:4566/{your-bucket-name}&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhq7fxokak4lp96awuqna.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhq7fxokak4lp96awuqna.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To have a look at a particular file in the bucket or to download a file, go to: &lt;a href="http://localhost:4566/%7Byour-bucket-name%7D/%7Bfile-name%7D" rel="noopener noreferrer"&gt;http://localhost:4566/{your-bucket-name}/{file-name}&lt;/a&gt;. This will download the file through your browser. &lt;/p&gt;

&lt;h2&gt;
  
  
  SNS (Simple Notification Service) with LocalStack
&lt;/h2&gt;

&lt;p&gt;LocalStack documentation for reference: &lt;a href="https://docs.localstack.cloud/user-guide/aws/sns/" rel="noopener noreferrer"&gt;https://docs.localstack.cloud/user-guide/aws/sns/&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  SNS Sample Code
&lt;/h3&gt;

&lt;p&gt;We have SNS service class with implementations. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsbi1ozaadwcx9yj0z2kz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsbi1ozaadwcx9yj0z2kz.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We are calling the functions through main.py &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F36d4x2k2pzc77eyxklju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F36d4x2k2pzc77eyxklju.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  SNS Code Output
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzskexwka045vq3xmle7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzskexwka045vq3xmle7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SSM (Systems Manager) with LocalStack
&lt;/h2&gt;

&lt;p&gt;SSM Local Stack documentation: &lt;a href="https://docs.localstack.cloud/user-guide/aws/systems-manager/" rel="noopener noreferrer"&gt;https://docs.localstack.cloud/user-guide/aws/systems-manager/&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  SSM Parameter Store Sample Code
&lt;/h3&gt;

&lt;p&gt;SSM service class with put and get parameter implementations. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgiarb7q4nfvho7140hat.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgiarb7q4nfvho7140hat.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Calling the methods in main.py &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0sws0zpa4nmupv7iwci4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0sws0zpa4nmupv7iwci4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  SSM Code Output:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fam57w9wnaratyon247xd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fam57w9wnaratyon247xd.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h1&gt;
  
  
  Advantages and Limitations:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Advantages
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It allows us to communicate with AWS services with little to no changes in the existing code. &lt;/li&gt;
&lt;li&gt;It allows us to develop and test AWS services without internet. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We need to use a third-party app Commandeer to get a UI (User Interface) for monitoring LocalStack. &lt;/li&gt;
&lt;li&gt;LocalStack docker container needs to be running to work with LocalStack. &lt;/li&gt;
&lt;li&gt;For community version, restarting the container causes loss of data as the everything is stored inside the container. &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Summary and Conclusion
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;LocalStack can be a good option for local development and testing.
&lt;/li&gt;
&lt;li&gt;There is no dependency on AWS accounts, and we do not need to be worried about exceeding the resource limits. &lt;/li&gt;
&lt;li&gt;As LocalStack is locally present, development or testing that requires huge data upload/download on S3, etc can be done even if we are facing bandwidth issues. &lt;/li&gt;
&lt;li&gt;To get more from LocalStack, we would need to purchase the pro license. It will allow us to use LocalStack with our AWS services code base by keeping our source code as is. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer &lt;br&gt;
This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally. &lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>aws</category>
      <category>localstack</category>
      <category>localdevelopment</category>
      <category>python</category>
    </item>
  </channel>
</rss>
