<?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: Emre Oztoprak</title>
    <description>The latest articles on Forem by Emre Oztoprak (@emreoztoprak).</description>
    <link>https://forem.com/emreoztoprak</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%2F720292%2F36a61117-69a9-4353-abad-081ddb1ea230.jpeg</url>
      <title>Forem: Emre Oztoprak</title>
      <link>https://forem.com/emreoztoprak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/emreoztoprak"/>
    <language>en</language>
    <item>
      <title>Host a static website on AWS under a minute with Terraform</title>
      <dc:creator>Emre Oztoprak</dc:creator>
      <pubDate>Sun, 14 Nov 2021 20:23:32 +0000</pubDate>
      <link>https://forem.com/aws-builders/host-a-static-website-on-aws-under-a-minute-with-terraform-3hmd</link>
      <guid>https://forem.com/aws-builders/host-a-static-website-on-aws-under-a-minute-with-terraform-3hmd</guid>
      <description>&lt;p&gt;If you have a static website and you want a simple solution, S3 and Cloudfront are great choices. S3 with Cloudfront secure, scalable way to host static content. Also, we will get an SSL certificate for our domain and it will be free.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;Before the deployment of this terraform module, make sure your hosted zone exists in Route 53 and move your domain to Route53 by changing NS records on your DNS provider.&lt;/p&gt;

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

&lt;p&gt;We will use 4 AWS Services;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;S3 - Storing website files (HTML, CSS, JavaScript)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cloudfront - CDN&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Certificate Manager - SSL Certificate&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Route 53 - DNS records&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since we are using Cloudfront we don't need the public bucket, so we will create a private S3 bucket. We will use OAI (Origin Access Identity) settings when we create Cloudfront. This means that only our Cloudfront distribution can access and read the files in our S3 bucket. Also, we will create an SSL certificate from Certificate Manager and Cloudfront redirect all HTTP traffic to HTTPS.&lt;/p&gt;

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

&lt;p&gt;First clone the repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com:emreoztoprak/terraform-aws-s3-cloudfront-acm.git

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

&lt;/div&gt;



&lt;p&gt;Change these two variables in the &lt;strong&gt;terraform.tfvars&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
SiteTags = "Example" (Tag value of the resources.)

domainName = "example.com"

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

&lt;/div&gt;



&lt;p&gt;You can now run this module when you change the variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
terraform plan
terrafom apply --auto-approve

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

&lt;/div&gt;



&lt;p&gt;After the deployment is completed upload your website files to in S3 Bucket. I configured DefaultRootObject as index.html. Basically, when users access your root URL they will see index.html file.&lt;/p&gt;

&lt;p&gt;I just uploaded a simple HTML file.&lt;/p&gt;

&lt;p&gt;Congratulations. You made it. :)&lt;/p&gt;

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

&lt;p&gt;Hope you find this tutorial helpful!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>terraform</category>
      <category>cloudfront</category>
      <category>s3</category>
    </item>
    <item>
      <title>Deploy Elastic Beanstalk Application with Terraform</title>
      <dc:creator>Emre Oztoprak</dc:creator>
      <pubDate>Thu, 21 Oct 2021 12:54:18 +0000</pubDate>
      <link>https://forem.com/aws-builders/deploy-elastic-beanstalk-application-with-terraform-2f9l</link>
      <guid>https://forem.com/aws-builders/deploy-elastic-beanstalk-application-with-terraform-2f9l</guid>
      <description>&lt;p&gt;AWS Elastic Beanstalk is a managed service for deploying and scaling web applications and services. It supports languages such as Java, .NET, PHP, Node.js, Python, Ruby, Go, and also Docker. You can deploy these applications on Apache, Nginx, Passenger, and IIS.&lt;/p&gt;

&lt;p&gt;But Elastic Beanstalk has a lot of configurations. With Terraform we can automate this process. Later we can use the same Terraform script just changing variables.&lt;/p&gt;

&lt;p&gt;With this Terraform configuration, we will create PHP 8.0 Elastic Beanstalk WebServer Environment on Amazon Linux 2 and Nginx. Also Application Load Balancer and SSL certificate for our domain. We will validate this certificate, create A record for our domain and it will be pointed to Elastic Beanstalk Environment. In the end, it will create Cloudwatch alarms for Elastic Beanstalk Environment Health, LoadBalancer 5xx requests, and network out the traffic of our instances.&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;Structure of our Terraform Configurations&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html" rel="noopener noreferrer"&gt;Create EC2 Key Pair &lt;/a&gt;&lt;br&gt;
Creating key pair in the EC2 console and using the name of that key pair in Terraform is a secure way than passing the public key pair file in Terraform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html" rel="noopener noreferrer"&gt;SNS Topic&lt;/a&gt;&lt;br&gt;
When Cloudwatch alarms are triggered you will get notifications via SNS. You can add subscriptions like E-Mail, SMS, or HTTP-HTTPS endpoint like Opsgenie. You can use the same SNS Topic later in different alarms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingHostedZone.html" rel="noopener noreferrer"&gt;Route53 Public Hosted Zone&lt;/a&gt;&lt;br&gt;
SSL Certification and DNS Records for your domain&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deployment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Clone the repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git@github.com:emreoztoprak/terraform-aws-elasticbeanstalk.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the variables in the terraform.tfvars file&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I set up one subnet for EC2 Instance and two subnets for ALB. You can change this any number you want.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;When everything is ready you can deploy with these 4 commands.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



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

