<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: ECV PH Tech Team</title>
    <description>The latest articles on Forem by ECV PH Tech Team (@ecvph-tech-team).</description>
    <link>https://forem.com/ecvph-tech-team</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%2Forganization%2Fprofile_image%2F8949%2F3f1fa7b5-07a1-4166-b5e5-599d5e3b212f.png</url>
      <title>Forem: ECV PH Tech Team</title>
      <link>https://forem.com/ecvph-tech-team</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ecvph-tech-team"/>
    <language>en</language>
    <item>
      <title>AWS Network Challenge 1: Deploy Web App to EC2 / Two-Tier VPC Architecture</title>
      <dc:creator>Raphael Jambalos</dc:creator>
      <pubDate>Sat, 25 May 2024 03:19:16 +0000</pubDate>
      <link>https://forem.com/ecvph-tech-team/aws-network-challenge-1-deploy-application-in-ec2-on-two-tier-vpc-architecture-135i</link>
      <guid>https://forem.com/ecvph-tech-team/aws-network-challenge-1-deploy-application-in-ec2-on-two-tier-vpc-architecture-135i</guid>
      <description>&lt;h2&gt;
  
  
  About the Challenge
&lt;/h2&gt;

&lt;p&gt;I manage the Service Delivery Team at eCloudValley Philippines, and one of the first things I teach them is to understand how AWS networks work. As cloud developers, we deploy our applications in Lambda and connect them with databases and other components inside our AWS VPC (virtual network in AWS). Because of this, it becomes imperative for them to know more about how VPCs work. They need to know how to navigate network issues they will encounter. &lt;/p&gt;

&lt;p&gt;In this challenge, we would deploy an application to 2 servers inside a virtual network in AWS. The network will have two tiers: private and public. Our result will be:&lt;/p&gt;

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

&lt;p&gt;Before we begin, here are a few helpful hints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is a series of challenges that get progressively harder. It also meant to state what to do and what you should have learned. This is NOT a step-by-step guide on how to do the challenges.&lt;/li&gt;
&lt;li&gt;I have added links to AWS documentation to help you get started with the challenges. &lt;/li&gt;
&lt;li&gt;I have added guide questions to test your knowledge. It's easy to follow documentation to make this all work. But what we are striving for is a true understanding of how these components work together for a secure, reliable, and working network.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  [A] Basic VPC Skeleton
&lt;/h2&gt;

&lt;p&gt;Let's build the backbones of our VPC network. You'll be creating:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/how-it-works.html" rel="noopener noreferrer"&gt;VPC&lt;/a&gt; (&lt;a href="-%20https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html#create-vpc-only"&gt;how&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;2 Private &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html" rel="noopener noreferrer"&gt;Subnets&lt;/a&gt; (deployed in separate Availability Zones, &lt;a href="(https://docs.aws.amazon.com/vpc/latest/userguide/create-subnets.html)"&gt;how&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;2 Public Subnets (deployed in separate Availability Zones)&lt;/li&gt;
&lt;li&gt;1 &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html" rel="noopener noreferrer"&gt;Internet Gateway&lt;/a&gt; (connected to the VPC we just created)&lt;/li&gt;
&lt;li&gt;1 NACL for both subnets (with a rule that allows all traffic)&lt;/li&gt;
&lt;li&gt;1 &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Route_Tables.html" rel="noopener noreferrer"&gt;Route Table&lt;/a&gt; (for Private Subnets, &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/WorkWithRouteTables.html" rel="noopener noreferrer"&gt;how&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;1 Route Table (for Public Subnets)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this exercise, you must be able to answer the following guide questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What makes a subnet private? What makes it public?&lt;/li&gt;
&lt;li&gt;What is an IPv4 CIDR block? What is the difference between /16, /20 and /24?&lt;/li&gt;
&lt;li&gt;Why do we deploy subnets in different availability zones?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Architecture Diagram for Exercise A:&lt;/strong&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  [B] Setting up the instances
&lt;/h2&gt;

