<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Raz</title>
    <description>The latest articles on DEV Community by Raz (@razcodes).</description>
    <link>https://dev.to/razcodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F337113%2Fbe6b6d3d-ba47-44b7-9427-7422e0d09813.jpg</url>
      <title>DEV Community: Raz</title>
      <link>https://dev.to/razcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/razcodes"/>
    <language>en</language>
    <item>
      <title>How to do a quick network recon during a pentest or CTF</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 07 Jun 2020 15:32:34 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-do-a-quick-network-recon-during-a-pentest-or-ctf-2o21</link>
      <guid>https://dev.to/razcodes/how-to-do-a-quick-network-recon-during-a-pentest-or-ctf-2o21</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since I have been learning more lately about pentesting, and playing on sites like &lt;a href="https://tryhackme.com/"&gt;tryhackme.com&lt;/a&gt;, I find myself starting with the same tools usually so I decided to write this short post about the process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Init
&lt;/h2&gt;

&lt;p&gt;Sometimes you know the IP of the machine that you will be working on and sometimes you don't. Sometimes there is more than one machine on the network you want to look into, so in those cases, you start with the basic IP scan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nmap &lt;span class="nt"&gt;-sn&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 192.168.0.0/24 &lt;span class="nt"&gt;-oN&lt;/span&gt; discovery.nmap
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;-sn&lt;/span&gt;: ping scan
&lt;span class="nt"&gt;-n&lt;/span&gt;: no DNS resolution
&lt;span class="nt"&gt;-oN&lt;/span&gt;: output scan &lt;span class="k"&gt;in &lt;/span&gt;normal to file
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Besides using &lt;em&gt;nmap&lt;/em&gt; for this, you can also use &lt;em&gt;netdiscover&lt;/em&gt; to see all the machine on the current network by specifying the interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;netdiscover &lt;span class="nt"&gt;-i&lt;/span&gt; tap0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here I use &lt;em&gt;tap0&lt;/em&gt; as the interface if I am connected to a VPN or if I just look at machines on my internal network I would use &lt;em&gt;eth0&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;netdiscover &lt;span class="nt"&gt;-i&lt;/span&gt; eth0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once &lt;em&gt;nmap&lt;/em&gt; is done running, I take that file and remove everything from it leaving just the IPs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;discovery.nmap | &lt;span class="nb"&gt;grep &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; 5 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ips.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I also make sure my IP is not in there so I don't scan myself.&lt;/p&gt;

&lt;h2&gt;
  
  
  More
&lt;/h2&gt;

&lt;p&gt;Now that we have a list of IPs, I can run a longer scan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;nmap &lt;span class="nt"&gt;-sV&lt;/span&gt; &lt;span class="nt"&gt;-p-&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-Pn&lt;/span&gt; &lt;span class="nt"&gt;-T4&lt;/span&gt; &lt;span class="nt"&gt;-iL&lt;/span&gt; ips.txt &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nt"&gt;--open&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;-sV&lt;/span&gt;: version info
&lt;span class="nt"&gt;-p-&lt;/span&gt;: scan all ports
&lt;span class="nt"&gt;-n&lt;/span&gt;: no DNS resolution
&lt;span class="nt"&gt;-v&lt;/span&gt;: verbose
&lt;span class="nt"&gt;-Pn&lt;/span&gt;: treat host as online
&lt;span class="nt"&gt;-T4&lt;/span&gt;: timing template
&lt;span class="nt"&gt;-iL&lt;/span&gt;: use the file and only scan IPs &lt;span class="k"&gt;in &lt;/span&gt;it
&lt;span class="nt"&gt;-A&lt;/span&gt;: OS detection, version, script scan, traceroute
&lt;span class="nt"&gt;--open&lt;/span&gt;: only show open
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Of course these might not work for every engagement and you should read more about &lt;em&gt;nmap&lt;/em&gt; strategies before using them, but for my needs so far these have worked well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Website involved
&lt;/h2&gt;

&lt;p&gt;If the scans above yield some http ports open (80,8080, etc), I then run &lt;em&gt;dirbuster&lt;/em&gt; to look for any folders that might be hidden.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;dirb http://10.10.47.53
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Fork in the road
&lt;/h2&gt;

&lt;p&gt;After the usual scan above is where I take a different road based on whatever scenario I encounter, now that I have the data I need from the scan.&lt;/p&gt;

&lt;p&gt;Happy scanning!&lt;/p&gt;

</description>
      <category>security</category>
      <category>nmap</category>
      <category>pentest</category>
      <category>ctf</category>
    </item>
    <item>
      <title>How to use AWS named profiles</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 31 May 2020 20:58:35 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-use-aws-named-profiles-29cl</link>
      <guid>https://dev.to/razcodes/how-to-use-aws-named-profiles-29cl</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might get to a point where for some reason or another you find yourself needing to use more than one set of AWS CLI credentials. Usually that's the case when you have more than one AWS account or you want to test the same account but with different permissions. So instead of keep reconfiguring your credentials every time, like someone I know used to do, you can use &lt;em&gt;named profiles&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This article assumes that you already have &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html"&gt;AWS CLI&lt;/a&gt; installed and configured. If you have not yet, I cover that in one of my older posts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the user
&lt;/h2&gt;

&lt;p&gt;We are going to first create a new user and give that user read only permissions to &lt;strong&gt;S3&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;log into your AWS console&lt;/li&gt;
&lt;li&gt;Services -&amp;gt; IAM -&amp;gt; Users&lt;/li&gt;
&lt;li&gt;Add user&lt;/li&gt;
&lt;li&gt;User name (ex: s3read)&lt;/li&gt;
&lt;li&gt;Check &lt;strong&gt;Programatic access&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Next: Permissions&lt;/li&gt;
&lt;li&gt;Attach existing policies directly&lt;/li&gt;
&lt;li&gt;Check &lt;strong&gt;AmazonS3ReadOnlyAccess&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Next: Tags (optional)&lt;/li&gt;
&lt;li&gt;Next: Review&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create User&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make sure that you either download the .csv file created, or copy the &lt;em&gt;Access key ID&lt;/em&gt; and &lt;em&gt;Secret access Key&lt;/em&gt; in a password manager, because once you click close you will not be able to see it again.&lt;/p&gt;

&lt;h2&gt;
  
  
  CLI Setup
&lt;/h2&gt;

&lt;p&gt;In the terminal, where you already have the AWS CLI working type the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure &lt;span class="nt"&gt;--profile&lt;/span&gt; s3read
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The profile name can be whatever you want, you will need to use it later and it can be different than what you named the username above.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;put in your Access key ID&lt;/li&gt;
&lt;li&gt;put in your Secret access key&lt;/li&gt;
&lt;li&gt;default region (ex: us-east-1)&lt;/li&gt;
&lt;li&gt;default output (ex: json)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Invoking
&lt;/h2&gt;

&lt;p&gt;You are now all set. To start using the newly created profile you have a few options available.&lt;/p&gt;

&lt;h3&gt;
  
  
  Command style
&lt;/h3&gt;

&lt;p&gt;You can add &lt;strong&gt;--profile&lt;/strong&gt; followed by the profile name after every command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;--profile&lt;/span&gt; s3read
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  ENV style
&lt;/h3&gt;

