<?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: Asrin</title>
    <description>The latest articles on Forem by Asrin (@az_codez).</description>
    <link>https://forem.com/az_codez</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%2F322544%2F8eae2c27-cc69-422a-bb78-c26c8a834dd7.jpg</url>
      <title>Forem: Asrin</title>
      <link>https://forem.com/az_codez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/az_codez"/>
    <language>en</language>
    <item>
      <title>Event driven architectures using AWS with example</title>
      <dc:creator>Asrin</dc:creator>
      <pubDate>Sun, 29 Jan 2023 15:29:05 +0000</pubDate>
      <link>https://forem.com/aws-builders/event-driven-architectures-using-aws-with-example-3d2d</link>
      <guid>https://forem.com/aws-builders/event-driven-architectures-using-aws-with-example-3d2d</guid>
      <description>&lt;p&gt;Event-driven architectures are becoming increasingly popular in modern software development, and Amazon Web Services (AWS) provides several tools to implement this style of architecture. In this blog, we will discuss what event-driven architectures are, why they are useful, and how to implement them in AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an event-driven architecture?
&lt;/h2&gt;

&lt;p&gt;An event-driven architecture is a way of designing software systems in which events trigger specific actions. This means that different parts of the system can communicate with each other by sending and receiving events, rather than directly invoking each other's methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use event-driven architectures?
&lt;/h2&gt;

&lt;p&gt;Event-driven architectures provide several benefits over traditional architectures:&lt;/p&gt;

&lt;p&gt;Loose coupling: Event-driven architectures promote loose coupling between components, making it easier to change or replace parts of the system without affecting the rest of the system.&lt;br&gt;
Scalability: Event-driven architectures are inherently scalable, as it's easy to add new components to respond to events without affecting existing components.&lt;br&gt;
Real-time processing: Event-driven architectures allow for real-time processing of events, making it possible to respond to events as soon as they occur.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to implement event-driven architectures in AWS?
&lt;/h2&gt;

&lt;p&gt;AWS provides several tools that make it easy to implement event-driven architectures:&lt;/p&gt;

&lt;p&gt;Amazon SNS (Simple Notification Service): SNS is a publish/subscribe messaging service that allows you to send messages to multiple recipients at once. You can use SNS to send events from one part of your system to another, and have multiple components subscribe to these events.&lt;/p&gt;

&lt;p&gt;Amazon SQS (Simple Queue Service): SQS is a managed message queue service that provides reliable, scalable, and efficient message delivery. You can use SQS to queue events for processing, allowing you to decouple the parts of your system that produce events from the parts that process them.&lt;/p&gt;

&lt;p&gt;AWS Lambda: Lambda is a serverless computing service that allows you to run code without having to manage servers. You can use Lambda to respond to events by triggering Lambda functions that perform specific actions in response to events.&lt;/p&gt;
&lt;h2&gt;
  
  
  Real world example
&lt;/h2&gt;

&lt;p&gt;Here is a real-world example of an event-driven architecture using Terraform and AWS:&lt;/p&gt;

&lt;p&gt;Suppose we have an e-commerce website that sells products. When a customer places an order, we want to send an email to the customer with a confirmation of the order, and we also want to update the inventory of the product that was ordered.&lt;/p&gt;

&lt;p&gt;To implement this, we can use the following components:&lt;/p&gt;

&lt;p&gt;Amazon S3: To store the Terraform code and the inventory data.&lt;/p&gt;

&lt;p&gt;AWS Lambda: To run the code that sends the email to the customer and updates the inventory. We will use two separate Lambda functions for these tasks.&lt;/p&gt;

&lt;p&gt;Amazon SNS: To send the events when an order is placed and when the inventory is updated.&lt;/p&gt;

&lt;p&gt;Terraform: To automate the creation of the above components.&lt;/p&gt;