&lt;p&gt;With the VPC backbone in place, let's add more network components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html" rel="noopener noreferrer"&gt;NAT Gateway&lt;/a&gt; (deployed in Public Subnet)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html" rel="noopener noreferrer"&gt;Set up&lt;/a&gt; for you to deploy an EC2 instance &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html" rel="noopener noreferrer"&gt;EC2 instance&lt;/a&gt; (deployed in Public Subnet) - &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html" rel="noopener noreferrer"&gt;Getting Started&lt;/a&gt; - &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-best-practices.html" rel="noopener noreferrer"&gt;Best Practices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;EC2 instance (deployed in Private Subnet)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html" rel="noopener noreferrer"&gt;Security Group&lt;/a&gt; that allows all traffic from port 22&lt;/li&gt;
&lt;li&gt;Associate the security group to both EC2 instances&lt;/li&gt;
&lt;li&gt;Private Route Table connected to NAT Gateway&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are a few guide questions to answer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DEMO: Be able to enter the CLI of the EC2 instance in the public subnet via SSH. Once inside, access the CLI of the EC2 instance in the private subnet.&lt;/li&gt;
&lt;li&gt;Why do we need a NAT Gateway? How does it operate?&lt;/li&gt;
&lt;li&gt;What is the difference between a NAT Gateway and an Internet Gateway?&lt;/li&gt;
&lt;li&gt;What is the difference between a security group and an NACL?&lt;/li&gt;
&lt;li&gt;Can a computer from the internet access the EC2 instance inside the private subnet? Why or why not?&lt;/li&gt;
&lt;li&gt;What is the difference between a NAT gateway and a NAT instance? When would you use a NAT instance? NAT gateway?&lt;/li&gt;
&lt;li&gt;What happens if you don't assign a public IP Address to an EC2 instance?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Architecture Diagram for Exercise B:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;What we achieved&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We created our private network in the Cloud! We also created two EC2 instances, one in the private subnet and another in the public subnet. &lt;/p&gt;

&lt;h2&gt;
  
  
  [C] Setting up NGINX and load balancing
&lt;/h2&gt;

&lt;p&gt;We're getting close:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EC2 instance (deployed in Private Subnet 1)&lt;/li&gt;
&lt;li&gt;EC2 instance (deployed in Private Subnet 2)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7" rel="noopener noreferrer"&gt;Install Nginx on both&lt;/a&gt;. Modify &lt;code&gt;/usr/share/nginx/html/index.html&lt;/code&gt; to add "this is server one" for the 1st EC2 and "this is server two" for the second one.&lt;/li&gt;
&lt;li&gt;Create an &lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html" rel="noopener noreferrer"&gt;application load balancer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Create a &lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-listener.html" rel="noopener noreferrer"&gt;listener&lt;/a&gt; to receive HTTP traffic&lt;/li&gt;
&lt;li&gt;Create a &lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html" rel="noopener noreferrer"&gt;target group&lt;/a&gt; that includes both EC2 instances as instance targets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are a few guide questions to answer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DEMO: Once the resources have been created, get the URL from the application load balancer and put it in your browser. It should alternate displaying "this is server one" and "this is server two". This proves that the ALB is alternating sending traffic between the first and second EC2 instances.&lt;/li&gt;
&lt;li&gt;What is the difference between a NAT Gateway and an Application Load Balancer?&lt;/li&gt;
&lt;li&gt;Why put the EC2 instances in separate private subnets?&lt;/li&gt;
&lt;li&gt;Why put the EC2 instances in the private subnet instead of being exposed directly?&lt;/li&gt;
&lt;li&gt;Why add an application load balancer?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Architecture Diagram for Exercise C:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;The result looks like this:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;What we achieved&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With Activity A-C, you have deployed your first VPC and have successfully deployed a simple app using a two-tier architecture. That’s honestly very close to how we deploy secure applications on the modern web.&lt;/p&gt;