&lt;p&gt;You can make that profile become the active profile for the current shell session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_PROFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;s3read
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After that you can just issue the commands without the --profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Oh My Zsh style
&lt;/h3&gt;

&lt;p&gt;Oh My Zsh has an &lt;a href="https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/aws/aws.plugin.zsh"&gt;AWS plugin&lt;/a&gt; and with it installed, you can just use the command &lt;em&gt;asp&lt;/em&gt; followed by the profile name to activate it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;asp s3read
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;From here on that profile will be active for the rest of the session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I put off configuring this for myself for a long time, but having to switch between 4 profiles every day motivated me to look into it and make it simple. So should you.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cli</category>
    </item>
    <item>
      <title>How to launch your first Webserver with AWS EC2</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 24 May 2020 19:32:55 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-launch-your-first-webserver-with-aws-ec2-4d8a</link>
      <guid>https://dev.to/razcodes/how-to-launch-your-first-webserver-with-aws-ec2-4d8a</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will outline in this article the steps for creating a simple HTTP server in AWS using the EC2 service, running on Amazon Linux 2.&lt;/p&gt;

&lt;p&gt;This article assumes that you already have an AWS account setup, with all the default settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Once logged into the AWS console go to &lt;strong&gt;Services&lt;/strong&gt; -&amp;gt; &lt;strong&gt;EC2&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Instances&lt;/strong&gt;  and click on &lt;strong&gt;Launch Instance&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here you will see a list with all the available images that can be launched. We will select the first one (at the time of writing this article) called &lt;strong&gt;Amazon Linux 2 AMI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Make sure &lt;strong&gt;t2.micro&lt;/strong&gt; is selected, as this is part of the free tier and click &lt;strong&gt;Next: Configure Instance Details&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On this screen we can leave most things on default, and feel free to click on the &lt;em&gt;info icon&lt;/em&gt; located by each option to get more information about what the options do. &lt;/p&gt;

&lt;p&gt;The one thing we are going to change is located towards the bottom, under &lt;strong&gt;Advanced Details&lt;/strong&gt; -&amp;gt;  &lt;em&gt;User Data&lt;/em&gt;. Here, you can include a bash script that will run when the instance is launched, with root privileges. We can use this to run a system update as well as install the run the WebServer. Just copy this script into the text field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
yum update &lt;span class="nt"&gt;-y&lt;/span&gt;
yum &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; httpd.x86_64
systemctl start httpd.service
systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;httpd.service
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"This is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;hostname&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /var/www/html/index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Next: Add Storage&lt;/strong&gt; - This is where we can select the drive(s) size and type(s) we want for the instance. We can leave everything as default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next: Add Tags&lt;/strong&gt; - Tags can be very useful for billing, inventory and all sorts of other things. For this exercise we do not need any.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next: Configure Security Groups&lt;/strong&gt; - This part will define what ports we want to leave open towards the host instance, so we will only deal with ports 22 for SSH and port 80 for HTTP.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new security group&lt;/li&gt;
&lt;li&gt;Security group name: WebServer&lt;/li&gt;
&lt;li&gt;Description: WebServer SG&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SSH is already added, but we will just open that for our machine, so under &lt;strong&gt;Source&lt;/strong&gt; click on the &lt;strong&gt;Custom&lt;/strong&gt; dropdown and select &lt;strong&gt;My IP&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;Add Rule&lt;/strong&gt; and select &lt;strong&gt;HTTP&lt;/strong&gt;. This will open port 80 for the web traffic from anywhere, which is what we want.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Review and Launch&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Launch&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a new key pair, give it a name (ex: myWebServer) and click Download Key Pair.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Launch Instances&lt;/strong&gt; -&amp;gt; &lt;strong&gt;View Instances&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now you will see you new instance being created. It will take a few minutes to get it up and running, update the system and install httpd.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser visit
&lt;/h2&gt;

&lt;p&gt;After a few minutes, with the new instance selected, you can copy the Public DNS or the IP, open a new browser window and visit your new server.&lt;/p&gt;

&lt;h2&gt;
  
  
  SSH connect
&lt;/h2&gt;

&lt;p&gt;You can click Connect on top, and you can get instructions on how to connect to it using SSH.&lt;/p&gt;

&lt;p&gt;Note that because of the way we configured the SSH port to only allow connections from our IP address, when you click connect, the EC2 Instance Connect using the browser will not work, since that will come from a different IP address. If you would like that functionality for playing around, you can go change the security group and allow connections to port 22 from 0.0.0.0/0, but that is not recommended and should only be done for testing purposes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The end
&lt;/h2&gt;

&lt;p&gt;When you are done with your instance you can select it and under &lt;strong&gt;Actions&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Instance State&lt;/strong&gt;, you can chose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; : this will stop the instance, you will no longer be charged and start it again when you want to. When you start it back up you will have a different IP address, so the connection string will be different.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminate&lt;/strong&gt;: this will destroy the instance.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>linux</category>
      <category>httpd</category>
    </item>
    <item>
      <title>How to upgrade your shell and prompt in Kali or Parrot</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 17 May 2020 18:40:17 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-upgrade-your-shell-and-prompt-in-kali-or-parrot-1oeg</link>
      <guid>https://dev.to/razcodes/how-to-upgrade-your-shell-and-prompt-in-kali-or-parrot-1oeg</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following procedure was tested in Kali Linux and Parrot OS, but it should work the same in other places, such as Ubuntu or Debian.&lt;/p&gt;

&lt;p&gt;I spend a lot of time in the terminal, both at work and home, so might as well have a good looking and useful terminal in front of me. I had this setup on my mac for a while and only recently I decided to move it over to my pentesting boxes.&lt;/p&gt;

&lt;p&gt;The things that we are going to now do are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;switch the shell from BASH to ZSH&lt;/li&gt;
&lt;li&gt;install Oh My Zsh&lt;/li&gt;
&lt;li&gt;install MesloLGS NF fonts&lt;/li&gt;
&lt;li&gt;install powerlevel10k theme&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The $SHELL
&lt;/h2&gt;

&lt;p&gt;This step is the easiest one. Open a terminal and issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;chsh &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;which zsh&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You will probably have to log out and log back in for the changes to take effect. Once you do, open a terminal again and you will be welcomed by a question about being the first time you setup ZSH so just chose option 2, to populate your config file with the default settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Oh My Zsh
&lt;/h2&gt;

&lt;p&gt;This framework is amazing, with so many plugins, feature and add-ons. You should totally dig more into it if you haven't already and look at the possibilities.&lt;/p&gt;

&lt;p&gt;You can install it using their installer, with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Powerlevel10k
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Fonts
&lt;/h3&gt;

&lt;p&gt;This is the actual eye candy part of the process. We are going to start by installing some fonts that contain icons that will be used by the theme. This can be achieved in many ways, but here is my process. This will download the fonts to a local folder and install them on your system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/.local/share/fonts
&lt;span class="nb"&gt;cd&lt;/span&gt;  ~/.local/share/fonts
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
fc-cache &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once this is done, quit terminal and open it back up. Now go to &lt;strong&gt;File&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Preferences&lt;/strong&gt; and set the terminal font to &lt;strong&gt;MesloLGS NF&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Theme
&lt;/h3&gt;