&lt;p&gt;Here is the Terraform code for creating the SNS topic for order placement events:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_sns_topic" "order_placed" {
  name = "order_placed"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we create the Lambda function that sends the email to the customer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_lambda_function" "send_email" {
  filename = "send_email.zip"
  function_name = "send_email"
  role = "${aws_iam_role.lambda_exec.arn}"
  handler = "index.handler"
  runtime = "python3.8"
  timeout = 30
  environment = {
    variables = {
      SENDER = "${var.sender}"
      RECIPIENT = "${var.recipient}"
    }
  }
  events = [
    {
      sns = "${aws_sns_topic.order_placed.arn}"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally, the Terraform code for the Lambda function that updates the inventory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_lambda_function" "update_inventory" {
  filename = "update_inventory.zip"
  function_name = "update_inventory"
  role = "${aws_iam_role.lambda_exec.arn}"
  handler = "index.handler"
  runtime = "python3.8"
  timeout = 30
  environment = {
    variables = {
      INVENTORY_BUCKET = "${var.inventory_bucket}"
    }
  }
  events = [
    {
      sns = "${aws_sns_topic.order_placed.arn}"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, when a customer places an order, an SNS event is sent to the order_placed topic. This event triggers both the send_email and update_inventory Lambda functions, which perform the actions of sending an email to the customer and updating the inventory, respectively.&lt;/p&gt;

&lt;p&gt;This is a simple example of how Terraform and AWS can be used to build an event-driven architecture. By using Terraform, you can automate the creation and deployment of these components, making it easier to manage and scale your architecture as your needs change over time.&lt;/p&gt;

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

&lt;p&gt;Event-driven architectures are a useful tool for designing modern software systems, and AWS provides several tools to make it easy to implement this style of architecture. By using tools such as SNS, SQS, and Lambda, you can build scalable, real-time systems that respond to events as soon as they occur.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was created with the help of AI&lt;/em&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Save EC2 costs by using a AWS Savings plan</title>
      <dc:creator>Asrin</dc:creator>
      <pubDate>Sun, 11 Sep 2022 11:11:45 +0000</pubDate>
      <link>https://forem.com/aws-builders/save-ec2-costs-by-using-a-aws-savings-plan-517l</link>
      <guid>https://forem.com/aws-builders/save-ec2-costs-by-using-a-aws-savings-plan-517l</guid>
      <description>&lt;h1&gt;
  
  
  Save EC2 costs by using a AWS Savings plan
&lt;/h1&gt;

&lt;p&gt;This is a real-life case of how I save 38% of EC2 micro cost using  &lt;a href="https://aws.amazon.com/savingsplans/"&gt;EC2 Instance Savings Plan&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I have an EC2 micro running at the moment which is always running a Barbershop website. There is no plans to take down or switch infrastructure within the next year so I thought I would save some costs by pre purchasing the EC2 using  &lt;a href="https://aws.amazon.com/savingsplans/"&gt;EC2 Savings plan&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Calculate savings
&lt;/h1&gt;

&lt;p&gt;First calculate how much you will save using savings using this  &lt;a href="https://aws.amazon.com/savingsplans/compute-pricing/"&gt;AWS Savings plan Calculator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I calculate my costs for an EC2 micro&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H6GWeunA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1050/1%2AJHdqJuLEU-N-0a5NDsLzwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H6GWeunA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1050/1%2AJHdqJuLEU-N-0a5NDsLzwg.png" alt="" width="880" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you see here it will cost me 0.0072 per hour.&lt;br&gt;&lt;br&gt;
For a month it will cost around $5.18 (0.0072 x 24 x 30 = 5.184)&lt;/p&gt;

&lt;p&gt;Check how much you pay currently for your EC2 in your Billing Dashboard by going to your AWS Billing Dashboard and selecting last month’s bill&lt;/p&gt;

&lt;p&gt;As you see below I pay $8.63 per month&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ebhvcjLn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1050/1%2AhrEkRnmqtInNXEE7yYRytw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ebhvcjLn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1050/1%2AhrEkRnmqtInNXEE7yYRytw.png" alt="" width="880" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I will save $3.45 per month ($8.63 — $5.18) which would be $41.40 per year. Quite decent for not doing much🤑&lt;/p&gt;

&lt;h1&gt;
  
  
  Configure a EC2 Savings plan
&lt;/h1&gt;

&lt;p&gt;Once you buy an EC2 savings plan it will automatically be applied to the EC2’s in your AWS account. You don’t need to do anything with your server it’s a billing configuration.  &lt;a href="https://aws.amazon.com/savingsplans/faq/"&gt;See for more information&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to your AWS Billing Dashboard &amp;gt; Savings Plan &amp;gt; Purchase subscription&lt;/p&gt;

&lt;p&gt;Configure your plan as per your  &lt;a href="https://aws.amazon.com/savingsplans/compute-pricing/"&gt;EC2 calculations you did above&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Term&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Select — 1 or 3 years (3 years more savings)&lt;/li&gt;
&lt;li&gt;  Region — Make sure to select same region your EC2 is in!&lt;/li&gt;
&lt;li&gt;  Instance family — Select same instance type that your EC2 is&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Purchase Commitment&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Copy the same value you got in your  &lt;a href="https://aws.amazon.com/savingsplans/compute-pricing/"&gt;EC2 calculator&lt;/a&gt;  (you could also pay more if you like)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vuzRJJgq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/771/1%2A6wEq1VLrwrU-ypialLWVbA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vuzRJJgq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/771/1%2A6wEq1VLrwrU-ypialLWVbA.png" alt="" width="514" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Payment option — select if you want to pay more upfront which would give you even more savings or leave it as no upfront.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Start Date&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  You can set a start date if you like but this is optional.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Double check again the region you are using and the type of EC2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add to cart&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was my EC2 micro configuration for a year&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--quanZYSF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1050/1%2AWa1N9TI-sYgMHZC2aquhSQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--quanZYSF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1050/1%2AWa1N9TI-sYgMHZC2aquhSQ.png" alt="" width="880" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submit order&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click inventory and your order will be in review&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Above is based on AWS August 2022 pricing&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps😁&lt;/p&gt;

&lt;p&gt;Feel free to comment with questions or feedback✌️&lt;/p&gt;

&lt;p&gt;Happy coding,&lt;/p&gt;

&lt;p&gt;Az 👨🏾‍💻&lt;/p&gt;

&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/"&gt;https://aws.amazon.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pixabay.com/images/id-2889046/"&gt;image&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackedit.io/app#"&gt;medium to markdown converter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cloud</category>
      <category>aws</category>
      <category>programming</category>
      <category>devops</category>
    </item>
    <item>
      <title>Create ACM certificate with DNS validation using Terraform</title>
      <dc:creator>Asrin</dc:creator>
      <pubDate>Sat, 27 Aug 2022 16:28:00 +0000</pubDate>
      <link>https://forem.com/aws-builders/create-acm-certificate-with-dns-validation-using-terraform-2adf</link>
      <guid>https://forem.com/aws-builders/create-acm-certificate-with-dns-validation-using-terraform-2adf</guid>
      <description>&lt;p&gt;This is how I created an HTTPS AWS Certificate (ACM) and validated it with my domain in AWSRoute53 using DNS validation, all using infrastructure as code tool Terraform.&lt;/p&gt;

&lt;p&gt;This is how I created an HTTPS AWS Certificate (ACM) and validated it with my domain in AWSRoute53 using DNS validation, all using infrastructure as code tool Terraform.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://aws.amazon.com/cli/"&gt;AWS CLI configured&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learn.hashicorp.com/tutorials/terraform/install-cli"&gt;Terraform&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://aws.amazon.com/route53/"&gt;R53 Domain&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs"&gt;AWS Terraform providers&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Add a variable for your domain
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variable "root_domain_name" {
  type    = string
  default = "helloworld.info"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Replace the above &lt;code&gt;helloworld.info&lt;/code&gt; with your domain&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Route53
&lt;/h2&gt;

&lt;p&gt;I had an imported route 53 already like so. See terraform docs for more info&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_route53_zone" "hello_world_zone" {
  name = var.root_domain_name
}
Create an ACM Certificate
resource "aws_acm_certificate" "hello_certificate" {
  domain_name       = var.root_domain_name
  validation_method = "DNS"
  lifecycle {
    create_before_destroy = true
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This creates a AWS ACM certificate for the domain name you set as variable&lt;/li&gt;
&lt;li&gt;Sets validation mode to DNS&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Add DNS records
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_route53_record" "hello_cert_dns" {
  allow_overwrite = true
  name =  tolist(aws_acm_certificate.hello_certificate.domain_validation_options)[0].resource_record_name
  records = [tolist(aws_acm_certificate.hello_certificate.domain_validation_options)[0].resource_record_value]
  type = tolist(aws_acm_certificate.hello_certificate.domain_validation_options)[0].resource_record_type
  zone_id = aws_route53_zone.hello_world_zone.zone_id
  ttl = 60
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This adds DNS records from the resource above and inputs them into your Route53 host zone. Similar way you would do this as if you did it manually&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Validate the certificcate
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_acm_certificate_validation" "hello_cert_validate" {
  certificate_arn = aws_acm_certificate.hello_certificate.arn
  validation_record_fqdns = [aws_route53_record.hello_cert_dns.fqdn]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This validates your ACM certificate with your domain name&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run Terraform
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform fmt
terraform validate
terraform plan
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check ACM
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In AWS Console &amp;gt; Certificate Manager&lt;/li&gt;
&lt;li&gt;You should have the status as issued&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope this helps😁&lt;/p&gt;

&lt;p&gt;Feel free to comment with questions or feedback✌️&lt;/p&gt;

&lt;p&gt;Happy coding,&lt;/p&gt;

&lt;p&gt;Az 👨🏾‍💻&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.oss-group.co.nz/blog/automated-certificates-aws"&gt;https://www.oss-group.co.nz/blog/automated-certificates-aws&lt;/a&gt;
-&lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record"&gt;https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://giphy.com/gifs/southparkgifs-26ueZwfsRvivkoHvO"&gt;https://giphy.com/gifs/southparkgifs-26ueZwfsRvivkoHvO&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.diagrams.net/"&gt;https://app.diagrams.net/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.terraform.io/"&gt;https://www.terraform.io/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/"&gt;https://aws.amazon.com/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>programming</category>
      <category>devops</category>
      <category>terraform</category>
    </item>
  </channel>
</rss>