&lt;p&gt;There is one thing though. The application you accessed looked like something like this when typed in the browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jamby-alb-1962899873.ap-southeast-2.elb.amazonaws.com/" rel="noopener noreferrer"&gt;http://jamby-alb-1962899873.ap-southeast-2.elb.amazonaws.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two things come to mind when I see this:&lt;/p&gt;

&lt;p&gt;First, the website is deployed on HTTP, not HTTPS, which leaves our end users insecure. As your end user browses your website, the data you send and receive goes across the internet unencrypted. The internet is made of thousands (or maybe millions) of routers connecting everyone in one big interconnected web. From your end user’s Macbook to your EC2 instance, there may be as many as 100 routers in between. if you leave your traffic as HTTP, any one of those 100 routers can see whatever you are sending between one another.&lt;/p&gt;

&lt;p&gt;Second, as an e-commerce, I’d like to have a decent website name that my end users can easily remember. Something like:&lt;/p&gt;

&lt;p&gt;jambyiscool.ecvphdevs.com&lt;/p&gt;

&lt;p&gt;In exercise D, we will do just that.&lt;/p&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  [D] Securing setup with HTTPS
&lt;/h2&gt;

&lt;p&gt;Let's take it a step further. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Buy a domain in GoDaddy and associate it with Route 53 (if you haven't). If you have access to an existing Domain Name, no need to do this step.&lt;/li&gt;
&lt;li&gt;Create a &lt;a href="https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html" rel="noopener noreferrer"&gt;public certificate&lt;/a&gt; with &lt;a href="https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html" rel="noopener noreferrer"&gt;AWS Certificate Manager&lt;/a&gt;. You may have to create DNS records in your domain manager.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://repost.aws/knowledge-center/associate-acm-certificate-alb-nlb" rel="noopener noreferrer"&gt;Associate the certificate with the ALB created earlier&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-creating.html" rel="noopener noreferrer"&gt;Create a route 53 record&lt;/a&gt; for "jambyiscool.yourdomain.com" and point it to the load balancer you just created. If your domain manager is not Route 53, feel free to create the record in your domain manager.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Architecture Diagram for Exercise D:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Here is the end result:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;Congratulations on completing this exercise! You know have a full view on how VPC works, and have deployed your first application on a best practice version of a private network in AWS.&lt;/p&gt;

&lt;p&gt;On the next challenge, we will be doing VPC peering, EC2 auto scaling, VPC endpoints and CI/CD. Stay tuned!&lt;/p&gt;

&lt;h2&gt;
  
  
  Interested about joining ECV Philippines?
&lt;/h2&gt;

&lt;p&gt;Send us your CV via email to &lt;a href="mailto:ph.hr@ecloudvalley.com"&gt;ph.hr@ecloudvalley.com&lt;/a&gt;:&lt;/p&gt;

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

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@dulhiier?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Nastya Dulhiier&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/lighted-city-at-night-aerial-photo-OKOOGO578eo?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>webdev</category>
      <category>network</category>
    </item>
    <item>
      <title>How to Hack (and secure) Serverless Applications</title>
      <dc:creator>Raphael Jambalos</dc:creator>
      <pubDate>Thu, 28 Mar 2024 06:49:00 +0000</pubDate>
      <link>https://forem.com/ecvph-tech-team/how-to-hack-and-secure-serverless-applications-2226</link>
      <guid>https://forem.com/ecvph-tech-team/how-to-hack-and-secure-serverless-applications-2226</guid>
      <description>&lt;p&gt;At eCloudValley Philippines, we prefer developing web backends as serverless applications. We just push the code to AWS and they worry about the infrastructure. We don't have to think about provisioning, patching, scaling and securing it. That's all AWS. In terms of security, since even us don't have access to the infrastructure, we don't have to worry about it. We pay AWS to worry about that for us. But what we do have access to is the code. And that's one major attack vector we have to secure. And in ECVPH, we take that very seriously. &lt;/p&gt;