&lt;p&gt;Now we can install the theme by cloning the git repo and then making the change in the config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &lt;span class="nt"&gt;--depth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 https://github.com/romkatv/powerlevel10k.git &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ZSH_CUSTOM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="p"&gt;~/.oh-my-zsh/custom&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/themes/powerlevel10k
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s1"&gt;'s/robbyrussell/powerlevel10k\/powerlevel10k/g'&lt;/span&gt; ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can log out of the terminal and log back in and it's customization time. Here you can chose whatever you want to make it look how you like it the most. Here are the buttons that I pressed to get the prompt I love:&lt;/p&gt;

&lt;p&gt;y,y,y,y,3,1,2,1,1,1,2,3,4,4,1,2,2,y,3,y&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.kali.org/"&gt;https://www.kali.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://parrotlinux.org/"&gt;https://parrotlinux.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ohmyzsh/ohmyzsh"&gt;https://github.com/ohmyzsh/ohmyzsh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/romkatv/powerlevel10k"&gt;https://github.com/romkatv/powerlevel10k&lt;/a&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>kali</category>
      <category>shell</category>
      <category>terminal</category>
    </item>
    <item>
      <title>How to create a lambda layer in AWS</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 10 May 2020 15:39:41 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-create-a-lambda-layer-in-aws-106m</link>
      <guid>https://dev.to/razcodes/how-to-create-a-lambda-layer-in-aws-106m</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the last article I wrote that one of the options you have, when creating a lambda function in AWS that requires external modules, is to use a lambda layer that contains all these modules. That way, the lambda is independent of those modules, can be updated by itself, and also you can share that layer between lambdas that use the same modules, thus making it easier to maintain.&lt;/p&gt;

&lt;p&gt;In this article, I will use the same example program from the last one, but instead of bundling everything together, I will create a lambda layer that can be used by the lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing the layer
&lt;/h2&gt;

&lt;p&gt;First create a new folder for this project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;aws-lambda-layer
&lt;span class="nb"&gt;cd &lt;/span&gt;aws-lambda-layer
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, create a folder structure for the modules that need to be installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; lambda-layer/python/lib/python3.8/site-packages
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once the folder is created we can install &lt;em&gt;requests&lt;/em&gt; in that folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;pip3 &lt;span class="nb"&gt;install &lt;/span&gt;requests &lt;span class="nt"&gt;--target&lt;/span&gt; lambda-layer/python/lib/python3.8/site-packages
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That folder structure is important because that is where Python expects to find the modules. Also as you can see, in this example I am using Python 3.8.&lt;/p&gt;

&lt;p&gt;Now we can go into the &lt;em&gt;lambda-layer&lt;/em&gt; folder and create a zip file for the layer that will be uploaded using the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;lambda-layer
zip &lt;span class="nt"&gt;-r9&lt;/span&gt; lambda-layer.zip &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating the layer
&lt;/h2&gt;

&lt;p&gt;Log into the AWS console and go to Services -&amp;gt; Lambda -&amp;gt; Layers&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create layer&lt;/li&gt;
&lt;li&gt;Name (ex: myRequestsLayer)&lt;/li&gt;
&lt;li&gt;Upload&lt;/li&gt;
&lt;li&gt;Select your zip file from before&lt;/li&gt;
&lt;li&gt;Runtime (Python 3.8)&lt;/li&gt;
&lt;li&gt;Create&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating the lambda
&lt;/h2&gt;

&lt;p&gt;We will be creating the lambda manually for this exercise, so in the AWS console go to Services -&amp;gt; Lambda&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create function&lt;/li&gt;
&lt;li&gt;Author from scratch&lt;/li&gt;
&lt;li&gt;Function name (ex: randomDadJokes)&lt;/li&gt;
&lt;li&gt;Runtime (Python 3.8)&lt;/li&gt;
&lt;li&gt;Create function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Replace the code in the editor with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'https://icanhazdadjoke.com'&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Accept"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'joke'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hit &lt;strong&gt;Save&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting the layer
&lt;/h2&gt;

&lt;p&gt;Still on the lambda screen, in the Designer section, click on the Layers box.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a layer&lt;/li&gt;
&lt;li&gt;Select from list of runtime compatible layers&lt;/li&gt;
&lt;li&gt;Name (chose your layer)&lt;/li&gt;
&lt;li&gt;Version 1&lt;/li&gt;
&lt;li&gt;Add&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating the Test event
&lt;/h2&gt;

&lt;p&gt;We also need to create a test event so we can trigger the lambda manually. You can do that by clicking on the dropdown (Select a test event) -&amp;gt; Configure test events.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give it an Event Name (ex: Run)&lt;/li&gt;
&lt;li&gt;Inputs don't matter so you can just leave it as is or delete those keys&lt;/li&gt;
&lt;li&gt;Create&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run it
&lt;/h2&gt;

&lt;p&gt;Now you can click on the &lt;strong&gt;Test&lt;/strong&gt; button and you should see a random dad joke.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thoughts
&lt;/h2&gt;

&lt;p&gt;I really like the layers a lot better than having to bundle everything together, because it's not just easier to maintain, but also now I can play with the lambda and edit the code or debug it right there in the browser and I don't have to package it and re upload every time I make a change. This makes prototyping a lot easier and fun.&lt;/p&gt;

&lt;p&gt;Note that other type of data can also be included in a layer so if you want to learn more, make sure you visit the &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html"&gt;AWS Lambda layers&lt;/a&gt; page.&lt;/p&gt;

</description>
      <category>python</category>
      <category>aws</category>
      <category>serverless</category>
    </item>
    <item>
      <title>How to create a lambda using Python with dependencies</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 03 May 2020 18:28:28 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-create-a-lambda-using-python-with-dependencies-4846</link>
      <guid>https://dev.to/razcodes/how-to-create-a-lambda-using-python-with-dependencies-4846</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you have a Python script that uses modules, which are not included in the &lt;a href="https://docs.python.org/3/library/"&gt;Python Standard Library&lt;/a&gt;, and want to run it as a lambda in AWS, you have two options. First one would be to create a AWS Lambda Layer that contains all the packages and then is connected to the Lambda, and the second would be to zip together the Lambda and the modules, creating a package that can then be uploaded and run. This article will cover the second option.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;As an example I will be creating a small script that uses the Python library Requests. We will be pulling a random dad joke from &lt;a href="https://icanhazdadjoke.com/api"&gt;icahasdadjoke&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the terminal, create a new folder, create a new virtual environment, activate it and install requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;dad-jokes-lambda
&lt;span class="nb"&gt;cd &lt;/span&gt;dad-jokes-lambda
python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate
pip &lt;span class="nb"&gt;install &lt;/span&gt;requests
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can now create the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;lambda_function.py
vim lambda_function.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The code will look something like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'https://icanhazdadjoke.com'&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Accept"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'joke'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  The Lambda
&lt;/h2&gt;

&lt;p&gt;To create the lambda, login into the AWS console and go to Services -&amp;gt; Lambda.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create function&lt;/li&gt;
&lt;li&gt;Author from scratch&lt;/li&gt;
&lt;li&gt;Fill in the function name (randomDadJoke)&lt;/li&gt;
&lt;li&gt;Runtime - Python 3.8&lt;/li&gt;
&lt;li&gt;Create function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We also need to create a test event so we can trigger the lambda manually. You can do that by clicking on the dropdown (Select a test event) -&amp;gt; Configure test events.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give it an Event Name (ex: Run)&lt;/li&gt;
&lt;li&gt;Inputs don't matter so you can just leave it as is or delete those keys&lt;/li&gt;
&lt;li&gt;Create&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, you could paste the code in the text editor in your browser and save, but you will notice that if you try running the lambda , by clicking &lt;strong&gt;Test&lt;/strong&gt;, it will fail, because it cannot find the requests module. We are going to fix that next.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bundle
&lt;/h2&gt;

