<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rafael Rodriguez on Medium]]></title>
        <description><![CDATA[Stories by Rafael Rodriguez on Medium]]></description>
        <link>https://medium.com/@rafael-a-rodriguez-m?source=rss-d9fd5861fc90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u7Fra0e4FBKieq4jSXBdSg.jpeg</url>
            <title>Stories by Rafael Rodriguez on Medium</title>
            <link>https://medium.com/@rafael-a-rodriguez-m?source=rss-d9fd5861fc90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:32:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rafael-a-rodriguez-m/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using AWS Services with Lambda Functions Beyond the Cloud]]></title>
            <link>https://towardsaws.com/using-aws-services-with-lambda-functions-beyond-the-cloud-628668e70797?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/628668e70797</guid>
            <category><![CDATA[industry-4-0]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Mon, 27 Jan 2025 06:40:29 GMT</pubDate>
            <atom:updated>2025-01-27T06:40:29.837Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered how to integrate locally deployed Lambda functions with AWS cloud services? Here’s how to make it happen.</p><p>Building on the ongoing <a href="https://towardsaws.com/deploy-lambda-functions-out-of-the-cloud-182237622f44">series</a> about AWS Greengrass and running Lambda functions outside the cloud, the previous article covered deploying a Lambda function locally. In this installment, we’ll explore how to connect such a setup with AWS cloud services — in this case, Amazon Translate.</p><p>The architecture will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*1mqv7cQXNEQqkchxEtWHjw.png" /></figure><p>In this case, we’ll outline the additional steps required to enable a local Lambda function in AWS Greengrass to use Amazon Translate. Referring to the diagram above, the process involves redeploying the Lambda function from the previous article to handle an event containing the text to be translated. The Lambda function will then invoke Amazon Translate to process the request, retrieve the translated text in the target language, and log the output for review.</p><h3>Deploying the code</h3><p>To implement the architecture, the first step is to modify the Lambda function to integrate with Amazon Translate. The updated code is shown below:</p><pre>import json<br>import boto3<br><br>client = boto3.client(&quot;translate&quot;)<br><br>def lambda_handler(event, context):<br><br>    response = client.translate_text(<br>        Text=&quot;esta es una traduccion de español a ingles usando amazon translate&quot;,<br>        SourceLanguageCode=&quot;es&quot;,<br>        TargetLanguageCode=&quot;en&quot;,<br>    )<br><br>    print(response[&quot;TranslatedText&quot;])<br>    return {<br>        &#39;statusCode&#39;: 200,<br>        &#39;body&#39;: json.dumps(response[&quot;TranslatedText&quot;])<br>    }</pre><p>To use this code in a locally running Lambda function, you’ll need to create a new version. To do this, navigate to the <strong>Versions</strong> tab in the Lambda management console and click <strong>Publish New Version</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSK516D4sEbuX3Y-G59Evg.png" /></figure><p>With the new version set up — version 2 in this case — it’s now time to update the component to utilize this updated code.</p><h3>Update the component</h3><p>To update the component, navigate to <strong>IoT Core Service</strong> &gt; <strong>Greengrass Devices</strong> &gt; <strong>Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BkZSxdD92M9qCr5NndftYQ.png" /></figure><p>Click on your component’s name, then select <strong>Create New Version</strong> to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*S69G3jhop31R0O7tHjsznQ.png" /></figure><p>In this window, ensure two key details:</p><ol><li>The <strong>Lambda Version</strong> is set to the new version you just created (version 2 in this case).</li><li>The <strong>Component Version</strong> is updated to the latest, which in this case will be 1.0.1.</li></ol><p>Once these are confirmed, proceed to create the component.</p><h3>Create the deployment</h3><p>With the component now updated with the latest code, it’s time to deploy it to the device. This can be done by creating or revising a deployment.</p><p>To do this:</p><ol><li>In the AWS Management Console, navigate to <strong>AWS IoT Core</strong> &gt; <strong>Greengrass Devices</strong> &gt; <strong>Deployments</strong>.</li><li>Locate and select the component you previously used to deploy the Lambda in the earlier article.</li><li>In the top-right corner, click the <strong>Actions</strong> dropdown button and select <strong>Revise</strong> from the options.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MvXMsrthzdrdZaIicOl1BA.png" /></figure><p>During the revision process, you’ll need to make some adjustments. One key change is ensuring that the device has the <strong>TokenExchangeService</strong> component installed as a dependency to enable the use of Amazon Translate. To achieve this, modify the component configuration to include the <strong>TokenExchangeService</strong> component as a dependency, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IE57zHEgTNjwxfpoMOFuaw.png" /></figure><p>Next, update the configuration of the <strong>LambdaInGreengrass</strong> component to reference and use the latest version of the Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wxZlmPGte0QcZmuVSK-sg.png" /></figure><p>Your deployment configuration should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YeVvg01sodXv7pcMSopq0Q.png" /></figure><p>From this point, you can proceed to create the deployment.</p><h3>Testing the lambda</h3><p>To test the Lambda function, send a message to the topic you configured for the component — in this case, test/locallambda. Currently, the message content is not being processed, but you can enhance the functionality by reading and handling the event within the Lambda code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BrOg1QuLZJYnoZ1xYTtgDw.png" /></figure><p>Now, you can connect to the device to verify the logs. In my case, I will use SSH to establish the connection and then run the following command to view the logs:</p><pre>cat /greengrass/v2/logs/lambdaInGreengrass.log</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cb-0i35IbcZTL_4qQHuYJQ.png" /></figure><p>However, we encountered an error. This error occurs because our exchange role lacks the necessary permissions to call the service. While this may seem like a roadblock, it’s actually a positive indicator that we’re adhering to the principle of least privilege. To resolve this, update the exchange role by adding the required permission for the service.</p><h3>Ensure the Permissions Are Set Up in the Role</h3><p>To locate your token exchange role:</p><ol><li>Navigate to <strong>Security</strong> &gt; <strong>Role Alias</strong> in the AWS Management Console.</li><li>Within your role alias, find the <strong>Role ARN</strong>. The role name is at the end of this ARN.</li></ol><p>Next, go to the <strong>IAM</strong> service and search for your role to update its permissions as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSpc7s0GevQgDVtTxjc6Dg.png" /></figure><p>This is the current configuration of my exchange role. Now, we need to add the necessary permissions to enable the Lambda function to call the required service.</p><pre>translate:TranslateText</pre><p>In the action, the configuration should look like this at the end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mI6sAyNKAw8FCRwCbOCmeg.png" /></figure><p>Now, send a new MQTT message to the device and validate the logs, just as we did earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*733eXpV6y4wPlFXB9AMJaQ.png" /></figure><h3>Conclusion</h3><p>Leveraging AWS services from Lambda functions outside of the cloud opens up exciting possibilities for building flexible and distributed systems. By integrating AWS IoT Greengrass, you can extend the powerful capabilities of cloud-based Lambda functions to edge devices, enabling real-time processing, local decision-making, and reduced latency.</p><p>This approach not only enhances application responsiveness but also reduces data transfer costs and bolsters security by processing sensitive data closer to its source. Whether you’re working on IoT solutions, hybrid architectures, or edge computing scenarios, this architecture exemplifies how AWS services can bridge the gap between the cloud and the edge.</p><p>By embracing these techniques, developers can unlock the full potential of AWS services to create innovative, scalable, and resilient applications, even in environments where consistent cloud connectivity is unavailable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=628668e70797" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/using-aws-services-with-lambda-functions-beyond-the-cloud-628668e70797">Using AWS Services with Lambda Functions Beyond the Cloud</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Lambda Functions Out of the Cloud]]></title>
            <link>https://towardsaws.com/deploy-lambda-functions-out-of-the-cloud-182237622f44?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/182237622f44</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[greengrass]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[industry-4-0]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Sun, 26 Jan 2025 06:04:19 GMT</pubDate>
            <atom:updated>2025-01-26T06:04:19.192Z</atom:updated>
            <content:encoded><![CDATA[<p>Running Lambda functions in the cloud is second nature to anyone familiar with AWS. But did you know that Lambda functions aren’t confined to the cloud? They can also be deployed on-premises — whether on AWS Outposts or even on IoT devices. Curious about how to make that happen? You’re in the right place.</p><p>In this article, I’ll guide you through the steps to deploy Lambda functions outside the cloud. The first thing you’ll need is a device with AWS Greengrass installed. Don’t have one set up yet? No problem! You can follow <a href="https://medium.com/towards-aws/aws-greengrass-101-installing-the-greengrass-core-29a8e1d79982">this guide</a> to install Greengrass on an EC2 instance. Let’s dive in!</p><p>This is how the deployment process flows, step by step:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*_Iluh8LPR0-cYm9oxWMFqg.png" /></figure><h3>Set Up Your Lambda Function with Your Custom Logic</h3><p>Navigate to the AWS Management Console, search for the Lambda service, and click “Create Function” to get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PEXcpI0f_UZnUQt6b-ZsrA.png" /></figure><p>To create a component based on a Lambda function, you must enable versioning. In the Lambda console, navigate to the “Versions” tab and publish a new version of your function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_EIbdsP9udbO--bauSDAzA.png" /></figure><h3>Create a Greengrass Component</h3><p>With your Lambda function versioning enabled, it’s time to create the AWS Greengrass component. Head to the AWS IoT Core service, and in the right-hand panel, select “Greengrass Devices” From the submenu, choose “Components”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00Ft77XAiHewNUI68HdioA.png" /></figure><p>On the main screen, click “Create Component” Choose the “Import Lambda Function” option, then select your Lambda function and its version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4L9NG5n9EjozDIEBqsi5TA.png" /></figure><p>In the configuration settings, choose a topic to trigger the Lambda function. For the type, select “IoT Core MQTT” to enable triggering from the cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pE6WlB_JXWxNRsnrMytNhg.png" /></figure><p>For simplicity in this tutorial, select “No Container” as the isolation mode. (However, using container isolation is highly recommended for production environments.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gd7hAPmPhXdRALm9jqNTWA.png" /></figure><p>Once all configurations are set, click “Create Component” to complete the process</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJgTl8OEsP2-WPlGjjDBog.png" /></figure><h3>Create or Revise Greengrass Deployment</h3><p>Now it’s time to deploy your component to the device. If you already have a deployment from setting up your AWS Greengrass device, you can revise it in this step.</p><p>Navigate to <strong>Greengrass Devices &gt; Deployments</strong> and locate the deployment associated with your device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7kDkB9aUFjlOLO8-5_938g.png" /></figure><p>In the top-right corner, click the <strong>Actions</strong> dropdown button and select <strong>Revise</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y4Tzy8TgbNTjPprD0G36Pw.png" /></figure><p>Ensure the deployment name is correct, then click <strong>Next</strong> to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W-ZWbbG3G8taE5akyy2TGA.png" /></figure><p>Now, choose the Lambda component you created in the earlier steps. In this example, it’s <strong>lambdaInGreengrass</strong>. After selecting it, click <strong>Next</strong> to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAfCqK4mmbSHvhMYElyU2w.png" /></figure><p>In the next step, you can adjust configurations for the components to be deployed. Since we’ve already defined the topic that will trigger the Lambda function, no further changes are needed here.</p><p>You’ll also have the option to configure how the deployment will roll out to devices. For this tutorial, since we’re working with a single device, no additional configuration is necessary. Simply click <strong>Next</strong> to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uOhCKBuKn8jUfHF7Mt2CA.png" /></figure><p>Take a moment to review all the configurations. If everything looks good, click <strong>Next</strong> to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEJXpgO3DI1DtZbeioYLqQ.png" /></figure><p>After about a minute, click on the deployment details to view its status. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Je6oydjj0yN-z8PuDsoB5A.png" /></figure><p>As you can see, the deployment was successful. Now, we’re ready to observe the component in action on the device.</p><h3>Review Lambda Component on the Greengrass Device</h3><p>To review the Lambda component installed on your device, you’ll need to connect to it. The connection process depends on the type of device where Greengrass is installed. For example, if you’re using an EC2 instance, you can connect via SSH.</p><p>Once connected, ensure the AWS Greengrass CLI is installed. This component is typically included by default when Greengrass is installed (if it isn’t, you can add it during the deployment process).</p><p>To view all the components installed on the device, run the following command:</p><pre>./greengrass/v2/bin/greengrass-cli component list</pre><p>Running the command will display a list of installed components on the device. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*9aaV5py6DClKGBN0h1gbvA.png" /></figure><p>As shown at the end of the list, the <strong>lambdaInGreengrass</strong> component is successfully installed.</p><p>Now, let’s test the component using the MQTT Test Client in the IoT Core service. We’ll send a message to the topic we specified during creation — in this case, <strong>test/locallambda</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_J1QO4dmdGzVu218jr8rSA.png" /></figure><p>To check the logs and monitor the component’s activity, run the following command:</p><pre>cat /greengrass/v2/logs/lambdaInGreengrass.log</pre><p>After running the command, you should see output similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KentRiTTXKqXuqUTRmSTTw.png" /></figure><h3>Wrapping It Up</h3><p>Deploying Lambda functions outside the cloud opens up a realm of possibilities, especially for edge computing and offline scenarios. Whether you’re leveraging AWS IoT Greengrass, running on-premises servers, or integrating with hybrid cloud architectures, the flexibility of Lambda functions ensures that your application remains efficient and scalable.</p><p>As the cloud evolves, so do the ways we can extend its capabilities to suit unique requirements. By following these steps, you can ensure a seamless deployment process while enjoying the benefits of AWS Lambda’s powerful features — wherever you need them.</p><p>Now it’s your turn! Experiment with deploying Lambda functions outside the cloud and let me know how it worked for your use case. If you have insights or questions, drop them in the comments below — I’d love to hear from you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=182237622f44" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/deploy-lambda-functions-out-of-the-cloud-182237622f44">Deploy Lambda Functions Out of the Cloud</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide to Job Execution with AWS IoT Device Client]]></title>
            <link>https://towardsaws.com/step-by-step-guide-to-job-execution-with-aws-iot-device-client-d04bdf0187c7?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/d04bdf0187c7</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[iot-core]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Tue, 23 Jan 2024 09:05:57 GMT</pubDate>
            <atom:updated>2024-01-23T09:05:57.429Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you ready to dive deeper into the world of the IoT device client? Great, because today I’m excited to walk you through a thrilling simulation of job execution using the IoT device client. Don’t worry if you’re not quite an expert yet — if you need a refresher or you’re just starting out, feel free to check out the introductory article I’ve linked right <a href="https://towardsaws.com/the-easiest-way-to-simulate-a-fully-functional-iot-device-in-aws-46fba600f8ac">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gsKIp1mTbEx5mRYpwmhNBA.png" /></figure><h3>How we’ll tackle this in five steps:</h3><ol><li>Start by setting up a handler in the Device Client.</li><li>Update the device policy so it’s ready to work with jobs.</li><li>Create the job you want to run.</li><li>Fire up the IoT Client.</li><li>Execute the job and watch it in action.</li></ol><h3>Setup the handler in the Device Client</h3><p>Alright, let’s continue where we left off from the previous article. We had our device running smoothly in a Docker container, all set up to connect to AWS with the credentials we supplied. Now, we’re going to take it up a notch by adding a new script that will spring into action when a job is received.</p><p>Our mission? To demonstrate the steps of installing a package, downloading a file, and then removing the package. To make this happen, let’s roll up our sleeves and set up our workspace.</p><p>First things first, we’ll create a new folder called job_handler. Inside this folder, let&#39;s craft our first scripts named download-file.sh , install-packages.sh , remove-packages.sh .</p><blockquote>download-file.sh</blockquote><pre>#!/usr/bin/env sh<br>set -e</pre><pre>echo &quot;Running download-file.sh&quot;<br>user=$1<br>fileUrl=$2<br>outputFile=$3<br>echo &quot;Username: $user&quot;<br>echo &quot;File URL: $fileUrl&quot;<br>echo &quot;Write documents to file: $outputFile&quot;<br>if command -v &quot;wget&quot; &gt; /dev/null<br>then<br>    echo &quot;Using wget for downloading user specified file&quot;<br>    if id &quot;$user&quot; 2&gt;/dev/null &amp;&amp; command -v &quot;sudo&quot; &gt; /dev/null; then<br>      if [ -d &quot;$outputFile&quot; ]; then<br>        sudo -u &quot;$user&quot; -n wget --quiet -P &quot;$outputFile&quot; &quot;$fileUrl&quot;<br>      else<br>        sudo -u &quot;$user&quot; -n wget --quiet -O &quot;$outputFile&quot; &quot;$fileUrl&quot;<br>      fi<br>    else<br>      echo &quot;username or sudo command not found&quot;<br>      if [ -d &quot;$outputFile&quot; ]; then<br>        wget --quiet -P &quot;$outputFile&quot; &quot;$fileUrl&quot;<br>      else<br>        wget --quiet -O &quot;$outputFile&quot; &quot;$fileUrl&quot;<br>      fi<br>    fi<br>else<br>    &gt;&amp;2 echo &quot;Wget software package not installed on the device. Use the \&quot;install-packages.sh\&quot; operation to install the wget software package on this device.&quot;<br>    exit 1<br>fi</pre><blockquote>install-packages.sh</blockquote><pre>#!/usr/bin/env sh<br>set -e</pre><pre>echo &quot;Running install-packages.sh&quot;<br>user=$1<br>shift 1<br>packages=$@<br>echo &quot;Username: $user&quot;<br>echo &quot;Packages to install: $packages&quot;<br>if command -v &quot;apt-get&quot; &gt; /dev/null<br>then<br>    echo &quot;Using apt-get for package install&quot;<br>    # Squash any issues related to debconf frontend<br>    export DEBIAN_FRONTEND=noninteractive<br>    if id &quot;$user&quot; 2&gt;/dev/null &amp;&amp; command -v &quot;sudo&quot; &gt; /dev/null; then<br>        sudo -u &quot;$user&quot; -n apt-get install -y $packages<br>    else<br>        echo &quot;username or sudo command not found&quot;<br>        apt-get update -y<br>        apt-get install -y $packages<br>    fi<br>elif command -v &quot;yum&quot; &gt; /dev/null<br>then<br>  echo &quot;Using yum for package install&quot;<br>    if id &quot;$user&quot; 2&gt;/dev/null &amp;&amp; command -v &quot;sudo&quot; &gt; /dev/null; then<br>      sudo -u &quot;$user&quot; -n yum install -y $packages<br>    else<br>      echo &quot;username or sudo command not found&quot;<br>      yum install -y $packages<br>    fi<br>else<br>  &gt;&amp;2 echo &quot;No suitable package manager found&quot;<br>  exit 1<br>fi</pre><blockquote>remove-packages.sh</blockquote><pre>#!/usr/bin/env sh<br>set -e</pre><pre>echo &quot;Running remove-packages.sh&quot;<br>user=$1<br>shift 1<br>packages=$@<br>echo &quot;Username: $user&quot;<br>echo &quot;Packages to remove: $packages&quot;</pre><pre>if command -v &quot;apt-get&quot; &gt; /dev/null<br>then<br>    echo &quot;Using apt-get for removing packages&quot;<br>    # Squash any issues related to debconf frontend<br>    export DEBIAN_FRONTEND=noninteractive<br>    if id &quot;$user&quot; 2&gt;/dev/null &amp;&amp; command -v &quot;sudo&quot; &gt; /dev/null; then<br>        sudo -u &quot;$user&quot; -n apt-get remove -y --purge $packages<br>    else<br>        echo &quot;username or sudo command not found&quot;<br>        apt-get remove -y --purge $packages<br>    fi<br>elif command -v &quot;yum&quot; &gt; /dev/null<br>then<br>  echo &quot;Using yum for removing packages&quot;<br>    if id &quot;$user&quot; 2&gt;/dev/null &amp;&amp; command -v &quot;sudo&quot; &gt; /dev/null; then<br>      sudo -u &quot;$user&quot; -n yum remove -y $packages<br>    else<br>      echo &quot;username or sudo command not found&quot;<br>      yum remove -y $packages<br>    fi<br>else<br>  &gt;&amp;2 echo &quot;No suitable package manager found&quot;<br>  exit 1<br>fi</pre><p>Great, now that we have our three files ready, it’s time to bring the Device Client into play by enabling job handling in its configuration. To do this, we’ll make some tweaks to the config_template.json file.</p><p>Here’s what we’ll do:</p><p>Open up config_template.json and look for the section related to job handling. Once you find it, simply adjust the settings as shown in the example below to turn on job handling. It&#39;s like flipping a switch to let the Device Client know it&#39;s showtime for executing jobs.</p><p>By making this change, we’re telling our Device Client, “Hey, get ready to handle some jobs!” And with that, your device will be all set to take on the tasks we’ve scripted out.</p><blockquote>config_template.json</blockquote><pre>{<br> &quot;endpoint&quot;: &quot;&lt;replace_with_endpoint_value&gt;&quot;,<br> &quot;cert&quot;: &quot;&lt;replace_with_certificate_file_path&gt;&quot;,<br> &quot;key&quot;: &quot;&lt;replace_with_private_key_file_path&gt;&quot;,<br> &quot;root-ca&quot;: &quot;&lt;replace_with_root_ca_file_path&gt;&quot;,<br> &quot;thing-name&quot;: &quot;&lt;replace_with_thing_name/replace_with_client_id&gt;&quot;,<br> &quot;logging&quot;: {<br>  &quot;level&quot;: &quot;DEBUG&quot;,<br>  &quot;type&quot;: &quot;STDOUT&quot;,<br>  &quot;file&quot;: &quot;/var/log/aws-iot-device-client/aws-iot-device-client.log&quot;<br> },<br>  &quot;jobs&quot;: {<br>    &quot;enabled&quot;: true,<br>    &quot;handler-directory&quot;: &quot;job_handlers&quot;<br>  }<br>}</pre><p>Perfect! By adding a new ‘jobs’ key to your config-template.json, you&#39;ve effectively flipped the switch to &#39;enabled&#39; and pointed the Device Client towards the job_handler directory—that special folder where we&#39;ve stored our script files.</p><p>Your project directory is now set up for success. It should have a neat structure, something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*BijgvEhx4Uib5QyIdYVFOg.png" /><figcaption>Folder Structure</figcaption></figure><h3>Update the Policy</h3><p>Updating the policy is an essential step to ensure your device can execute jobs. You’re right on track with the intention to adhere to best practices by embracing the principle of least privilege — granting only the necessary permissions for the job to be done, no more, no less.</p><p>So, let’s enhance the initial policy to enable secure interactions with the job topics. To do this, you’ll need to modify the policy to include permissions that specifically allow your device to communicate with the AWS IoT job service.</p><p>By refining the policy with these adjustments, your device will be not only more secure but also ready to tackle the jobs you’ve set up for it. It’s like giving your device the exact key it needs to open the door to a new set of capabilities, making sure it’s the right fit and no more than necessary.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Connect&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:client/${iot:Connection.Thing.ThingName}&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Publish&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/start-next&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*/update&quot;<br>      ]<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Subscribe&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/start-next/accepted&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/start-next/rejected&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*/update/accepted&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*/update/rejected&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/notify-next&quot;<br>      ]<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Receive&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/start-next/accepted&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/start-next/rejected&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*/update/accepted&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*/update/rejected&quot;,<br>        &quot;arn:aws:iot:&lt;region&gt;:&lt;accountId&gt;:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/notify-next&quot;<br>      ]<br>    }<br>  ]<br>}</pre><p>Replace the &lt;region&gt; and the &lt;accountId&gt; for your values to make it work.</p><p>Now in the console go to Security &gt; Policy and select your Policy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6zVak9qVUXcn0g6FA-p-w.png" /><figcaption>Select your policy</figcaption></figure><p>Once in the policy in the top right corner press the <strong>Edit Active Version</strong> button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0-jCQWfqUgnXy43MUEuBg.png" /><figcaption>Edit Active Version</figcaption></figure><p>Replace the current policy with the new one by pressing the JSON button will allow you to copy and paste the policy I provided modified with your account and region</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KugVgfKF9_BBdKu98H42cQ.png" /></figure><h3>Create the Job</h3><p>Alright, now that you’re all set with the handler files and an updated policy, it’s time to put the spotlight on the job document. This document is the master plan that tells your device exactly what to do. It’s like a recipe that your IoT device will follow to the letter, ensuring every task is performed perfectly.</p><p>Let’s create this all-important document:</p><ol><li>Open your favorite text editor and get ready to define your job.</li><li>Start by creating a new file named job_document.json.</li><li>Save this file right at the heart of your project, the root directory, where it can be the star of the show.</li><li>With your job_document.json open, it&#39;s time to write the script for your IoT device. Here&#39;s a sample structure you can use:</li></ol><pre>{<br>  &quot;_comment&quot;: &quot;This sample JSON file can be used for installing wget packages on the device, then downloading specified file and cleanup by removing the installed package in the end.&quot;,<br>  &quot;version&quot;: &quot;1.0&quot;,<br>  &quot;steps&quot;: [<br>      {<br>        &quot;action&quot;: {<br>          &quot;name&quot;: &quot;Install-Packages&quot;,<br>          &quot;type&quot;: &quot;runHandler&quot;,<br>          &quot;input&quot;: {<br>            &quot;handler&quot;: &quot;install-packages.sh&quot;,<br>            &quot;args&quot;: [<br>                &quot;wget&quot;<br>            ],<br>            &quot;path&quot;: &quot;default&quot;<br>          },<br>          &quot;runAsUser&quot;: &quot;root&quot;<br>      }<br>      },<br>      {<br>        &quot;action&quot;: {<br>          &quot;name&quot;: &quot;Download-File&quot;,<br>          &quot;type&quot;: &quot;runHandler&quot;,<br>          &quot;input&quot;: {<br>            &quot;handler&quot;: &quot;download-file.sh&quot;,<br>            &quot;args&quot;: [<br>              &quot;https://github.com/awslabs/aws-iot-device-client/archive/refs/tags/v1.3.tar.gz&quot;,<br>              &quot;/tmp/Downloaded_File.tar.gz&quot;<br>            ],<br>            &quot;path&quot;: &quot;default&quot;<br>          },<br>          &quot;runAsUser&quot;: &quot;root&quot;<br>        }<br>      }<br>  ],<br>  &quot;finalStep&quot;: {<br>    &quot;action&quot;: {<br>      &quot;name&quot;: &quot;Remove-Packages&quot;,<br>      &quot;type&quot;: &quot;runHandler&quot;,<br>      &quot;input&quot;: {<br>        &quot;handler&quot;: &quot;remove-packages.sh&quot;,<br>        &quot;args&quot;: [<br>          &quot;wget&quot;<br>        ],<br>        &quot;path&quot;: &quot;default&quot;<br>      },<br>      &quot;runAsUser&quot;: &quot;root&quot;<br>    }<br>  } <br>}</pre><p>5. Once your job_document.json looks good, it&#39;s time to give it a home in the cloud. You&#39;ll want to upload it to an S3 bucket. To do this, replace &lt;S3bucketname&gt; with your actual bucket name and run the following command:</p><p>aws s3 cp job_document.json s3://&lt;S3bucketname&gt;/job_document.json</p><p>And there you go! With this command, your job_document.json takes its rightful place in the cloud, ready to be called upon when the job is created. Your IoT device is now one step closer to performing its tasks with the precision of a symphony conductor guiding the orchestra through a flawless performance.</p><h3>Run the IoT Client</h3><p>Awesome, you’re at the finish line! It’s time to power up the IoT Client and see it in action. You’ve got everything prepped and primed — the handler files are in place, the certificates are set, and the configurations are finely tuned. Now, let’s run the IoT Client with a Docker command that will mount all the necessary volumes, ensuring your client has access to all the resources it needs.</p><p>Here’s the command you’ll use to awaken the IoT Client:</p><pre>docker run -it -v ./certs:/certs -v ./config:/config -v ./job_handlers:/job_handlers public.ecr.aws/aws-iot-device-client/aws-iot-device-client:x86_64-ubuntu-latest --config-file config/config_template.json --enable-sdk-logging</pre><p>This command will:</p><ul><li>Start a Docker container interactively with the -it flag.</li><li>Mount your certs directory to the container&#39;s /certs.</li><li>Mount your config directory to the container&#39;s /config.</li><li>Mount your job_handlers directory to the container&#39;s /job_handlers.</li><li>Pull the AWS IoT Device Client image for Ubuntu and run it.</li><li>Use your config_template.json as the configuration file.</li><li>Enable SDK logging to help you keep an eye on the inner workings of the client.</li></ul><p>Once you hit Enter, the show begins! The IoT Client will come to life, and you should see an output indicating that the JobsFeature is enabled. Te output will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r9-Q-1l7dkOD5_cH4xgc_Q.png" /><figcaption>Expected Output running the IoT Client</figcaption></figure><h3>Execute the Job</h3><p>Fantastic! You’ve got your IoT Client humming along nicely, and it’s time to take the next exciting step: executing the job. To do this, you’ll venture into the AWS IoT console and create the job that will command your devices remotely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwcO5XdfhnvDBp429QzfJw.png" /><figcaption>Press Create Job button in the top right corner</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFcRPs8KtXcSZ2NGWTw0bQ.png" /><figcaption>Create a custom Job and click next</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jkMd1M11DJ7gSjrY4hF0Gw.png" /><figcaption>Assign a name and click next</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WQVEuDWN33PRt6Oo2Ng-JA.png" /><figcaption>Select your thing and in the second section select the file in the s3 bucket</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wh5tf4rErNr8_oLGdLMJ0g.png" /><figcaption>Select snapshot to run it just once</figcaption></figure><p>That’s right! As you click ‘Submit’, you’re giving the final go-ahead for the job to be executed. It’s a simple click for you, but it’s the start of an intricate process for your device</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FEjgaA48kuyRdalGwjRVVQ.png" /><figcaption>Install package step</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2p3Q42MO0AEyaZ-emsVPg.png" /><figcaption>Download-file step</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhI-TcWra62uYVYMuY6-Zg.png" /><figcaption>Remove package step</figcaption></figure><h3>In Summary</h3><p>Embarking on an IoT project journey can be as exciting as it is complex, and simulating a job execution using the AWS IoT Device Client is a pivotal step. This guide has walked you through the process, from setting up handlers and updating policies to creating and executing a job, equipping you with the knowledge to bring your IoT devices to life.</p><p>To recap, we’ve covered:</p><ol><li>Preparing and scripting handlers within the Device Client for specific tasks such as installing packages, downloading files, and cleaning up afterwards.</li><li>Updating the device policy to ensure secure and appropriate permissions for job execution.</li><li>Crafting the job document (job_document.json), a detailed script that orchestrates the actions your IoT device will perform.</li><li>Running the IoT Client with the necessary Docker commands to mount handlers, certificates, and configurations.</li><li>Creating and submitting the job in the AWS IoT console, leading to the execution of the predefined tasks on your IoT device.</li></ol><p>With each step, you’ve turned the complex into the achievable, setting the stage for your IoT device to perform with precision and reliability. Now, with a simple click on ‘Submit’, your job sets off through the AWS cloud, reaching your device and signaling it to begin its performance, just as a conductor cues an orchestra.</p><p>This hands-on simulation has not only demonstrated the power of the AWS IoT Device Client but has also given you the confidence to manage and deploy IoT jobs effectively. As your device executes each step, it’s a testament to the successful setup of your IoT environment, a symphony of technology working in concert, ready to tackle the tasks at hand.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d04bdf0187c7" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/step-by-step-guide-to-job-execution-with-aws-iot-device-client-d04bdf0187c7">Step-by-Step Guide to Job Execution with AWS IoT Device Client</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Easiest way to simulate a fully functional IoT device in AWS]]></title>
            <link>https://towardsaws.com/the-easiest-way-to-simulate-a-fully-functional-iot-device-in-aws-46fba600f8ac?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/46fba600f8ac</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[prototyping]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Fri, 12 Jan 2024 12:01:59 GMT</pubDate>
            <atom:updated>2024-01-12T12:01:59.153Z</atom:updated>
            <content:encoded><![CDATA[<p>Let me tell you a little secret about making things super easy: it’s all about embracing what’s already out there! Imagine someone has already done the hard work, crafted something amazing, and even better, they’ve written down every step of the way. That’s right, documentation is the magic word! When you find that, it’s like striking gold — you can simply pick it up, tailor it to your needs, and voilà, you’re on the fast track to success! And you know what? That’s exactly what we’re going to do. Let’s dive in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dvl4xS0bD1WDbWY1Rro5mA.png" /><figcaption>AI-generated Image from the article summary</figcaption></figure><p>Diving into the world of IoT, when you’re eager to whip up a Proof-of-Concept (PoC) for your latest project, you’ll find yourself at a crossroads with two key components to bring to life: the cloud and the device side. Now, let me tell you, the cloud is like the life of the party — it’s fun, it’s quick, and it’s a smooth ride. But when the spotlight turns to the device side, that’s when the real challenge begins.</p><p>You start asking the tough questions: “Which hardware should I use to test my cloud connection?” “Do I even have the hardware on hand?” Unlike the cloud, where one size fits all, each piece of hardware demands its own set of features to be implemented, which can really slow down your progress.</p><p>I’ve been down this road many times, but not too long ago, I stumbled upon a game-changer that turbocharged my development process. It’s a nifty solution from the folks at AWS, called<a href="https://github.com/awslabs/aws-iot-device-client"> aws-iot-device-client</a>. AWS describes it as…</p><blockquote>The AWS IoT Device Client is free, open-source, modular software written in C++ that you can compile and install on your Embedded Linux based IoT devices to access <a href="https://aws.amazon.com/iot-core/">AWS IoT Core</a>, <a href="https://aws.amazon.com/iot-device-management/">AWS IoT Device Management</a>, and <a href="https://aws.amazon.com/iot-device-defender">AWS IoT Device Defender</a> features by default. It serves as a reference implementation for your IoT devices to work with AWS IoT services, with operational best practices baked in — using it is the easiest way to create a proof-of-concept (PoC) for your IoT project. What’s more, since it is open-source, you can modify it to fit your business needs, or optimize it when you wish to scale up from a PoC to production.</blockquote><h3>The easiest way to use it</h3><p>Let me walk you through the simplest path to harnessing this awesome tool. There are two main approaches to using this project: one is to build it from scratch using cmake (let’s be honest, that’s the less-than-fun way), and the other is to use Docker. I’m all for taking the path of least resistance, so I wholeheartedly recommend going with Docker. Why? Because it lets you bypass the whole building ordeal.</p><p>To sweeten the deal, the team has already prepped Docker images for various architectures, <a href="https://gallery.ecr.aws/aws-iot-device-client/aws-iot-device-client">ready for you to use right out of the gate</a>. It’s like they’ve laid out a welcome mat for your project, inviting you to step in and get going with ease. So, let’s grab those images and get your PoC up and running smoothly!</p><h3>Let use it</h3><p>Alright, let’s put this into action! In our getting started guide, we’re going to do something really straightforward. We’ll pull the image straight from ECR — that’s Amazon’s Elastic Container Registry, in case you were wondering. Then, we’ll get down to the nitty-gritty of setting up the configuration file that’s required.</p><p>But that’s not all. We’ll also provide the necessary certificates and specify the endpoint. And depending on the feature you’re itching to test, there might be a few other configurations to tweak. It’s like setting up a new gadget; you just need to plug in the right pieces to bring it to life. So, let’s roll up our sleeves and make your IoT project come alive!</p><p>Pull the image</p><blockquote>docker pull public.ecr.aws/aws-iot-device-client/aws-iot-device-client:armv7-ubuntu-latest</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yad00lK1bPwWQfNbW-B7WQ.png" /><figcaption>Get the Image from ECR</figcaption></figure><p>Great, now that we’re ready to roll, let’s navigate to the root folder. Here, you’ll find the configuration file template. But to keep things super simple, we’re going to craft the most basic config template. Here’s how:</p><p>First, create a new file and name it config_template.json. Then, all you need to do is copy and paste the following content into it. This is going to be our starting point, a sort of blueprint, if you will. By doing this, we&#39;re laying the groundwork for your IoT device to connect seamlessly with the cloud. Ready? Let&#39;s get to it!</p><pre>{<br> &quot;endpoint&quot;: &quot;&lt;replace_with_endpoint_value&gt;&quot;,<br> &quot;cert&quot;: &quot;&lt;replace_with_certificate_file_path&gt;&quot;,<br> &quot;key&quot;: &quot;&lt;replace_with_private_key_file_path&gt;&quot;,<br> &quot;root-ca&quot;: &quot;&lt;replace_with_root_ca_file_path&gt;&quot;,<br> &quot;thing-name&quot;: &quot;&lt;replace_with_thing_name/replace_with_client_id&gt;&quot;,<br> &quot;logging&quot;: {<br>  &quot;level&quot;: &quot;DEBUG&quot;,<br>  &quot;type&quot;: &quot;STDOUT&quot;,<br>  &quot;file&quot;: &quot;/var/log/aws-iot-device-client/aws-iot-device-client.log&quot;<br> }<br>}</pre><p>To get your device chatting with AWS IoT Core, we need to pinpoint your unique IoT Core endpoint. It’s like finding the exact address for your device to send its data to the right place in the cloud.</p><p>To discover this endpoint, we’re going to use the AWS Command Line Interface (CLI), a handy tool that lets you talk to AWS services right from your terminal. Here’s the magic command you’ll run:</p><p>Just open up your terminal, type in this command, and hit enter. It’ll fetch the endpoint information and display it right there on your screen. With this piece of the puzzle, you’re one step closer to a fully connected IoT device. Let’s do this!</p><pre>aws iot describe-endpoint --endpoint-type iot:Data-ATS</pre><p>you will get something like this:</p><pre>{<br>    &quot;endpointAddress&quot;: &quot;f3mhgcvncgiyqj-ats.iot.us-east-1.amazonaws.com&quot;<br>}</pre><p>Alright, it’s time to update your configuration with the endpoint we just retrieved. Open up the config-template.json file you downloaded earlier and look for the &quot;endpoint&quot; key. Replace the placeholder with the endpoint value you got from the AWS CLI command. This is like setting the GPS for your device so it knows exactly where to send its data in the vast cloud sky.</p><p>Next up, we need to create a &quot;thing&quot; in the AWS IoT world. Think of a &quot;thing&quot; as a virtual representation of your physical device. It&#39;s pretty straightforward to set this up, and to make it even easier, we&#39;ll do it through the AWS Management Console. Here&#39;s how:</p><ol><li>Head over to the AWS Management Console and sign in.</li><li>Navigate to the AWS IoT Core service.</li><li>In the IoT Core dashboard, look for the “Manage” section and click on “Things.”</li><li>Now, you’ll see an option to “Create” a thing. Click on that and follow the prompts to define your new thing.</li></ol><p>By creating a thing, you’re essentially giving your device a name tag and a place in the AWS IoT ecosystem. Once that’s done, your device is no longer just a piece of hardware — it’s part of a larger, connected system, ready to interact with the cloud and other devices. Let’s get your thing set up!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYS683lsSWWkWREoYhqtZQ.png" /><figcaption>Create a thing in Iot Core &gt; Manage &gt; Things &gt; Create Thing</figcaption></figure><p>Create a single thing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pp_T_AFU9CaTfd9z1N-wsg.png" /><figcaption>Click Next</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xmu8vsWikJs6PT_dKvYmwg.png" /><figcaption>Name it and click next</figcaption></figure><p>Autogenerate a certificate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNdwIPIZT_8cFh7vgrdxeA.png" /><figcaption>Click Next</figcaption></figure><p>Create a policy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DEhD17koHn0cAApeUgggWg.png" /><figcaption>Click on the create policy in the top right corner button</figcaption></figure><p>Let’s create the following policy (This is a pretty open policy not recommended for production)</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Connect&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Publish&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Subscribe&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><p>You’ve got a basic policy in place now, which is like the rules of engagement for your device when it’s talking to AWS IoT Core. This policy is your device’s permission slip — right now, it’s got the green light to connect, publish, and subscribe to topics.</p><p>But here’s the thing: AWS IoT Core has a whole playground of features like jobs, provisioning, and device shadows that can really take your project to the next level. To let your device play with these cool tools, you’ll need to update your policy to grant it access.</p><p>For example, I named my policy “Test-policy.” It’s a good practice to give it a name that’s descriptive and makes sense to you (not like this name). When you’re ready to expand your device’s capabilities, just tweak the policy to include permissions for the additional features you want to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9viw87eOOrG2MF-SC11Lvg.png" /><figcaption>Click create thing</figcaption></figure><p></p><p>Alright, you’re about to cross a crucial bridge on your IoT journey. Once you’ve set up your policy, you’ll be greeted with a new window where you can download some important documents: the certificate, private key, public key, and the RootCA. Think of these as the secret codes and ID badges your device needs to communicate securely with AWS IoT Core.</p><p>Make sure to save these files in a secure place because they’re the keys to your IoT kingdom. You’ll need them shortly to complete your configuration file.</p><p>Here’s what you do next:</p><ol><li>Open the configuration file you’ve been working on.</li><li>Find the “cert” key and replace its value with the file path to your thing’s certificate.</li><li>Locate the “key” key and update its value with the file path to your private key.</li><li>Look for the “root-ca” key and input the file path to the RootCA file.</li><li>Lastly, find the “thing-name” key and replace its value with the name you gave your thing — in my case, it’s “test-thing.”</li></ol><p>Now, let’s get your folder organized to make it a breeze to provide these configuration files to the container. We’ll set up a folder structure that’s clean and logical, so when it’s time to get your container up and running, everything is right where it needs to be. Ready to sort and secure your files? Let’s do it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*8e04OdsnG8Q6KCsJ6BQ_6Q.png" /><figcaption>Folder. structure</figcaption></figure><p>Great, you’re almost there! Now that you’ve reorganized your files, it’s time to set the correct permissions to ensure everything runs smoothly when mounted as a volume in your Docker container. This is like giving your Docker container the right key to access the files it needs.</p><p>Here’s what you’ll do:</p><ol><li>Open your terminal or command prompt.</li><li>Change the permissions of the config directory and the config_template.json file within it:</li></ol><pre>chmod 745 config/<br>chmod 640 config/config_template.json</pre><p>3. Next, adjust the permissions for the certs directory and the private key file for your &quot;test-thing&quot;:</p><pre>chmod 745 certs/<br>chmod 600 certs/test-thing-private.pem.key</pre><p>These commands set the permissions so that the Docker container can properly read the configuration and certificate files without exposing them more than necessary.</p><p>Now, with the permissions set, you’re ready to launch your device client using Docker. Run the following command:</p><pre>docker run -it -v ./certs:/certs -v ./config:/config  public.ecr.aws/aws-iot-device-client/aws-iot-device-client:x86_64-ubuntu-latest --config-file config/config_template.json --enable-sdk-logging</pre><p>Great, you’re almost there! Now that you’ve reorganized your files, it’s time to set the correct permissions to ensure everything runs smoothly when mounted as a volume in your Docker container. This is like giving your Docker container the right key to access the files it needs.</p><p>Here’s what you’ll do:</p><ol><li>Open your terminal or command prompt.</li><li>Change the permissions of the config directory and the config_template.json file within it:</li></ol><pre>chmod 745 config/  <br>chmod 640 config/config_template.json</pre><p>3. Next, adjust the permissions for the certs directory and the private key file for your &quot;test-thing&quot;:</p><pre>chmod 745 certs/  <br>chmod 600 certs/test-thing-private.pem.key</pre><p>These commands set the permissions so that the Docker container can properly read the configuration and certificate files without exposing them more than necessary.</p><p>Now, with the permissions set, you’re ready to launch your device client using Docker. Run the following command:</p><pre>docker run -it -v $(pwd)/certs:/certs -v $(pwd)/config:/config public.ecr.aws/aws-iot-device-client/aws-iot-device-client:x86_64-ubuntu-latest --config-file /config/config_template.json --enable-sdk-logging</pre><p>Let’s break down what this command does:</p><ul><li>docker run -it: This tells Docker to run a container interactively, so you can see the output in your terminal.</li><li>-v $(pwd)/certs:/certs: This mounts your local certs directory to the /certs directory inside the container.</li><li>-v $(pwd)/config:/config: Similarly, this mounts your local config directory to the /config directory inside the container.</li><li>public.ecr.aws/aws-iot-device-client/aws-iot-device-client:x86_64-ubuntu-latest: This specifies the Docker image to use, which is the AWS IoT Device Client image for Ubuntu.</li><li>--config-file /config/config_template.json: This tells the AWS IoT Device Client inside the container where to find its configuration file.</li><li>--enable-sdk-logging: This option enables additional logging from the AWS SDK for troubleshooting and insight.</li></ul><p>After running this command, the AWS IoT Device Client will start up, and you should see output in your terminal indicating that it&#39;s running. It will be using the credentials and configuration you&#39;ve provided to connect to AWS IoT Core and perform its tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2RTTE-YkBT1YizpY9eXiIQ.png" /><figcaption>Output of the docker running the device client</figcaption></figure><p>Congratulations, you’re now piloting your IoT device through the cloud with Docker!</p><p>Guess what? Your device is now live and kicking, all set to dive into the exciting world of AWS IoT Core features, such as jobs and secure tunneling. And that’s exactly what we’ll explore in my upcoming article. Stay tuned as we embark on this next adventure together!</p><p>In conclusion, we’ve taken a journey through setting up and securing an IoT device with AWS IoT Core. We started by updating our configuration file with the necessary endpoint information and created a “thing” in the AWS IoT ecosystem to represent our physical device. We then established a basic policy to grant our device the permissions to connect, publish, and subscribe to topics.</p><p>Recognizing the potential of AWS IoT Core’s advanced features, we discussed the importance of updating our policy to access jobs, provisioning, and device shadows. We downloaded the essential certificates and keys, ensuring they were saved securely, as they are the credentials that authenticate our device with AWS IoT Core.</p><p>We meticulously organized our files into a clear folder structure and set precise permissions to meet the requirements for mounting them as volumes in a Docker container. This step is crucial for maintaining security and functionality when our device interacts with the Docker environment.</p><p>Finally, we executed a Docker command to run the AWS IoT Device Client, linking our configuration and certificate files to the container. This allowed our device to communicate with AWS IoT Core, ready to harness the full power of the cloud for our IoT applications.</p><p>By following these steps, we’ve set a strong foundation for our IoT device’s cloud interactions, ensuring it’s well-equipped to handle secure communication and take advantage of the powerful services offered by AWS IoT Core. Whether you’re a hobbyist or a professional, this guide has prepared you to embark on a successful IoT adventure with confidence and technical savvy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46fba600f8ac" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/the-easiest-way-to-simulate-a-fully-functional-iot-device-in-aws-46fba600f8ac">The Easiest way to simulate a fully functional IoT device in AWS</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Greengrass 101: Installing the Greengrass Core]]></title>
            <link>https://towardsaws.com/aws-greengrass-101-installing-the-greengrass-core-29a8e1d79982?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/29a8e1d79982</guid>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[greengrass]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 02:35:21 GMT</pubDate>
            <atom:updated>2023-04-11T02:35:21.861Z</atom:updated>
            <content:encoded><![CDATA[<p>Unleash the Power of IoT: A Step-by-Step Guide to Installing AWS Greengrass Core on Your Devices</p><h3><strong>Introduction to AWS Greengrass</strong></h3><p>AWS Greengrass Core is a piece of software that extends AWS cloud capabilities to local devices, allowing them to act locally on the data they generate while still using the cloud for management, analytics, and durable storage. It enables devices to run AWS Lambda functions, Docker containers and perform local computing, messaging, and data caching.</p><p>This tutorial will guide you through installing Greengrass on a Linux device. By the end of this tutorial, you will better understand how to install AWS Greengrass in an Ubuntu OS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*BfvGWlL6ddFgL_eTuEn3Bg.png" /></figure><h3>Greengrass Requirements</h3><p>Before beginning, a few requirements must be met to use AWS Greengrass. You will need a Linux device that meets the following requirements:</p><p>- A 64-bit ARM or x86 processor<br>- At least 96 MB of RAM (Only for the Greengrass Core software)<br>- At least 256 MB of storage (Only for the Greengrass Core software)<br>- A network connection</p><h3>Create a Provision role for Greengrass devices.</h3><p>In this section, we will create a provisioning role for Greengrass devices. A provision role is an AWS Identity and Access Management (IAM) role that grants AWS Greengrass permission to access AWS resources on behalf of the device.</p><p>First, let’s create two files, one for the role creation and one for the policies:</p><blockquote>assume-policy.json</blockquote><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::&lt;ACCOUNT_ID&gt;:user/&lt;USER_ID&gt;&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>        }<br>    ]<br>}</pre><p>Replace your USER_ID and ACCOUNT_ID with your values; this policy will allow only your user to get credentials from the new role. To create the role run the following command:</p><pre>aws iam create-role - role-name provision-greengrass-role - assume-role-policy-document file://assume-policy.json</pre><p>This command creates a new IAM role named provision-greengrass-role. The --role-name option specifies the name of the role to be created. <br>The --assume-role-policy-documentoption specifies the JSON policy document granting AWS Greengrass permission to assume the role. The policy document is stored in a file named assume-policy.json</p><p>After the role creation, you need to attach the minimal IAM policy for the installer to provision; let’s start by creating the policy in a file with the following content:</p><blockquote>FILE NAME: greengrass-core-policy.json</blockquote><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;CreateTokenExchangeRole&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iam:AttachRolePolicy&quot;,<br>                &quot;iam:CreatePolicy&quot;,<br>                &quot;iam:CreateRole&quot;,<br>                &quot;iam:GetPolicy&quot;,<br>                &quot;iam:GetRole&quot;,<br>                &quot;iam:PassRole&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:iam::&lt;ACCONUT_ID&gt;:role/GreengrassV2TokenExchangeRole&quot;,<br>                &quot;arn:aws:iam::&lt;ACCOUNT_ID&gt;:policy/GreengrassV2TokenExchangeRoleAccess&quot;<br>            ]<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;CreateIoTResources&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iot:AddThingToThingGroup&quot;,<br>                &quot;iot:AttachPolicy&quot;,<br>                &quot;iot:AttachThingPrincipal&quot;,<br>                &quot;iot:CreateKeysAndCertificate&quot;,<br>                &quot;iot:CreatePolicy&quot;,<br>                &quot;iot:CreateRoleAlias&quot;,<br>                &quot;iot:CreateThing&quot;,<br>                &quot;iot:CreateThingGroup&quot;,<br>                &quot;iot:DescribeEndpoint&quot;,<br>                &quot;iot:DescribeRoleAlias&quot;,<br>                &quot;iot:DescribeThingGroup&quot;,<br>                &quot;iot:GetPolicy&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;DeployDevTools&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;greengrass:CreateDeployment&quot;,<br>                &quot;iot:CancelJob&quot;,<br>                &quot;iot:CreateJob&quot;,<br>                &quot;iot:DeleteThingShadow&quot;,<br>                &quot;iot:DescribeJob&quot;,<br>                &quot;iot:DescribeThing&quot;,<br>                &quot;iot:DescribeThingGroup&quot;,<br>                &quot;iot:GetThingShadow&quot;,<br>                &quot;iot:UpdateJob&quot;,<br>                &quot;iot:UpdateThingShadow&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        }<br>    ]<br>}</pre><p>Now let’s attach the policy to the provision-greengrass-role by issuing:</p><pre>aws iam put-role-policy - role-name provision-greengrass-role - policy-name greengrass-provision-policy - policy-document file://greengrass-core-policy.json</pre><p>As seen in the code block above, the aws iam put-role-policy command is used to attach a policy to an IAM role. In this case, the `put-role-policy` command is used to attach the greengrass-provision-policy policy to the provision-greengrass-role IAM role. The--policy-document flag specifies the JSON file that contains the policy document.</p><p>After all this process, we are ready to retrieve credentials from this role using:</p><pre>aws sts assume-role \<br> -role-arn arn:aws:iam::&lt;ACCOUNT_ID&gt;:role/provision-greengrass-role \<br> -role-session-name ProvisionSession \<br> -output json</pre><p>This code segment illustrates how to assume an IAM role using the aws sts assume-role command. The -- role-arn flag specifies the Amazon Resource Name (ARN) of the IAM role to assume, while the --role-session-name flag specifies a name for the session. The --output flag specifies the output format, which is JSON in this case.</p><p>Getting back the following:</p><pre>{<br>    &quot;Credentials&quot;: {<br>        &quot;AccessKeyId&quot;: &quot;&lt;ACCESS_KEY&gt;&quot;,<br>        &quot;SecretAccessKey&quot;: &quot;&lt;SECRET_ACCESS_KEY&gt;&quot;,<br>        &quot;SessionToken&quot;: &quot;&lt;SESSION_TOKEN&gt;&quot;,<br>        &quot;Expiration&quot;: &quot;2023-04-08T15:35:42+00:00&quot;<br>    },<br>    &quot;AssumedRoleUser&quot;: {<br>        &quot;AssumedRoleId&quot;: &quot;AROAX7U2EUGE4JXTH5V2S:ProvisionSession&quot;,<br>        &quot;Arn&quot;: &quot;arn:aws:sts::&lt;ACCOUNT_ID&gt;:assumed-role/provision-greengrass-role/ProvisionSession&quot;<br>    }<br>}</pre><p>This output demonstrates the credentials that were assumed by the IAM role. The AccessKeyId, SecretAccessKey, and SessionToken are temporary security credentials that can be used to access AWS resources. The Expiration field indicates when the credentials will expire. The AssumedRoleUser field shows the ARN of the assumed role and the session name.</p><p>To provide the credentials to the device, log into the device and provide the credentials as environmental variables by typing:</p><pre>export AWS_ACCESS_KEY_ID=&lt;ACCESS_KEY&gt;<br>export AWS_SECRET_ACCESS_KEY=&lt;SECRET_KEY&gt;<br>export AWS_SESSION_TOKEN=&lt;SESSION_TOKEN&gt;<br>export AWS_DEFAULT_REGION=us-east-1</pre><p>Replace the region if you want a different one.</p><p>Now you are ready to install Greengrass Core.</p><h3>Installing Greengrass Core</h3><p>This installation process applies to Ubuntu OS.</p><pre># Install Java <br>sudo apt update<br>sudo apt install default-jdk<br><br># Validate Java installation<br>java --version</pre><p>Let’s take a closer look at what’s happening here. The code block installs Java using the apt package manager on a Linux device. The sudo command is used to run the installation with administrative privileges. After installation, the java --version command is used to verify that Java has been installed correctly. This command will output the version of Java that has been installed, along with information about the runtime environment and the server virtual machine. This step is necessary because AWS Greengrass requires Java to be installed on the device.</p><pre>openjdk version &quot;11.0.9.1&quot; 2020–11–04<br>OpenJDK Runtime Environment (build 11.0.9.1+1-post-Debian-1deb10u2)<br>OpenJDK 64-Bit Server VM (build 11.0.9.1+1-post-Debian-1deb10u2, mixed mode)</pre><p>The output above provides an example of what the java --version command returns when Java is installed on a Linux device. The output shows the version of OpenJDK that has been installed, along with information about the runtime environment and the server virtual machine. This information is useful for verifying that Java has been installed correctly and troubleshooting any issues.</p><pre>sudo useradd - system - create-home ggc_user<br>sudo groupadd - system ggc_group</pre><p>Here, we can see that the code creates a group and a user on the Linux device. The useradd command is used to create a system user named ggc_user with a home directory. The groupadd command is used to create a system group named ggc_group. These commands are necessary for creating a user and group that will be used to run the AWS Greengrass daemon. By creating a separate user and group for Greengrass, we can ensure that the daemon runs with the appropriate permissions and does not have access to other system resources.</p><pre>sudo apt install unzip<br>cd ~<br>curl -s https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-nucleus-latest.zip &gt; greengrass-nucleus-latest.zip<br>unzip greengrass-nucleus-latest.zip -d GreengrassInstaller &amp;&amp; rm greengrass-nucleus-latest.zip<br>sudo -E java -Droot=&quot;/greengrass/v2&quot; -Dlog.store=FILE -jar ./GreengrassInstaller/lib/Greengrass.jar - aws-region us-east-1 \<br> - thing-name GreengrassQuickStartCore-test \<br> - thing-group-name GreengrassQuickStartGroup \<br> - component-default-user ggc_user:ggc_group \<br> - provision true \<br> - setup-system-service true \<br> - deploy-dev-tools true</pre><p>As demonstrated in the code block above, the AWS IoT Greengrass Core software is installed on the Linux device. The `curl` command is used to download the latest version of the Greengrass Core software from the AWS website. The unzip command is used to extract the downloaded file to a directory named GreengrassInstaller. The sudo command is used to run the Greengrass installer with administrative privileges. The installer is configured with various options, such as the AWS region, the name of the Greengrass Core device, and the default user and group for components. These options are necessary for configuring the Greengrass Core software to run on the device.</p><h3>Deploy the Greengrass CLI component</h3><p>Once the provisioning is done, the deployment process using the Command Line Interface (CLI) might take a little while — around 1 to 2 minutes. To check if everything went well, you can run a command on your own computer. Just keep in mind that you won’t be able to do this check from the device itself, since you might not have the AWS CLI installed there. Plus, the role that the device took on with the credentials won’t allow it to list the deployments.</p><pre>aws greengrassv2 list-effective-deployments - core-device-thing-name GreengrassQuickStartCore-test</pre><p>This code segment demonstrates how to validate that the AWS Greengrass CLI is installed on the Linux device. The aws greengrassv2 list-effective-deployments command is used to list the effective deployments for the Greengrass Core device named GreengrassQuickStartCore-test. This command requires the AWS CLI to be installed and configured on the device. If the command executes successfully and returns a list of deployments, then the Greengrass CLI is installed and configured correctly.</p><p>Another way to test if the CLI is installed is to run the following command to try list the components in the device from the CLI:</p><pre>sudo /greengrass/v2/bin/greengrass-cli component list</pre><p>And you will see the list of components running on the device.</p><p><strong>In case the CLI component is not installed: </strong><br>From your local computer, run the following command:</p><pre>aws greengrassv2 create-deployment \<br>  --target-arn &quot;arn:aws:iot:us-east-1:&lt;ACCOUNT_ID&gt;:thing/GreengrassQuickStartCore-test&quot; \<br>  --components &#39;{<br>    &quot;aws.greengrass.Cli&quot;: {<br>      &quot;componentVersion&quot;: &quot;2.9.4&quot;<br>    }<br>  }&#39;</pre><p>This command will create a deployment to deploy the AWS-provided Greengrass CLI component and respond the deploymentId</p><pre>{<br> &quot;deploymentId&quot;: &quot;50e4b5c6–8d15–4561–99c1-dea209462f6d&quot;<br>}</pre><p>The output above provides an example of a successful deployment of the Greengrass CLI component. The deploymentId field contains a unique identifier for the deployment, which can be used to track and manage the component.</p><h3>Using the Greengrass CLI</h3><p>With the default configuration, the CLI component is located at /greengrass/v2/bin/greengrass-cli to get the help information and validate that the CLI is working, you can issue the following command:</p><pre>sudo /greengrass/v2/bin/greengrass-cli -help</pre><h3>Reviewing the logs</h3><p>To view the logs on the device, you can use the following command:</p><pre>sudo cat /greengrass/v2/logs/greengrass.log</pre><h3>Conclusion</h3><p>Awesome! This tutorial showed us how to install AWS Greengrass on a Linux device. We did this by setting up a special role just for Greengrass devices and giving the installer the necessary permissions to do its thing. By following along with the easy-to-follow steps in this tutorial, we now know how to install AWS Greengrass on an Ubuntu OS and all the cool stuff that comes with it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29a8e1d79982" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/aws-greengrass-101-installing-the-greengrass-core-29a8e1d79982">AWS Greengrass 101: Installing the Greengrass Core</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting the dots AI, IoT, Cloud, and Web Dev]]></title>
            <link>https://medium.com/data-science/connecting-the-dots-ai-iot-cloud-and-web-dev-848447e1ca66?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/848447e1ca66</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[movenet]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Fri, 24 Sep 2021 12:23:07 GMT</pubDate>
            <atom:updated>2021-09-24T12:23:07.562Z</atom:updated>
            <content:encoded><![CDATA[<h4>Small journey for an End-to-End solution development using trending technologies</h4><h3>End goal and steps:</h3><p>The idea behind this project is to determine the performance of my work from home and get insides on how to improve my workstation setup using Computer Vision on edge with an IoT Device, AWS Cloud, and a simple Web app.</p><p>Additionally, I would like to share the setbacks found during the developments and the walk-around I took to solve them.</p><p>So, based on the requirement, my first idea was something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*3-dvnY3w1_ahWDX4i-snmQ.png" /><figcaption>The camera above my work-station, to determine the face position, I<em>mage by author</em></figcaption></figure><p>Once the initial setup was defined, I started determining the minimum required tools to get the data, in this case, the camera; since in the <a href="https://rafael-a-rodriguez-m.medium.com/train-and-deploy-an-alpr-for-colombian-license-plate-with-tiny-yolov4-and-jetson-nano-without-5da6f975ea14"><strong>LPR Recognition Article</strong></a> I used the <a href="https://www.amazon.com/-/es/gp/product/B077889YRN/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;psc=1">SV3C</a> low-cost camera, I decided to use the same one because the integration is already done using HTTP.</p><p>These are the initial images:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*s24jPIJ8exCuHiv0vhey7g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*Y-0Pk-NI0ZLRTjbKGZhzJQ.jpeg" /><figcaption>Right, Center, I<em>mage by author</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*mu2SHaKL8uYcpyIyKHS9uw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*9idhuokahnYUb2WQV82hqQ.jpeg" /><figcaption>Empty, left, I<em>mage by author</em></figcaption></figure><p>I used two scripts to get those images, one in Python and one in Bash (Note: all the information regarding this project is available in the following <a href="https://github.com/RrodriguezM/Face-position-app">Github</a> repo). The first one is to create the folder structure named <a href="https://github.com/RrodriguezM/Face-position-app/blob/main/create-folder-structure.sh">create-folder-structure.sh</a>, and the second one is used to collect the data named <a href="https://github.com/RrodriguezM/Face-position-app/blob/main/collect_images.py">collect_images.py</a>.</p><h3>Getting the Input Data:</h3><p>At this point, I had the setup and 200 images of each position, and I started to think about the way I would use these images, so I ended up using transfer learning with <a href="https://www.tensorflow.org/api_docs/python/tf/keras/applications/efficientnet/EfficientNetB0">EfficientNetB0</a> as a feature extractor and training just the last layer. Here is the <a href="https://colab.research.google.com/drive/1bjI2YLTwkMcrwIjK6Fo92C-IKzKHJSAJ?usp=sharing">Colab Link</a></p><p>And just after a few epochs, I was able to achieve more than 80% of accuracy. Nevertheless, I found some setbacks in real-time testing because my idea was to train based on my head position. However, the network actually learned my shoulders and arms positions, so I had a few more options such as getting more data, getting different images, data augmentation, and more complex networks. Still, I wanted to keep it simple, so I researched a little more and found a new approach.</p><p>Based on my initial thought, I wanted to track my face, and after some research, I found a neural network named <a href="https://blog.tensorflow.org/2021/05/next-generation-pose-detection-with-movenet-and-tensorflowjs.html">MoveNet</a> released by Google in 2021which is able to detect 17 keypoints in the body (<em>nose, left eye, right eye, left ear, right ear, left shoulder, right shoulder, left elbow, right elbow, left wrist, right wrist, left hip, right hip, left knee, right knee, left ankle, right ankle)</em> and with the first five keypoint I had some information about my face, or any face, so I decided to try this new option.</p><p>Additionally, I changed the camera position. This is the difference between doing a real project rather than testing and learning with datasets. With real projects, you can change the input data and validate if the new data provides you more information than the previous, and I can do this because this is an end-to-end project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*nqDyiAAWrBqpOh72pt9Q1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ETHEgkvM_YhI-gUSYt7zUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*68_EADQY3iQLy_WU9PWGRA.png" /><figcaption>Face-keypoints, I<em>mage by author</em></figcaption></figure><p>With this information, the approach now is to detect these 5 keypoints and select an ML classifier to determine the position of the head.</p><h3>Selecting the classifier:</h3><p>As part of the trending technologies for beginners in ML, there are a couple of <strong>AutoML</strong> solutions (<a href="https://github.com/microsoft/FLAML">FLAML</a> and <a href="https://github.com/mljar/mljar-supervised">MLJAR</a>), so I decided to test FLAML and get an initial direction on which classifier to use</p><p>and just with a few lines of code:</p><pre>from flaml import AutoML<br>automl = AutoML()<br>automl.fit(X_train, y_train, task=”classification”, time_budget=120)</pre><p>I got an 84% in the validation set</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czPC8aWutQizDaNsPnG4ng.png" /><figcaption>Best ML solution*, I<em>mage by author</em></figcaption></figure><p>But 93% in the test set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*LWwJFh1HwvW2V2io3UmKMQ.png" /><figcaption>I<em>mage by author</em></figcaption></figure><p>Here is the <a href="https://colab.research.google.com/drive/1RD-a-c9Gs0oDoA39rkQAnCvvkxVB3qGo?usp=sharing">Colab</a> for MoveNet future extraction and the AutoML classifier.</p><h3>Integration with AWS IoT:</h3><p>Once I have the setup to get images, get the keypoints with MoveNet and classify the image using FLAML, I want to send the information to AWS. An interesting service to use is the IoT Core of AWS, so this is the basic architecture I will end up with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*ljybG4Hkn4vGJn_eeUpT9w.png" /><figcaption>Architecture, I<em>mage by author</em></figcaption></figure><h3>Basic Architecture description:</h3><p>The SV3C camera is OVNIF compliant. OVNIF has some standard ways to get snapshots of images using the HTTP protocol, allowing you to get images whenever you want, without having to deal with video streams. You can see the request in <a href="https://github.com/RrodriguezM/Face-position-app/blob/main/GetImagesCameraSv3c/getImage.py">Github</a>.</p><p>For communication between the end device and AWS IoT Core I used MQTT, a communication protocol that helps me to communicate and act over a remote device so easily, allowing me to add any intelligent switch in the future to turn off the light once I leave the office.</p><p>This part was based on the following AWS <a href="https://aws.amazon.com/premiumsupport/knowledge-center/iot-core-publish-mqtt-messages-python/">blog</a> to use the Python <strong>awsiotsdk</strong></p><p>Regard the AWS Services I&#39;m using, both are serverless and can scale to billions of devices, and I&#39;m only paying for what I use (Pay as you go). For the DynamoDB, the integration was based on the following <a href="https://docs.aws.amazon.com/iot/latest/developerguide/iot-ddb-rule.html">doc</a>. I’m also uploading the images to an S3 bucket and storing them in a folder named as the predictions that will help me to validate how the model is behaving.</p><p>Then we have Streamlit, which I&#39;m using locally now just to get an overview.</p><h3>Running it in the JetsonNano:</h3><p>The real challenge started once I decided to move my model to the Jetson Nano after having it ready and working on my computer. The main reason was that the Jetson was running out of memory and the AutoML library (Flaml) had some problems to be installed.</p><p>After some more research, I found the MoveNet Model using <strong>Tflite</strong> which solved the memory problem, but I still had the problem of the Flaml library. However, the solution was mentioned in this blog; I proposed the AutoML to get an initial direction, and based on the output obtained from the Flaml Library I found the specific Library for the model that AutoML proposed, in this case, <a href="https://lightgbm.readthedocs.io/en/latest/index.html">LGBM</a> as shown in the (Best ML solution*) image.</p><p>See Tflite implementation in realtimepredictionmovenetflaml.py and the initial test in this <a href="https://colab.research.google.com/drive/1JA-fomqWhzD570D4QlmX623bzc6Fk7kR?usp=sharing">Colab</a></p><p>See the LGBM training in this <a href="https://colab.research.google.com/drive/1RD-a-c9Gs0oDoA39rkQAnCvvkxVB3qGo#scrollTo=--pI-RmRrNEI">Colab</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQRUW1MLWhU90OG6o_1i2A.png" /><figcaption>I<em>mage by author</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*AzjTC6_D-ei2ErzX5eI-WQ.png" /><figcaption>Jetson Messages, I<em>mage by author</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VO5AzezCeC4GjDdiQL49Eg.png" /><figcaption>AWS IoT Console Logging the Messages</figcaption></figure><h3>Scripts to run the project:</h3><ul><li>To do the real-time inference and send the data to AWS:</li></ul><p>python realtimepredictionmovenetflaml.py</p><ul><li>To run locally the Streamlit server:</li></ul><p>streamlit run app.py</p><ul><li>To collect images from the camera:</li></ul><p>python collect_images.py</p><ul><li>To train the NN, go to the <a href="https://colab.research.google.com/drive/1RD-a-c9Gs0oDoA39rkQAnCvvkxVB3qGo?usp=sharing">COLAB</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*fUm-DN6ZVsMW6k6lTv5VmQ.png" /><figcaption>Web page prototype, I<em>mage by author</em></figcaption></figure><h3>Improvements and Comments from Prototype to Product:</h3><p>There are a lot of points to be improved in this project, such as:</p><ul><li>Change from Streamlit to a SPA could be something similar to React.js</li><li>Train with more images to improve accuracy</li><li>Add data augmentation</li><li>Add infrastructure as a code to configure all AWS services</li><li>Get more metrics</li><li>Add visibility (Logs)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=848447e1ca66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/connecting-the-dots-ai-iot-cloud-and-web-dev-848447e1ca66">Connecting the dots AI, IoT, Cloud, and Web Dev</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Least Privileges in AWS Roles Made Easy]]></title>
            <link>https://towardsaws.com/least-privileges-in-aws-roles-made-easy-18b21a35a314?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/18b21a35a314</guid>
            <category><![CDATA[well-architected]]></category>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[aws-role]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Tue, 03 Aug 2021 16:26:11 GMT</pubDate>
            <atom:updated>2021-08-03T16:26:11.593Z</atom:updated>
            <content:encoded><![CDATA[<h4>Easier than ever</h4><h4>The easiest way to generate fine-grained policies in AWS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*uqrRX4f0oQb6_ds1INpTrw.jpeg" /></figure><p>Whenever you are trying to develop and deploy a service in AWS is a good practice to grant the least privilege to your application&#39;s roles to comply with the company&#39;s security requirements. Although, sometimes, this is not easy at all.</p><p>To deal with this problem, AWS came up with a solution based on CloudTrail and AccessAnalizer.</p><p>But what are CloudTrail and AccessAnalizer?</p><h3>CloudTrail</h3><p>AWS CloudTrail is an AWS service that helps you enable governance, compliance, operational, and risk auditing in AWS accounts. Actions taken by a user, role, or an AWS service are recorded as events in CloudTrail. Events include actions taken in the AWS Management Console, AWS Command Line Interface, and AWS SDKs and APIs.</p><h3>IAM Access Analyzer</h3><p>AWS IAM Access Analyzer helps to identify the resources in organizations and accounts, such as Amazon S3 buckets or IAM roles, shared with an external entity. This allows to identify unintended access to your resources and data, which is a security risk. Access Analyzer identifies resources shared with external principals using logic-based reasoning to analyze the resource-based policies in your AWS environment.</p><p>Imagine you are deploying a basic API gateway with a lambda function, which gets a parameter from SSM and returns the name of a bucket. However, you are struggling to follow the best practices and grant the least privilege to the role you are using.</p><p><strong>Solution:</strong></p><p>With the new IAM Access Analyzer Tool, you can follow a simple approach, develop your solution without considering permissions, initially granting admin access, and then running the tool to get the actions used for the role you are using.</p><p><strong>Requirements:</strong></p><p>Install SAM as explained by AWS: <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html">https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html</a></p><p>Create a Trail as explained in <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html">https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html</a> using <strong>Creating a trail in the console (basic event selectors)</strong></p><p>The following section will explain all required steps to grant the least privilege to a role:</p><p>To implement this, we have a Github repo you can clone with the following link <a href="https://github.com/RrodriguezM/least-privilege-role">https://github.com/RrodriguezM/least-privilege-role</a>.</p><p>When reviewing this repo, there is a <strong><em>template.yaml </em></strong>file containing the infrastructure to deploy, but more interesting is the lambda policy (lines 26–31), allowing access to all actions and all resources:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*JtLwY8-DgiAYJPHJWP3bFw.png" /><figcaption>Administrator policy</figcaption></figure><p>Provide your AWS credentials and run the following command in the project <strong>root</strong> folder:</p><pre><em>./deploy.sh</em></pre><p>This command runs a Bash script to deploy the infrastructure required through SAM (Serverless Application Model) and IaaC (Infrastructure as a Code)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*OdOvdyOibIfigwSr86uEeg.png" /><figcaption>Deployed Architecture</figcaption></figure><p>In the script’s output, you will see some information to test your API. It will be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*9NJblAsb6p3JE8-8vjjz8w.png" /></figure><p>As you can see, there is a URL to use in the browser, which will look something like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*EuXLIRYh3lD_SXHXZxZtsg.png" /><figcaption>API response</figcaption></figure><p><strong><em>Note: Try to use this endpoint repeatedly to create trail logs</em></strong></p><p>Up to this point, we have an infrastructure deployed and working, but we haven’t solved our main issue: to grant the least privilege to the lambda role allowing only access to get the SSM parameter.</p><p>In order to solve this, we will use the IAM Access Analyzer,</p><p>Go to IAM, then go to Roles and filter using ListObjectFunction</p><p>Click the role name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A9zy05gZ2SpY1kU7Fh43Zg.png" /></figure><p>In the option, select Generate Policy based on CloudTrail events and <strong><em>Generate Policy:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zz6ImEN7l1ab4zfpV0pPDg.png" /></figure><p>You will be prompt to a new window, fill in the information, and select a new service role:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*hEVlao3DPy-Oqb5l9nnWyw.png" /></figure><p>This could take some minutes to be generated, and then you will see something like this at the bottom of the screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*1Vj7dxw-hNMXHB0pcqAbVw.png" /><figcaption>Policy Successfully generated</figcaption></figure><p>Click on View Generated Policyto see a preview of the generated policy, then click next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*UYbzajpAKQLhzxfWaaLZXg.png" /></figure><p>And here we have our new policy based on the access recorded by the cloud trail service allowing us to comply with the least privilege principle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*4WYyrrR2rzNroDv-XiRQGQ.png" /></figure><p>You can now modify the <strong><em>template.yaml</em></strong> to include only the required permissions leaving something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*YJZytfV316y4YIXf3uaWhA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18b21a35a314" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/least-privileges-in-aws-roles-made-easy-18b21a35a314">Least Privileges in AWS Roles Made Easy</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Train and Deploy an ALPR for Colombian License Plate with Tiny-YoloV4 and Jetson Nano without…]]></title>
            <link>https://rafael-a-rodriguez-m.medium.com/train-and-deploy-an-alpr-for-colombian-license-plate-with-tiny-yolov4-and-jetson-nano-without-5da6f975ea14?source=rss-d9fd5861fc90------2</link>
            <guid isPermaLink="false">https://medium.com/p/5da6f975ea14</guid>
            <category><![CDATA[license-plate-recognition]]></category>
            <category><![CDATA[yolov4]]></category>
            <category><![CDATA[deploy]]></category>
            <category><![CDATA[jetson-nano]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Rafael Rodriguez]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 09:42:52 GMT</pubDate>
            <atom:updated>2020-10-26T01:13:25.566Z</atom:updated>
            <content:encoded><![CDATA[<h3>Train and Deploy an ALPR for Colombian License Plate with Tiny-YoloV4 and Jetson Nano without Internet</h3><p>There is a wide range of tutorial and medium articles talking about training YoloV4 for custom object detection, but what about deploying? not only deploy to consume from a web service in any cloud provider as AWS or AZURE why not to do it locally? that what we will do here.</p><p>For small parking, the empty places and the number of free spaces are hard to get automatically, so we can detect if there is a car in a certain place and count it, also we can count it at the entry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uY1vOafHzLZFGNXbSyFj4g.jpeg" /><figcaption>Final Result get the car and Plate Position</figcaption></figure><h3>Steps :</h3><blockquote>1. The Architecture of the Network</blockquote><blockquote>2. Components</blockquote><blockquote>3. Labeling License Plates, Cars, and Motorcycles</blockquote><blockquote>4. Installing Darknet in Jetson Nano</blockquote><blockquote>5. Running Basic Test</blockquote><h3>1. ARCHITECTURE OF THE NETWORK</h3><p>To deploy this solution, we should put cameras in places close to car circulation. The location could be in the entry, exit, and principal route of the parking lot to get most or all the License Plates and count the number of vehicles in certain parking places.</p><p>Cameras installation in different places forces us to make significant investments in data connection and energy. An alternative to avoid this is to use wifi cameras and reuse some of the electrical power installations available in the parking lot.</p><p>The following is the architecture proposed for the network :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*NQvkphYiaSOkJlw1zFve0w.png" /></figure><p>COMPONENTS</p><p>The list of parts needed to deploy is the first step because it takes time to arrive, and you can do other actions while the articles come:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*qTtZ06Zo_LezRhVSafcTfA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*DvJZIh8ZS93vbw8i_UTYAA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MhgcHy2SfjaKtZ1Z1IbMjg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*GYxAfPNlj3tu6ZG3PKJjzg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRLDuDSNRqbAwpHP4qa-sg.jpeg" /><figcaption>Basics Components to Assembly the network</figcaption></figure><p><a href="https://www.amazon.com/-/es/dp/B07PZHBDKT/ref=twister_B085QSXLCJ?_encoding=UTF8&amp;psc=1">https://www.amazon.com/-/es/dp/B07PZHBDKT/ref=twister_B085QSXLCJ?_encoding=UTF8&amp;psc=1</a></p><p><a href="https://www.amazon.com/Waveshare-Power-Supply-Applicable-Jetson/dp/B07X8P1LFD">https://www.amazon.com/Waveshare-Power-Supply-Applicable-Jetson/dp/B07X8P1LFD</a></p><p><a href="https://www.amazon.com/-/es/gp/product/B077889YRN/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;psc=1">https://www.amazon.com/-/es/gp/product/B077889YRN/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;psc=1</a></p><p><a href="https://www.amazon.com/-/es/TP-Link-wireless-network-Adapter-SoftAP/dp/B008IFXQFU/ref=sr_1_6?__mk_es_US=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;crid=5XLIVBRIB9I3&amp;dchild=1&amp;keywords=wifi+dongle&amp;qid=1599645104&amp;sprefix=wifi+dongfl%2Caps%2C257&amp;sr=8-6">https://www.amazon.com/-/es/TP-Link-wireless-network-Adapter-SoftAP/dp/B008IFXQFU/ref=sr_1_6?__mk_es_US=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;crid=5XLIVBRIB9I3&amp;dchild=1&amp;keywords=wifi+dongle&amp;qid=1599645104&amp;sprefix=wifi+dongfl%2Caps%2C257&amp;sr=8-6</a></p><p><a href="https://www.amazon.com/-/es/TP-Link-N450-Wi-Fi-Router-TL-WR940N/dp/B003Y5RYNY/ref=sr_1_6?__mk_es_US=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;crid=12UIEUJFT9LDP&amp;dchild=1&amp;keywords=router&amp;qid=1599645204&amp;sprefix=router%2Caps%2C222&amp;sr=8-6">https://www.amazon.com/-/es/TP-Link-N450-Wi-Fi-Router-TL-WR940N/dp/B003Y5RYNY/ref=sr_1_6?__mk_es_US=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;crid=12UIEUJFT9LDP&amp;dchild=1&amp;keywords=router&amp;qid=1599645204&amp;sprefix=router%2Caps%2C222&amp;sr=8-6</a></p><h3>LABELING THE IMAGES</h3><p>Here is the tedious step, to train a detector, we have to label images. To do that, we have many options. Here we will use a program available in Github from <strong><em>Yonghye Kwon</em></strong><em>, </em><a href="https://github.com/developer0hye/Yolo_Label">https://github.com/developer0hye/Yolo_Label</a> there is some improvement points about this app that I want you to take care of:</p><ul><li>If you don’t see the windows complete, change your computer screen resolution because you can’t change the size of the app windows</li><li>Sometimes the box over the image is not entirely close but don’t worry about that</li></ul><p>Put all the car images in a folder named <strong>car</strong>, and all the Motorcycle images in a folder called <strong>motorcycle. After </strong>that, put both folders in a new folder named <strong>ParkingImages </strong>and create a new file named <strong><em>obj.names</em></strong> inside the folder, put the following words <strong><em>car, plate, motorcycle</em></strong> in the file one word per line</p><p>Run the YoloLabel.exe, and let’s label the images. You have to do it with the car and motorcycle folder. We can’t merge the photos because we need to do a train and test split with a balanced amount of images of both classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/129/1*gM3zrCRxqvteXoH0ylIpSQ.png" /><figcaption>Folder Structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*4kum3n55j1_yYJyGAy795Q.png" /><figcaption>Inside the PakingImages Folder</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*hDAq0OhF0erlIt5ePFaSrQ.png" /><figcaption>obj.names File</figcaption></figure><p>After that, we have to run the following script to Split your data into train and test. Here it is, you have to put it in the <strong>ParkingImages </strong>folder and run it with the following command.</p><pre>$ python TrainTestSplit.py</pre><p>or</p><pre>$ python3 TrainTestSplit.py</pre><p>Note: if you don´t have imutils library installed, run the following command:</p><pre>$ pip install imutils</pre><p>After running the script, you have to merge the cars and motorcycle’s images in a folder named <strong>data </strong>and delete the car and motorcycle folders. You will end with the following structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*kLk9PxR-MrCd8GJ0nkmFtQ.png" /></figure><p>At the end with this step, you should finish with a folder named data with all your images and a .<strong>txt </strong>file for each image you also have, another file <strong><em>obj.names </em></strong>for the name of the objects to detect in our case, <strong><em>car, plate, and motorcycle </em></strong>additionally you will have <strong>train.txt</strong> and <strong>test.txt </strong>two files containing the paths of the images to train and test the tiny-yolov4</p><h3>TRAINING TINY-YOLOV4</h3><p>Here is the exciting part, we will train our custom object detector using COLAB, the google’s open platform for running python code in a GPU for free.</p><blockquote>“We will not reinvent the wheel”.</blockquote><p>with this phrase in mind, we will follow a Github repo to train the Tiny-YoloV4</p><p>Our training process is based on Github: <a href="https://github.com/reubenbf/quick-yolov4-tiny">https://github.com/reubenbf/quick-yolov4-tiny</a></p><p>But first, we have to Compress the <strong>ParkingImages </strong>folder and name it as <strong>ParkingImages.zip</strong> and upload it to GOOGLE DRIVE in your root folder because it is needed in Step 5.</p><p>I made some modifications to avoid use Roboflow, my Colab Notebook is <a href="https://colab.research.google.com/drive/1AhCZHmp5I2YTcaHqND4FDhdYz1mmRXq8?usp=sharing">Here</a>, the Notebook explains to you how to update and where you have to place the folder with the images we labeled in the previous steps.</p><p>At the end of this step, you should finish with 4 main files,</p><ul><li>yolov4-tiny-obj_best.weights — you can find it in /darknet/backup/</li><li>yolov4-tiny-obj.cfg — you can find it in /darknet/cfg/</li><li>obj.data — you can find it in /darknet/data/</li><li>obj.names — you can find it in /darknet/data/</li></ul><p>That&#39;s what we need to deploy in the Jetson Nano</p><h3>INSTALLING DARKNET IN JETSON NANO</h3><p>To install Darknet on Jetson Nano, you have to follow these steps:</p><ul><li>Download the image from the Nvidia web page <a href="https://developer.nvidia.com/jetson-nano-sd-card-image">https://developer.nvidia.com/jetson-nano-sd-card-image</a>, review the requirements in the Nvidia web page to avoid any issue</li><li>Run the following commands:</li></ul><pre>$ mkdir ${HOME}/project<br>$ cd ${HOME}/project<br>$ git clone <a href="https://github.com/AlexeyAB/darknet.git">https://github.com/AlexeyAB/darknet.git</a><br>$ cd darknet</pre><p>Verify you are in the darknet folder with the PWD command, as shown. In my case, rafael is in the path, but in your case, may change this part of the path:</p><pre>$ pwd<br>/home/rafael/Documents/project/darknet</pre><p>Delete the <strong>Makefile </strong>existing in the darknet folder and replace it with <a href="https://drive.google.com/uc?export=download&amp;id=1uNKGBQPxLNMTfAB0dSGaHWB55YUPCgNz"><strong>this</strong></a> with all the configuration needed to compile in the Jetson Nano</p><p>Run the following command to compile darknet</p><pre>$ make</pre><pre>## to get the max of the Jetson Nano<br>$ sudo nvpmodel -m 0<br>$ sudo jetson_clocks</pre><p>With this part, we are done, ready to run the first test.</p><h3>RUNNING BASIC TEST</h3><p>First of all, let’s get an image to test. To do this, you can download from <a href="http://www.tucarro.com.co/">www.tucarro.com.co</a>, to download open the image on a different tab and change the extension from .webp to .jpeg manually. Here is an example:</p><pre><a href="https://http2.mlstatic.com/spark-life-full-aire-acondicionada-D_NQ_NP_650151-MCO43229406559_082020-F.webp">https://http2.mlstatic.com/spark-life-full-aire-acondicionada-D_NQ_NP_650151-MCO43229406559_082020-F.webp</a></pre><pre>## to</pre><pre><a href="https://http2.mlstatic.com/spark-life-full-aire-acondicionada-D_NQ_NP_650151-MCO43229406559_082020-F.webp">https://http2.mlstatic.com/spark-life-full-aire-acondicionada-D_NQ_NP_650151-MCO43229406559_082020-F.</a>jpeg</pre><p>and save it as <strong>car.jpeg</strong> in the darknet folder.</p><p>Copy the files from the training step to :</p><ul><li>yolov4-tiny-obj_best.weights <strong>to</strong> /darknetfolder</li><li>yolov4-tiny-obj.cfg <strong>to</strong> /darknetfolder</li><li>obj.data rename it as <strong>coco.data </strong>and move it to /darknet/cfg folder</li><li>obj.names <strong>to</strong> /darknet/data folder</li></ul><pre>$ ./darknet detector test cfg/coco.data \<br>                          yolov4-tiny-obj.cfg \<br>                          yolov4-tiny-obj_best.weights \<br>                          car.jpeg</pre><p>After that, you will see the image with the bounding boxes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TeJAseIFHed4bCCI61j3Xg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lq5nznvV1aa_zmCU2WoUVQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfUg3S0hLaq_mjJUjYZQcw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*QKv_3i97GmH64nC8eRTYbw.jpeg" /><figcaption>Predictions</figcaption></figure><p>As we can see, there are some cases where we have false positives, the first one is closer to the images used to train the model, is crucial for us to select the images to train, and this is a trade-off between accuracy (traying to get similar photos controlling the position, the camera used to take the pictures and light conditions) or generic usage (trying to get a lot of images from different angles, cameras, and light conditions)</p><h3>NEXT STEPS</h3><ul><li>Script to run the detector in real-time</li><li>Segment Characters and read the License Plate</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5da6f975ea14" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>