&lt;p&gt;In this article, we will take a deeper look at how Serverless workloads get hacked, and what you can do about it. &lt;/p&gt;

&lt;p&gt;Here are the 6 common types of attacks on Serverless applications&lt;/p&gt;

&lt;h2&gt;
  
  
  [1] Denial of Service
&lt;/h2&gt;

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

&lt;p&gt;You'd think Serverless applications don't get DDoS attacks. Yes, they can scale fast. But the network components attached to them don't often scale at the same rate as them. We've seen Lambda functions use an RDS database, or is connected to an API that is deployed on a traditional EC2 setup.  Your lambda functions will scale to meet the traffic, but they will rain down traffic into these weaker downstream dependencies.&lt;/p&gt;

&lt;p&gt;That's why it's often a good idea to do event-driven architecture. Instead of directly writing into the database or directly calling the legacy system, the Lambda function queues&lt;/p&gt;

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

&lt;p&gt;It's not only infrastructure that can cause denial of service. Sometimes, there are vulnerabilities in your packages that can cause this. For example, &lt;a href="https://security.snyk.io/vuln/SNYK-PYTHON-ETHABI-6394102"&gt;this Python package for etherium&lt;/a&gt; can cause resource exhaustion when a specific payload is added to it. With just a few requests, the package causes a malfunction that causes it to hog all the CPU and RAM of the device. This exhausts the resources of the server, causing it to go down.&lt;/p&gt;

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

&lt;p&gt;To learn more about how to survive a DDoS attack, check out my &lt;a href="https://dev.to/awscommunity-asean/devs-guide-to-surviving-ddos-attacks-in-your-api-56ke"&gt;blog post&lt;/a&gt; about how we survived a 2M requests per min attack.&lt;/p&gt;

&lt;h2&gt;
  
  
  [2] Denial of Wallet
&lt;/h2&gt;

&lt;p&gt;But suppose that somehow your entire setup is serverless. You're using AWS Lambda for your compute, DynamoDB for your backend, and S3 for all your files. The attacker can just keep attacking you and AWS will be able to keep your website up. But since these services are pay-per-use, you'd just end up racking up higher AWS charges. And so long as they can sustain their attack, they can bankrupt your company to the ground.&lt;/p&gt;

&lt;p&gt;To protect against both DoS and DoW attacks, it is best to put into place some kind of rate limiting. AWS WAF does this by allowing you to limit request per second for each IP address. This makes these attacks harder, but not impossible, especially if they have thousands of IP addresses on their disposal.&lt;/p&gt;

&lt;h2&gt;
  
  
  [3] Remote Code Execution
&lt;/h2&gt;

&lt;p&gt;While the most common attacks are volumetric in nature, some just need a few API calls and they've compromised your system. The most common of which is remote code execution. It is when hackers are able to manipulate the payload so that they can execute custom code in your application.&lt;/p&gt;