&lt;p&gt;Back in the terminal, in the project folder, we will create a zip file with the dependencies and then add the lambda code to that zip file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;venv/lib/python3.8/site-packages
zip &lt;span class="nt"&gt;-r9&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;OLDPWD&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/function.zip &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="nv"&gt;$OLDPWD&lt;/span&gt;
zip &lt;span class="nt"&gt;-g&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;.zip lambda_function.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  All together now
&lt;/h2&gt;

&lt;p&gt;Back in the AWS console, on the lambda screen, in the &lt;em&gt;Function code&lt;/em&gt; section, click on the dropdown for &lt;strong&gt;Code entry type&lt;/strong&gt; and select &lt;strong&gt;Upload a .zip file&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload&lt;/li&gt;
&lt;li&gt;Select the function.zip file created&lt;/li&gt;
&lt;li&gt;Open&lt;/li&gt;
&lt;li&gt;Save&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Optionals
&lt;/h2&gt;

&lt;p&gt;You will notice that you can no longer see the code editor, but instead you see a message telling you why. Every time you want to change the code for that lambda, you will have to update it on your machine, update the zip file with the new code and upload it again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;zip &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;.zip lambda_function.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Test
&lt;/h2&gt;

&lt;p&gt;You can now click on the &lt;strong&gt;Test&lt;/strong&gt; button on top and the lambda will run, rewarding you with a dad joke. Have fun!&lt;/p&gt;

</description>
      <category>python</category>
      <category>aws</category>
      <category>lambda</category>
    </item>
    <item>
      <title>How to create and invoke a lambda using the AWS CLI</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 26 Apr 2020 23:57:43 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-create-and-invoke-a-lambda-using-the-aws-cli-28jc</link>
      <guid>https://dev.to/razcodes/how-to-create-and-invoke-a-lambda-using-the-aws-cli-28jc</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's say you create a cool little program that does some automation for you, or chore you need, and you then turn it into a lambda in AWS, but you don't want to go into the console and log in all the time you want to run it. You can invoke this program right from the AWS CLI, and here is how.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;I will be creating a simple Node.js function that gives us a random Star Wars Quote every time we invoke it.&lt;/p&gt;

&lt;p&gt;Using the terminal, create the folder and cd into it and create the function file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;randomStarWarsQuoteGen
&lt;span class="nb"&gt;cd &lt;/span&gt;randomStarWarsQuoteGen
&lt;span class="nb"&gt;touch &lt;/span&gt;index.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using your favorite text editor add the code to the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;vim index.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is the simple code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Help me, Obi-Wan Kenobi. You’re my only hope. — Leia Organa&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I find your lack of faith disturbing. — Darth Vader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The Force will be with you. Always. — Obi-Wan Kenobi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Never tell me the odds! — Han Solo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Do. Or do not. There is no try. — Yoda&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;No. I am your father. — Darth Vader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;There’s always a bigger fish. — Qui-Gon Jinn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;You can’t stop the change, any more than you can stop the suns from setting. — Shmi Skywalker&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I’m just a simple man trying to make my way in the universe. — Jango Fett&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Power! Unlimited power! — Darth Sidious&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  The Lambda Role
&lt;/h2&gt;

&lt;p&gt;To follow along from here you will need to have the AWS CLI installed and configured on your machine. My last article covered that, so make sure you go and read it if you need to.&lt;/p&gt;

&lt;p&gt;The lambda will need a role so let's create one. First we need to create a new file called trust.json for the assume role policy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;trust.json
vim trust.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add the following to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"Service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"lambda.amazonaws.com"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can create the role using the CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam create-role &lt;span class="nt"&gt;--role-name&lt;/span&gt; randomStarWarsQuoteGenRole &lt;span class="nt"&gt;--assume-role-policy-document&lt;/span&gt; file://trust.json &lt;span class="nt"&gt;--description&lt;/span&gt; &lt;span class="s2"&gt;"Random Star Wars Quote Generator Role"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Make sure you copy down somewhere the result ARN as we will need to use it to create the function.&lt;/p&gt;

&lt;p&gt;Now let's attach to that new role the AWSLambdaBasicExecutionRole policy, which is managed by AWS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam attach-role-policy &lt;span class="nt"&gt;--role-name&lt;/span&gt; randomStarWarsQuoteGenRole &lt;span class="nt"&gt;--policy-arn&lt;/span&gt; arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  The Lambda
&lt;/h2&gt;

&lt;p&gt;With the role created and policy attached, we can now create the function.&lt;/p&gt;

&lt;p&gt;First, create a zip file of your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;zip &lt;span class="k"&gt;function&lt;/span&gt;.zip index.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you are ready to create the function, making sure to replace &lt;strong&gt;your-role-arn&lt;/strong&gt; with the ARN that you wrote down in the above step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda create-function &lt;span class="nt"&gt;--function-name&lt;/span&gt; randomStarWarsQuoteGen &lt;span class="nt"&gt;--runtime&lt;/span&gt; nodejs12.x &lt;span class="nt"&gt;--handler&lt;/span&gt; index.handler &lt;span class="nt"&gt;--role&lt;/span&gt; &amp;lt;your-role-arn&amp;gt; &lt;span class="nt"&gt;--zip-file&lt;/span&gt; fileb://function.zip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you need to update the lambda code in the future, you can just update your code, create the zip file again and then use the update command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda update-function-code &lt;span class="nt"&gt;--function-name&lt;/span&gt; randomStarWarsQuoteGen &lt;span class="nt"&gt;--zip-file&lt;/span&gt; fileb://function.zip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Invocation Time
&lt;/h2&gt;

&lt;p&gt;To call the function, you simply use the following command, where &lt;strong&gt;result.json&lt;/strong&gt; is the file that will contain the function response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda invoke &lt;span class="nt"&gt;--function-name&lt;/span&gt; randomStarWarsQuoteGen result.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>node</category>
      <category>lambda</category>
      <category>cli</category>
    </item>
    <item>
      <title>How to get up and running with AWS CLI on macOS</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 19 Apr 2020 14:20:15 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-get-up-and-running-with-aws-cli-on-macos-2cf4</link>
      <guid>https://dev.to/razcodes/how-to-get-up-and-running-with-aws-cli-on-macos-2cf4</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While you can do all the things you need in AWS using the console, the AWS CLI offers a convenient way to control your environment from the terminal as well as to create simple or complex automations through scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get credentials
&lt;/h2&gt;