&lt;p&gt;&lt;a href="https://github.com/emreoztoprak/terraform-aws-elasticbeanstalk" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope it was useful. Thank you for reading this article.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Send AWS Config Notification to Slack</title>
      <dc:creator>Emre Oztoprak</dc:creator>
      <pubDate>Wed, 06 Oct 2021 11:20:05 +0000</pubDate>
      <link>https://forem.com/aws-builders/send-aws-config-notification-to-slack-1f7j</link>
      <guid>https://forem.com/aws-builders/send-aws-config-notification-to-slack-1f7j</guid>
      <description>&lt;h3&gt;
  
  
  What is AWS Config?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;AWS Config provides a detailed view of the configuration of AWS resources in your AWS account. This includes how the resources are related to one another and how they were configured in the past so that you can see how the configurations and relationships change over time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s what AWS say. It’s basically compliance and auditing tool for your AWS resources. You can track your resources are compliant or not, according to the rules. Here are some sample rules;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ssh port disabled off all my instances?&lt;/li&gt;
&lt;li&gt;Deletion protection enabled on all my RDS instances?&lt;/li&gt;
&lt;li&gt;IAM Access Keys rotating every 90 day?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But there aren’t only 3 rules, there are too many rules. You can’t track all rules by manually. You want to get notified when a rule change status to &lt;strong&gt;non-compliant.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will do this by Amazon Eventbridge and little python code.&lt;br&gt;
Here our python code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json, boto3, requests

def lambda_handler(event, context):

    time = event['time']
    region = event['region']
    rule = event["detail"]["configRuleName"]
    resource_type = event["detail"]["newEvaluationResult"]["evaluationResultIdentifier"]["evaluationResultQualifier"]["resourceType"]
    resource_id = event["detail"]["resourceId"]
    compliance = event["detail"]["newEvaluationResult"]["complianceType"]

    webhook_url = "YOUR SLACK WEBHOOK URL"
    slack_data = slack_data = {
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "\n*Config Compliance Change* :alert_:"
            }
        },
        {
            "type": "divider"
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "*`Compliance:`*  " + compliance + "\n*`Time:`* " + time + "\n*`Region:`* " + region + "\n*`Rule:`* " + rule +"\n*`Resource Type:`* "+resource_type+"\n*`Resource ID:`* "+ resource_id
            },
            "accessory": {
                "type": "image",
                "image_url": "https://i.ibb.co/BjWcWKt/Picture1.png",
                "alt_text": "thumbnail"
            }
        },
        {
            "type": "divider"
        },
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "For more details."
            },
            "accessory": {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "text": "AWS Config"
                },
                "value": "click_me_123",
                "url": "https://console.aws.amazon.com/config/home?region="+region+"#/timeline/"+resource_type+"/"+resource_id+"/configuration",
                "action_id": "button-action"
            }
        }
    ]
}
    response = requests.post(
        webhook_url, data=json.dumps(slack_data),
        headers={'Content-Type': 'application/json'}
    )
    if response.status_code != 200:
        raise ValueError(
            'Request to slack returned an error %s, the response is:\n%s'
            % (response.status_code, response.text)
    )

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

&lt;/div&gt;



&lt;p&gt;After uploading our code to lambda, we open the Eventbridge console. First we need event pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "source": ["aws.config"],
  "detail-type": ["Config Rules Compliance Change"],
  "detail": {
    "messageType": ["ComplianceChangeNotification"],
    "newEvaluationResult": {
      "complianceType": ["NON_COMPLIANT"]
    }
  }
}

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

&lt;/div&gt;



&lt;p&gt;This event will trigger our lambda function when &lt;strong&gt;“complianceType”&lt;/strong&gt; goes &lt;strong&gt;“NON_COMPLIANT”&lt;/strong&gt; status.&lt;/p&gt;

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

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

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

&lt;p&gt;Everything is ready now it’s time to see the results.&lt;/p&gt;

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

&lt;p&gt;AWS Config always checks your resources and rules and if a &lt;strong&gt;NON_COMPLIANT&lt;/strong&gt; type event occurs you will get notification like this.&lt;/p&gt;

&lt;p&gt;Thank you for taking the time and reading. I hope it was useful.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>monitoring</category>
      <category>compliance</category>
      <category>auditing</category>
    </item>
  </channel>
</rss>