&lt;p&gt;Probably the most insecure code in Python is this snippet below. It allows you to evaluate a string and execute it as a Python code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;request_body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;2 ** 2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_body&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;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine the possibilities. When you are using this code, an attacker can just modify the request body to a more sinister one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;request_body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;run_sql(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;drop database&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_body&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;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much of the programming world does not use this code anymore. But vulnerabilities found in old packages (that you may still be using) may leave you exposed to this vulnerability. Here's an example from an outdated version of &lt;a href="https://security.snyk.io/vuln/SNYK-PYTHON-ASTROPY-6457316"&gt;Astropy&lt;/a&gt;.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  [4] Malicious Packages
&lt;/h2&gt;

&lt;p&gt;The dawn of open-source software has allowed developers to share code much freely. It has accelerated development since we no longer have to write code from the ground up. We can just compose libraries together to make our application. But that openness also comes at a price. &lt;/p&gt;

&lt;p&gt;There are malicious libraries out there that exist to mimic legitimate software. Once added to your project, these libraries open backdoors for hackers to remotely execute code on your server. Like this &lt;a href="https://security.snyk.io/vuln/SNYK-PYTHON-MJPOYTWNGDDH-6483334"&gt;"python package"&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Malicious code don't exclusively come from packages. It can also come from Lambda layers. An inconvenience with Lambda is that when there are libraries with OS-specific dependencies, it is more difficult to upload them to Lambda. You have to compile the library using an OS that is similar to Lambda's OS. An example of this is psycopg2 (an internal library required to make Postgresql work in Python). &lt;/p&gt;

&lt;p&gt;The most convenient way to fix this is just to use a Lambda Layer that somebody else already created. Like this &lt;a href="https://api.klayers.cloud/api/v2/p3.9/layers/latest/ap-southeast-1/html"&gt;Github page of Keith&lt;/a&gt;. While he looks generally reputable, nothing is stopping Keith from inserting malicious code to any one of his public Lambda layers. And once you use the code inside the Lambda layer, he may be able to remotely run code in your lambda. A better fix is to build the lambda layer yourself, even if it takes awhile. In Python, &lt;a href="https://repost.aws/knowledge-center/lambda-python-package-compatible"&gt;Pip added&lt;/a&gt; the &lt;code&gt;--platform&lt;/code&gt; command where you can specific the platform when you install your library.&lt;/p&gt;

&lt;h2&gt;
  
  
  [5] API is too open
&lt;/h2&gt;

&lt;p&gt;The easiest way to hack an API is when it is open to the public. &lt;/p&gt;

&lt;p&gt;What we do is we often pair it with Cognito. The user logs in to the frontend, and Cognito issues a set of tokens that the backend will use to ensure that the user is who he says he is. The token expires every hour and needs to be renewed. During each renewal, we can validate if the session is still valid. &lt;/p&gt;

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

&lt;p&gt;But how about APIs that are only used by other APIs? They shouldn't be open to the public in the first place. They should, at the minimum, be secured by an expiring API token that only the authorized system has access to. An even better approach is to determine these APIs and ensure they can only be accessed privately, inside the network. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  [6] Privilege Escalation
&lt;/h2&gt;

&lt;p&gt;ECS tasks and Lambda functions rely on IAM Roles to access AWS services. Those who leave this role with an admin privilege can leave their account open to hacking.&lt;/p&gt;

&lt;p&gt;If there is a remote code execution vulnerability, hackers can use that to discover the IAM role inside the Lambda / ECS task. Then, they can use this role to create an IAM user with elevated privileges, which they can use to gain access to your AWS accounts. &lt;/p&gt;

&lt;p&gt;But more often than not, this vulnerability is an inside job. For example, we have given the developer limited rights to our AWS account. They can only push code to their CodeCommit repository. But the execution role of the Lambda function is set to Administrator Access. The developer can change the code that is pushed to the CI/CD to include instructions to create an IAM user for him with elevated permissions. &lt;/p&gt;

&lt;p&gt;Another form of privilege escalation is modifying the CloudFormation code that comes with the serverless application. Malicious developers can directly add instructions to create an elevated user there.&lt;/p&gt;

&lt;h2&gt;
  
  
  How about you? What are other ways to "hack" into serverless applications?
&lt;/h2&gt;

&lt;p&gt;Let us know in the comments!&lt;/p&gt;

&lt;p&gt;Also check out my &lt;a href="https://dev.to/aws-builders/top-10-security-best-practices-we-learned-the-hard-way-3f55"&gt;other blog post&lt;/a&gt; on security best practices we learned the hard way.&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@maxwbender?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Max Bender&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/person-standing-near-led-sign-XIVDN9cxOVc?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>webdev</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