&lt;p&gt;The first thing that you will need to be able to issue commands is a set of security credentials, that is an Access Key ID and a Secret Access Key. You can do that by using the AWS console.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;login to your account&lt;/li&gt;
&lt;li&gt;Services -&amp;gt; IAM&lt;/li&gt;
&lt;li&gt;Users&lt;/li&gt;
&lt;li&gt;Add user&lt;/li&gt;
&lt;li&gt;Give it a username (this is more for you, it will not be used ex: service)&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Programmatic access&lt;/strong&gt; then click &lt;em&gt;Next&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Attach exiting policies&lt;/li&gt;
&lt;li&gt;For this demo I selected &lt;em&gt;AdministratorAccess&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Next add tags if you want&lt;/li&gt;
&lt;li&gt;Next Review your choices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create user&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you clicked on &lt;em&gt;Create user&lt;/em&gt;, you will be given the option to download a .csv file with the credentials or you can copy them from this screen for later use and maybe keep them in a password manager. Please keep in mind that this will be the one and only time you will see the Secret access key in the console, so make sure you save it somewhere safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install the CLI
&lt;/h2&gt;

&lt;p&gt;The easiest way to install the CLI on a Mac is by using &lt;strong&gt;Homebrew&lt;/strong&gt;. If you don't have it installed already you can do so by following the instructions on their &lt;a href="https://brew.sh/"&gt;website&lt;/a&gt;, which say that you need to paste this following command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;/bin/bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/Homebrew/install/master/install.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once you have Homebrew installed, simply issue the following command in your terminal to install the AWS CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;awscli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will install awscli version 2 at the time of writing this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the CLI with your credentials
&lt;/h2&gt;

&lt;p&gt;Now you need to tell the CLI what credentials to use to it can access your AWS account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;paste your AWS Access Key ID&lt;/li&gt;
&lt;li&gt;paste your AWS Secret Access Key&lt;/li&gt;
&lt;li&gt;fill in your default region (ex: us-east-1)&lt;/li&gt;
&lt;li&gt;default output can be json, yaml, text, table (I chose json)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Issue commands and get help
&lt;/h2&gt;

&lt;p&gt;Now you can issue commands. For example to see a list of all your s3 buckets you would type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To get general help from the CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws &lt;span class="nb"&gt;help&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To get help for a specific command, so you know how to use it, issue the command followed by &lt;em&gt;help&lt;/em&gt;. For example, to get help on using the CLI with S3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;help&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Named Profiles (optional)
&lt;/h2&gt;

&lt;p&gt;When you configured your credentials above, this created a folder in your home directory called &lt;em&gt;.aws&lt;/em&gt; as well as 2 files in that folder, &lt;em&gt;credentials&lt;/em&gt; and &lt;em&gt;config&lt;/em&gt;. These files can be used to configure additional profiles, either for different users in the same account, with different permissions, or as I use them, for different AWS accounts.&lt;/p&gt;

&lt;p&gt;Let's say you want to add another user profile. You would first edit the credentials file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;vim ~/.aws/credentials
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Under your default account you add the following lines, replacing the username and the credentials with yours.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;username]
&lt;span class="nv"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;your_access_key_id&amp;gt;
&lt;span class="nv"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;your_secret_access_key&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next edit the config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;vim ~/.aws/config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add your new profile information under the existing one, making sure the username matches the one in your credentials file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;profile username]
&lt;span class="nv"&gt;region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east-1
&lt;span class="nv"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, you can use your new profile by issuing the following command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_PROFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;username
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;From this point, every aws command will use this profile's credentials.&lt;/p&gt;

&lt;p&gt;To read more about the AWS CLI and all the options you can visit &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html"&gt;this link&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cli</category>
      <category>bash</category>
      <category>mac</category>
    </item>
    <item>
      <title>How to run a lambda locally and deploy it to AWS using SAM</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 12 Apr 2020 19:19:01 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-run-a-lambda-locally-and-deploy-it-to-aws-using-sam-3g6b</link>
      <guid>https://dev.to/razcodes/how-to-run-a-lambda-locally-and-deploy-it-to-aws-using-sam-3g6b</guid>
      <description>&lt;p&gt;This article was also published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/serverless/sam/"&gt;AWS SAM&lt;/a&gt; or Serverless Application Model, is a framework for building serverless applications. There are several things I like about this framework that I have just discovered, from the fact that it's an extension of CloudFormation which gives you an awesome reliable way to deploy and describe your application and resources to the fact that in combination with Docker it allows you to test and debug your code locally.&lt;/p&gt;

&lt;p&gt;This article will serve as a quick intro to SAM to get you a taste of what the process might look like.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;In my examples, I am using a mac, but you should be able to get the same experience using a different OS with minor changes here and there. To get started, you will need to have the following things in place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/free"&gt;AWS Account&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html"&gt;AWS CLI&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ aws &lt;span class="nt"&gt;--version&lt;/span&gt;
aws-cli/2.0.0 Python/3.8.1 Darwin/19.4.0 botocore/2.0.0dev4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.docker.com/get-docker/"&gt;Docker&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ docker &lt;span class="nt"&gt;--version&lt;/span&gt;
Docker version 19.03.8, build afacb8b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://aws.amazon.com/serverless/sam/"&gt;SAM CLI&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ sam &lt;span class="nt"&gt;--version&lt;/span&gt;
SAM CLI, version 0.47.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.python.org/"&gt;Python&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ python3 &lt;span class="nt"&gt;--version&lt;/span&gt;
Python 3.8.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;First step is to create a new project in a folder of your choice using the &lt;em&gt;init&lt;/em&gt; option. For this example I will be using the Python runtime so I will pass that as a parameter to the SAM CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sam init &lt;span class="nt"&gt;--runtime&lt;/span&gt; python3.8 &lt;span class="nt"&gt;--name&lt;/span&gt; sam-lambda-demo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;Which template &lt;span class="nb"&gt;source &lt;/span&gt;would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Cloning app templates from https://github.com/awslabs/aws-sam-cli-app-templates.git

AWS quick start application templates:
        1 - Hello World Example
        2 - EventBridge Hello World
        3 - EventBridge App from scratch &lt;span class="o"&gt;(&lt;/span&gt;100+ Event Schemas&lt;span class="o"&gt;)&lt;/span&gt;
Template selection: 1

&lt;span class="nt"&gt;-----------------------&lt;/span&gt;
Generating application:
&lt;span class="nt"&gt;-----------------------&lt;/span&gt;
Name: sam-lambda-demo
Runtime: python3.8
Dependency Manager: pip
Application Template: hello-world
Output Directory: &lt;span class="nb"&gt;.&lt;/span&gt;

Next steps can be found &lt;span class="k"&gt;in &lt;/span&gt;the README file at ./sam-lambda-demo/README.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will create all the folders and files that you would need for a simple &lt;em&gt;Hello World&lt;/em&gt; app. You can open the newly created folder in VS Code and explore the files and folders created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;sam-lambda-demo
code &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The two important files to look at right away would be &lt;strong&gt;README.md&lt;/strong&gt;, that is a nicely documented file with more information about what is going on, and then &lt;strong&gt;template.yaml&lt;/strong&gt;, which is the file that will be used to create the CloudFormation template and get things ready for deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy to AWS
&lt;/h2&gt;

&lt;p&gt;You will need an S3 bucket in your AWS account, where your code will be stored. Keep in mind that buckets name have to be unique so make sure to chose an &lt;em&gt;original&lt;/em&gt; name. I called mine &lt;strong&gt;raz-sam-us-east-1&lt;/strong&gt;. You can create a new bucket from the console or to create a new bucket using the AWS CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 mb s3://raz-sam-us-east-1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First you will need to create the package. This will create a new yaml file for CloudFormations as well as upload all the code to AWS in your S3 bucket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sam package &lt;span class="nt"&gt;--template-file&lt;/span&gt; template.yaml &lt;span class="nt"&gt;--output-template-file&lt;/span&gt; deploy.yaml &lt;span class="nt"&gt;--s3-bucket&lt;/span&gt; raz-sam-us-east-1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once that is done, you can run the deploy command that will create the stack in CloudFormations. You need to provide the command with the stack name of your choice as well as the deploy.yaml file that was created in the last step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sam deploy &lt;span class="nt"&gt;--template-file&lt;/span&gt; deploy.yaml &lt;span class="nt"&gt;--stack-name&lt;/span&gt; SAMLambdaDemo &lt;span class="nt"&gt;--capabilities&lt;/span&gt; CAPABILITY_IAM
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A nice screen will be presented to you in the terminal showing the progress of the stack creation. Once the process is complete you can look at the &lt;strong&gt;Outputs&lt;/strong&gt; section on the screen for a link to the new API endpoint, name of the lambda function, as well as the role. Copy the URL for the api and put it in your browser to see the "hello world" message on your screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;: &lt;span class="s2"&gt;"hello world"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also log into the AWS console and under &lt;strong&gt;CloudFormations&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Stacks&lt;/strong&gt; find your new stack. There you can go under &lt;em&gt;Resources&lt;/em&gt; to see everything that was built as well as under &lt;em&gt;Outputs&lt;/em&gt; where you can see the same info that was presented above in the terminal.&lt;/p&gt;

&lt;p&gt;Once you are done playing around, if you want to delete the stack together with all the resources that have been created you can do it right from the console or from the CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudformation delete-stack &lt;span class="nt"&gt;--stack-name&lt;/span&gt; SAMLambdaDemo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Run it locally
&lt;/h2&gt;

&lt;p&gt;Mare sure you have Docker up and running for this as it will spin up a new container.&lt;/p&gt;

&lt;p&gt;There are two ways of doing this. You can run it as a function when you just expect the result in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sam &lt;span class="nb"&gt;local &lt;/span&gt;invoke HelloWorldFunction &lt;span class="nt"&gt;--no-event&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will spin up a container, run the function and shut it down. Keep in mind that the first run will take longer because it will have to download the Python3.8 Docker image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;Invoking app.lambda_handler &lt;span class="o"&gt;(&lt;/span&gt;python3.8&lt;span class="o"&gt;)&lt;/span&gt;

Fetching lambci/lambda:python3.8 Docker container image......................................................................................................................................
Mounting /Users/raz/aws-sam/sam-lambda-demo/hello_world as /var/task:ro,delegated inside runtime container
START RequestId: cb2eff67-910e-15d1-7f6f-48087ac290bb Version: &lt;span class="nv"&gt;$LATEST&lt;/span&gt;
END RequestId: cb2eff67-910e-15d1-7f6f-48087ac290bb
REPORT RequestId: cb2eff67-910e-15d1-7f6f-48087ac290bb  Init Duration: 88.72 ms Duration: 2.58 ms       Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 25 MB

&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"statusCode"&lt;/span&gt;:200,&lt;span class="s2"&gt;"body"&lt;/span&gt;:&lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;hello world&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also run it in a way that will start a local web server, and you will be able to see the results in the browser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sam &lt;span class="nb"&gt;local &lt;/span&gt;start-api
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once you do that, it will create a local web server and present you with a local URL that you can visit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;Mounting HelloWorldFunction at http://127.0.0.1:3000/hello &lt;span class="o"&gt;[&lt;/span&gt;GET]
You can now browse to the above endpoints to invoke your functions. You &lt;span class="k"&gt;do &lt;/span&gt;not need to restart/reload SAM CLI &lt;span class="k"&gt;while &lt;/span&gt;working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI &lt;span class="k"&gt;if &lt;/span&gt;you update your AWS SAM template
2020-04-12 13:45:29  &lt;span class="k"&gt;*&lt;/span&gt; Running on http://127.0.0.1:3000/ &lt;span class="o"&gt;(&lt;/span&gt;Press CTRL+C to quit&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you want to cleanup the Docker images you can first list them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then delete the one that was created, which in my case is &lt;em&gt;lambci/lambda:python3.8&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;docker rmi lambci/lambda:python3.7
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There are many interesting things you can do using AWS SAM and this was just a short intro, so go out there and explore.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>sam</category>
      <category>python</category>
      <category>serverless</category>
    </item>
    <item>
      <title>How to install Jenkins on Ubuntu 18.04 in VirtualBox</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 05 Apr 2020 20:58:55 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-install-jenkins-on-ubuntu-18-04-in-virtualbox-4e54</link>
      <guid>https://dev.to/razcodes/how-to-install-jenkins-on-ubuntu-18-04-in-virtualbox-4e54</guid>
      <description>&lt;p&gt;This article was first published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following will show you how to install Jenkins on &lt;em&gt;Ubuntu Server 18.04&lt;/em&gt; that you will get up and running in &lt;em&gt;VirtualBox&lt;/em&gt; on your machine. I wrote this using a mac, but it should be the same on other operating systems.&lt;/p&gt;

&lt;p&gt;VirtualBox is a virtualization tool that allows you to create multiple virtual machines and have them run on your computer. You can download it and install it directly from their &lt;a href="https://www.virtualbox.org/"&gt;website&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing Ubuntu Install
&lt;/h2&gt;

&lt;p&gt;Once you have that up and running, go and download the ISO for &lt;a href="https://ubuntu.com/download/server"&gt;Ubuntu Server&lt;/a&gt;. For this demo I used version 18.04 LTS.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In VirtualBox, click on &lt;strong&gt;New&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Fill in the name (ex: Ubuntu - Jenkins), type (Linux), and version (Ubuntu 64-bit), then click &lt;strong&gt;Continue&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;For memory, I went with 2048 MB&lt;/li&gt;
&lt;li&gt;Create a virtual hard disk now&lt;/li&gt;
&lt;li&gt;Chose VDI&lt;/li&gt;
&lt;li&gt;Dynamically allocated&lt;/li&gt;
&lt;li&gt;I gave it 16GB of space&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the new machine created and selected, right click and chose &lt;strong&gt;Settings&lt;/strong&gt;, then click on &lt;strong&gt;Storage&lt;/strong&gt;. Select the &lt;em&gt;Empty&lt;/em&gt; option under the IDE controller and then on the right side of the interface click on the disk icon, which will allow you to point it to the ISO you downloaded.&lt;/p&gt;

&lt;p&gt;Go to the &lt;em&gt;Network&lt;/em&gt; tab, and select &lt;strong&gt;Bridged Adapter&lt;/strong&gt;. I like to use this option because it gives the new machine an IP address on the network, instead of just a local one. Click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now you can start the new Virtual machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Ubuntu
&lt;/h2&gt;

&lt;p&gt;Once the installation starts, you can move around using the &lt;em&gt;tab&lt;/em&gt; key or arrow keys. I mostly left everything as default, unless noted otherwise.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;select your language&lt;/li&gt;
&lt;li&gt;keyboard layout and variant&lt;/li&gt;
&lt;li&gt;network&lt;/li&gt;
&lt;li&gt;proxy&lt;/li&gt;
&lt;li&gt;mirror&lt;/li&gt;
&lt;li&gt;Use An Entire Disk&lt;/li&gt;
&lt;li&gt;select the disk&lt;/li&gt;
&lt;li&gt;Done&lt;/li&gt;
&lt;li&gt;Continue&lt;/li&gt;
&lt;li&gt;Fill in your name, desired server name, username and password&lt;/li&gt;
&lt;li&gt;press space to Install OpenSSH server (optional)&lt;/li&gt;
&lt;li&gt;Done&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the installation is complete, select &lt;strong&gt;Reboot&lt;/strong&gt;, then press &lt;strong&gt;Enter&lt;/strong&gt; when asked to remove the install media.&lt;/p&gt;

&lt;p&gt;You can login, using the credentials you setup earlier. First, you should apply all the available patches to your new system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt upgrade
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing Jenkins
&lt;/h2&gt;

&lt;p&gt;In order for Jenkins to work we will need to install Java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; openjdk-8-jre
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we will add the Jenkins key to our system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-O&lt;/span&gt; - https://pkg.jenkins.io/debian-stable/jenkins.io.key | &lt;span class="nb"&gt;sudo &lt;/span&gt;apt key add -
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add source packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'echo deb https://pkg.jenkins.io/debian-stable binary/ &amp;gt; /etc/apt/sources.list.d/jenkins.list'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can run another update and install Jenkins&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;jenkins
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now, just to make sure that Jenkins will restart when the system is rebooted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;jenkins
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Final setup
&lt;/h2&gt;

&lt;p&gt;You can now get the IP of your new system using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;ifconfig | &lt;span class="nb"&gt;grep &lt;/span&gt;inet
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can take your ip address and add :8080 at the end of it and paste it in the browser. That will bring up the Jenkins setup (ex: 192.168.1.49:8080)&lt;/p&gt;

&lt;p&gt;To pass this first screen you will need the secret key that was created during the install, so back on the server you can get that key like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cat&lt;/span&gt; /var/lib/jenkins/secrets/initialAdminPassword
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;take the output of that key and put it in the browser &lt;/li&gt;
&lt;li&gt;chose if you want to install the default plugins or none&lt;/li&gt;
&lt;li&gt;fill in your desired username, password and email for Jenkins&lt;/li&gt;
&lt;li&gt;take note of your new URL&lt;/li&gt;
&lt;li&gt;start using Jenkins&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s all folks. You should have a brand new VM Ubuntu Server running Jenkins.&lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>ubuntu</category>
      <category>devops</category>
      <category>virtualbox</category>
    </item>
    <item>
      <title>How to scan your AWS account for old access keys using python</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 29 Mar 2020 15:59:50 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-scan-your-aws-account-for-old-access-keys-using-python-21kk</link>
      <guid>https://dev.to/razcodes/how-to-scan-your-aws-account-for-old-access-keys-using-python-21kk</guid>
      <description>&lt;p&gt;This article was first published on &lt;a href="https://razcodes.dev"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In AWS, control 1.3 of the &lt;a href="https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-cis-controls.html"&gt;CIS AWS Foundations&lt;/a&gt; talks about making sure that keys that are older than 90 days are disabled. You can check this manually of course using the AWS console as explained in the documentation or you can write a script that does those checks for you with python.&lt;/p&gt;

&lt;p&gt;Using the terminal, in your projects folder create a new directory for this experiment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;iam-key-scanner &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;iam-key-scanner
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I like having virtual environments for all my projects, so I will create a new one and activate it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source&lt;/span&gt; ./venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You will need to install 2 packages to follow along. One is of course boto3 and the other one is python-dotenv for storing the AWS keys used to to the scan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;boto3 python-dotenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create a .env file for storing the AWS credentials. If later you decide to convert this into a lambda, you would of course not need this and you would create a role, but for running it from the computer this approach is a good option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; .env
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Edit the .env file in your favorite editor and add the following 2 lines with your credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-access-key-id
&lt;span class="nv"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-secret-access-key
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First thing that we have to do is to generate the report and then after it's generated we can read it and take action. To keep this simple I will break it into the two parts, however they can be part of the same script when you are ready for production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating the report
&lt;/h2&gt;

&lt;p&gt;Here is the script that will generate the report.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;generate-report.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dotenv&lt;/span&gt;

&lt;span class="n"&gt;load_dotenv&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'AWS_ACCESS_KEY_ID'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'AWS_SECRET_ACCESS_KEY'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;'iam'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;generate_credential_report&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now run it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;generate&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The report generation is pretty fast, but if you want to wait for it just look at the response. When the &lt;em&gt;State&lt;/em&gt; is 'COMPLETE', the report is ready.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;print&lt;span class="o"&gt;(&lt;/span&gt;response[&lt;span class="s1"&gt;'State'&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Parsing the report
&lt;/h2&gt;

&lt;p&gt;For parsing the report I decided to use &lt;em&gt;namedtuple&lt;/em&gt; so I can access the data more easily.&lt;/p&gt;

&lt;p&gt;I am using &lt;em&gt;timedelta&lt;/em&gt;, so I can calculate the age of a user key. You will see that there are two user keys for each user so we need to make sure we look at both. I am also declaring a variable called &lt;em&gt;format&lt;/em&gt; that I am using together with &lt;em&gt;strptime&lt;/em&gt; to get the returned date as I want it.&lt;/p&gt;

&lt;p&gt;This script will just print out the users, but you can easily create another function that you can call to disable the expired key or do perform key rotation. Also note that the script will show you the users with keys older than 90 days even if the key is inactive. You can add an extra check if you would like to only show the ones with active keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;parse-user-report.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dotenv&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;namedtuple&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;

&lt;span class="n"&gt;retentionDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'%Y-%m-%d'&lt;/span&gt;

&lt;span class="n"&gt;load_dotenv&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;namedtuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'User'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'user arn user_creation_time password_enabled password_last_used password_last_changed password_next_rotation mfa_active access_key_1_active access_key_1_last_rotated access_key_1_last_used_date access_key_1_last_used_region access_key_1_last_used_service access_key_2_active access_key_2_last_rotated access_key_2_last_used_date access_key_2_last_used_region access_key_2_last_used_service cert_1_active cert_1_last_rotated cert_2_active cert_2_last_rotated'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'AWS_ACCESS_KEY_ID'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'AWS_SECRET_ACCESS_KEY'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;'iam'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_credential_report&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Content'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'utf-8'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;','&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:]]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;access_key_1_last_rotated&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;'N/A'&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strptime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;access_key_1_last_rotated&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;retentionDate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;access_key_2_last_rotated&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;'N/A'&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strptime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;access_key_2_last_rotated&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;retentionDate&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Please let me know if you have any questions or if you would have done something differently.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>python</category>
      <category>security</category>
      <category>iam</category>
    </item>
    <item>
      <title>How to host a static website with AWS S3 and SSL using CLoudFront</title>
      <dc:creator>Raz</dc:creator>
      <pubDate>Sun, 22 Mar 2020 17:40:01 +0000</pubDate>
      <link>https://dev.to/razcodes/how-to-host-a-static-website-with-aws-s3-and-ssl-using-cloudfront-3e37</link>
      <guid>https://dev.to/razcodes/how-to-host-a-static-website-with-aws-s3-and-ssl-using-cloudfront-3e37</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HscxxKdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/09.S3Hosting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HscxxKdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/09.S3Hosting.png" alt="Map"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This article was first published on &lt;a href="https://razcodes.dev/"&gt;razcodes.dev&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow this article, you will need to have an AWS account. You can create one &lt;a href="https://aws.amazon.com/free"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note that while creating an account with AWS you are eligible for the free tier for your first year, some of the setup will not be free. It is always a good idea to setup a billing alarm first thing after you create your account, and you can do so by following &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You will also need to have a domain name. If you don't, you can register one using a registrar like &lt;a href="https://domains.google.com"&gt;Google Domains&lt;/a&gt;, or another one of your choice. You can also register your domain directly with AWS using Route53 once you login. I like having the domain name in a different place, just because I am not 100% sure I will stay with this hosting solution forever, so I feel this gives me the flexibility to move around and experiment easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up S3
&lt;/h2&gt;

&lt;p&gt;S3 is the AWS file system where the files for the website will be uploaded. We will be creating 2 buckets here, one for the root domain (getjambalaya.com) and one for the www subdomain (&lt;a href="http://www.getjambalaya.com"&gt;www.getjambalaya.com&lt;/a&gt;). The root domain bucket will just be forwarded to the main www one where we will be uploading all the files.&lt;/p&gt;

&lt;p&gt;Go to your AWS console and then go to S3. Start by creating the first bucket. This bucket will have to be the name of your domain. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OlLTaZx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/01.domain1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OlLTaZx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/01.domain1.png" alt="naked domain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next create the www domain bucket, this time deselecting  &lt;em&gt;Block all public access&lt;/em&gt;  and acknowledging the choice. We are doing this, since this bucket will be made public.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N7v7sR4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/02.domain2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N7v7sR4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/02.domain2.png" alt="www domain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Still in S3, click on the initial bucket, go under &lt;em&gt;Properties&lt;/em&gt; and under &lt;em&gt;Static website hosting&lt;/em&gt;, set it up so it redirects to your www domain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--12BIEPSP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/03.redirect.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--12BIEPSP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/03.redirect.png" alt="redirect domain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to your www bucket, under &lt;em&gt;Properties&lt;/em&gt; -&amp;gt; &lt;em&gt;Static website hosting&lt;/em&gt;, and &lt;em&gt;Use this bucket to host a website&lt;/em&gt;. Also put index.html as the index document.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6RiZRo5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/04.domainHosting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6RiZRo5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/04.domainHosting.png" alt="Domain Hosting"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this same bucket, under &lt;em&gt;Permissions&lt;/em&gt; -&amp;gt; &lt;em&gt;Bucket Policy&lt;/em&gt;, you can add the following policy, making sure you replace my domain name with yours. This will make all the objects in the bucket accessible to the outside world.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::www.getjambalaya.com/*"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now go under Overview and upload all the files of your website into your bucket. For this example I will just upload an index.html file that I have prepared.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the domain
&lt;/h2&gt;

&lt;p&gt;In AWS go to &lt;em&gt;Route 53&lt;/em&gt; and under &lt;em&gt;Hosted zones&lt;/em&gt; click &lt;strong&gt;Create Hosted Zone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qKNDXf12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/00.hostedZone.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qKNDXf12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/00.hostedZone.png" alt="Hosted Zone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the zone has been created, take all 4 of your NS domains provided and make sure you update your DNS setting with your registrar. For Google Domains I went under my domain -&amp;gt; DNS -&amp;gt; Name Servers -&amp;gt; Use custom name servers. Should be the same with others as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E16QW9fn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/05.dns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E16QW9fn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/05.dns.png" alt="DNS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These might take a while to update as such is the way with DNS settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the certificate
&lt;/h2&gt;

&lt;p&gt;In AWS, &lt;em&gt;Services&lt;/em&gt; -&amp;gt; &lt;em&gt;Certificate Manager&lt;/em&gt; -&amp;gt; &lt;strong&gt;Request a certificate&lt;/strong&gt; -&amp;gt; &lt;em&gt;Request a public certificate&lt;/em&gt;. Put in your domain name (&lt;a href="http://www.getjambalaya.com"&gt;www.getjambalaya.com&lt;/a&gt;). Select DNS validation. Add Tags if you wish. &lt;strong&gt;Confirm and Request&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Because we already added the domain to Route53, on the confirmation screen, you can expand by clicking on your domain name and click on &lt;em&gt;Create record in Route53&lt;/em&gt; and then &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now you will just have to wait until AWS validates your certificate based on the DNS settings. It only took 2 minutes for me, but might take longer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the CloudFront distribution
&lt;/h2&gt;

&lt;p&gt;In AWS, &lt;em&gt;Services&lt;/em&gt; -&amp;gt; &lt;em&gt;CloudFront&lt;/em&gt; -&amp;gt; &lt;strong&gt;Create Distribution&lt;/strong&gt; -&amp;gt; &lt;em&gt;Web&lt;/em&gt; -&amp;gt; &lt;strong&gt;Get Started&lt;/strong&gt;. There will be a lot of options on this screen, but only a few will be changed for this exercise. &lt;/p&gt;

&lt;p&gt;Under &lt;em&gt;Origin Domain Name&lt;/em&gt; select your www s3 bucket. Under &lt;em&gt;Viewer Protocol Policy&lt;/em&gt; chose &lt;em&gt;Redirect HTTP to HTTPS&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qtvgScY4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/06.cloudFront1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qtvgScY4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/06.cloudFront1.png" alt="Cloud Front 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under &lt;em&gt;Alternate Domain Names&lt;/em&gt; put in your www domain name (&lt;a href="http://www.getjambalaya.com"&gt;www.getjambalaya.com&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Under &lt;em&gt;SSL Certificate&lt;/em&gt; chose &lt;em&gt;Custom SSL Certificate &lt;/em&gt; and chose the one you just created above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Co2oBgt6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/07.cloudFront2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Co2oBgt6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/07.cloudFront2.png" alt="CloudFront2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last thing, under &lt;em&gt;Default Root Object&lt;/em&gt; put in index.html.&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt;. It will take a while for the distribution to be created so be patient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finishing the domain setup
&lt;/h2&gt;

&lt;p&gt;Now back to &lt;em&gt;Services&lt;/em&gt; -&amp;gt; &lt;em&gt;Route 53&lt;/em&gt; -&amp;gt; &lt;em&gt;Hosted Zones&lt;/em&gt; select your domain name. We will create 2 more record sets, one for each bucket we created above.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Create Record Set&lt;/em&gt; -&amp;gt; Alias and select as the Alias Target the s3 bucket you created first, then click &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bc30hTeT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/08.domainR1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bc30hTeT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dsc.cloud/blackpanda/08.domainR1.png" alt="DomainRS1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the second one, we will point it to the CloudFront distribution we created above, so make sure you wait until that finishes.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Create Record Set&lt;/em&gt;, add www to the name, select Yes for &lt;em&gt;Alias&lt;/em&gt; and in the &lt;em&gt;Alias Target&lt;/em&gt;, select your CloudFront distribution, then &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As with other DNS changes this might take a bit to update so if it does not work right away just be patient. It will.&lt;/p&gt;

&lt;p&gt;Congratulations, you can now visit your new website.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>s3</category>
      <category>hosting</category>
      <category>ssl</category>
    </item>
  </channel>
</rss>
