<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mariem SOUSSI on Medium]]></title>
        <description><![CDATA[Stories by Mariem SOUSSI on Medium]]></description>
        <link>https://medium.com/@meriemiag?source=rss-2ee5b7b9130e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8nPrcncR7ZsO17ndP19Ydw.jpeg</url>
            <title>Stories by Mariem SOUSSI on Medium</title>
            <link>https://medium.com/@meriemiag?source=rss-2ee5b7b9130e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:17:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meriemiag/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Navigating the Amazon Inspector Console]]></title>
            <link>https://medium.com/@meriemiag/navigating-the-amazon-inspector-console-62ae78d728fb?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/62ae78d728fb</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[console]]></category>
            <category><![CDATA[amazon-inspector]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Tue, 27 Aug 2024 02:36:57 GMT</pubDate>
            <atom:updated>2024-08-27T02:47:55.547Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous article, <a href="https://medium.com/@meriemiag/why-amazon-inspector-54048160eb6b"><em>Why Amazon Inspector?</em></a>, we explored the key features and benefits of Amazon Inspector for enhancing your AWS security. Now, let’s dive into the practical side of things. This guide will walk you through using the Amazon Inspector console with detailed screenshots, covering everything from activation to reviewing scan results. Whether you’re new to Amazon Inspector or looking to optimize your usage, this article will help you get hands-on with the service.</p><h3><strong>Activating Amazon Inspector</strong></h3><h4>Get started</h4><p>Select your preferred AWS region and initiate the activation process for Amazon Inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*LSdTeDC1mnj9tFcBwtoeFw.png" /></figure><h4><strong>Activate Amazon Inspector</strong></h4><p>During activation, a role with the necessary permissions for Inspector is automatically created. You can review it before finalizing the activation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*b_VAAIrzc1UQBbXJ9UFs7A.png" /></figure><h3><strong>Navigating the Inspector Dashboard</strong></h3><p>After activation, Amazon Inspector automatically scans all eligible resources in your environment, and you can review the results through the Inspector dashboard, which provides an overview of scan outcomes, critical findings, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ikwPaJJpxB9dq2fWy6M0rA.png" /></figure><h3><strong>Reviewing Findings</strong></h3><p>You can easily access all your findings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*InECUFRVw-Y4QvSlRZBO6A.png" /></figure><h4><strong>View detailed findings</strong></h4><p>You can dive deeper into each finding to understand the vulnerabilities identified and their potential impact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*0jhVL7hAbReUhxv1moos3w.png" /></figure><h4><strong>Export findings</strong></h4><p>You can export all findings to an S3 bucket in JSON or CSV format for further analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*-ysPtznzu1dIJLGq2TtAbw.png" /></figure><h3><strong>Creating suppression rules</strong></h3><p>You can create suppression rules to hide specific vulnerabilities based on criteria such as account ID, resource ID, vulnerability ID, severity, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*2TjET-wOmCirmSMRHbagEw.png" /></figure><h3>Searching in Inspector Vulnerability Database</h3><p>You can obtain detailed information about vulnerabilities by entering their CVE-ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*-Ognv8vT8Vc8agHFfQPegw.png" /></figure><h3>Viewing EC2 Scanning Coverage</h3><p>You can review the number of instances scanned, the scanning method used, and the date of the last scan. Instances that are stopped are excluded from scans, while others are scanned using either the agent-based or agentless method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*-VTElOGG_91aXR2z4_IKfQ.png" /></figure><h3><strong>Creating and Running CIS Scans</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*q8zDnfvzQMrPZafPrKdVaw.png" /></figure><h4><strong>Define CIS scans parameters</strong></h4><p>You can configure CIS scans by setting the scan name, tags, targeted EC2 instances, CIS Benchmark level, accounts, and schedule for one-time or recurring scans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*u_XZBfQfImxU5fc4LdB0jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*DL6vNXx0EvgqidEQEBk6sA.png" /></figure><p>At this step, the scan configuration is established, and the CIS scan is now in progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*CTZVBp6tr9Z-O7KY7UZvjw.png" /></figure><h4><strong>Review CIS Scan Results</strong></h4><p>You can View CIS scan results in the console or download them in PDF or CSV format to take necessary compliance actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*9YIhH-qAR-5fwx-hqeP1jA.png" /></figure><h3><strong>Viewing lambda scanning coverage</strong></h3><p>Inspector allows you to easily review the scan results for your Lambda functions. Keep in mind that functions not modified or invoked in the last 90 days are automatically excluded from scans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ZiivQ8DxJoRnmW0zllx1Ew.png" /></figure><h3>Enabling Lambda code scanning</h3><p>In addition to the default standard scanning, you have the option to activate Lambda code scanning for enhanced security coverage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*PdP2feZPd2Zn14lI_ETTWA.png" /></figure><p>Lambda code scanning is now active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*opmLMBlxmJfx6K_TzBi49g.png" /></figure><h3>Analyzing Lambda Scanning Results</h3><p>You can review the scanning outcomes for a specific function, as shown in the screenshot below. The results indicate detected vulnerabilities and specify whether they were identified through standard scanning or code scanning processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*l4JMiAvGhOlDbVzIb-8lcw.png" /></figure><p>You can view detailed information about the detected vulnerabilities and the recommended remediation steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*ogABJYu2DYRL4UbJ50idoQ.png" /></figure><h3><strong>Viewing ECR scanning coverage</strong></h3><p>You can explore detailed information about scanned ECR images. It’s important to note that ECR images are excluded from scanning if their push or pull dates do not meet the configured re-scan duration settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*eM_ljnXDrAzsG9dxO8_IMg.png" /></figure><h3><strong>Viewing ECR scanning findings</strong></h3><p>You can review ECR scanning findings through both the ECR and Inspector consoles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*KmMeqI5Gxzo7dBpZGdUt9Q.png" /></figure><h3>Customizing ECR Scanning</h3><h4>Choose filters and scan mode</h4><p>You can adjust filters for images to be scanned and modify the ECR scan mode, choosing between on-push or continuous scanning, from the ECR console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*pMKQxr9I0OhwCBHuSuj_Kw.png" /></figure><h4><strong>Configure ECR Re-Scan Duration</strong></h4><p>You can define the ECR re-scan duration from the Inspector console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*xkY3USz1IyeaJp22eT1yQA.png" /></figure><h3><strong>Monitoring Costs</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*s6cJxgAQe90tlLAng8Cxow.png" /></figure><h3><strong>Deactivating Amazon Inspector</strong></h3><p>You can deactivate Amazon Inspector when it’s no longer needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*nuoYRCf7F_J3tj9J28TQJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*-1TjM7eEGcueHttp06PuPQ.png" /></figure><h3>Conclusion</h3><p>By following this guide, you can efficiently activate the service, monitor scans, and review findings to safeguard your environment.</p><p>AWSharing: Together, We Keep Growing! ❤️💪🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62ae78d728fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Amazon Inspector?]]></title>
            <link>https://medium.com/@meriemiag/why-amazon-inspector-54048160eb6b?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/54048160eb6b</guid>
            <category><![CDATA[ec2-scanning]]></category>
            <category><![CDATA[ecr-scanning]]></category>
            <category><![CDATA[cis-benchmarks]]></category>
            <category><![CDATA[lambda-scanning]]></category>
            <category><![CDATA[amazon-inspector]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 14:05:29 GMT</pubDate>
            <atom:updated>2024-08-26T14:43:18.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yqhxr_0j4lVw8U9QtA6mKQ.jpeg" /></figure><p>Ensuring the security of your AWS application is a shared responsibility between you and AWS. While AWS provides a secure infrastructure, it’s crucial to focus on the security aspects within your control. Security encompasses multiple layers and requires continuous vigilance to prevent potential threats that could compromise your application. A key part of this continuous work is regularly scanning for vulnerabilities in the software packages your application depends on, as well as in your network configuration. This is where Amazon Inspector becomes essential.</p><p>Amazon Inspector is a vulnerability management service that automatically discovers workloads and continuously scans them for software vulnerabilities and unintended network exposure. It identifies package vulnerabilities across EC2 instances, Elastic Container Registry (ECR) images, and Lambda functions. Additionally, Amazon Inspector integrates seamlessly with CI/CD pipelines, making it an essential tool in DevSecOps practices.</p><p>In this article, I will guide you through the key functionalities of Amazon Inspector, including EC2 scanning, ECR scanning, Lambda scanning, and more, to help you leverage its full potential in securing your cloud environment.</p><h3><strong>Amazon inspector</strong></h3><p>Amazon Inspector is a regional service that is not enabled by default. Once activated, it automatically discovers all your Amazon EC2 instances, ECR images, and Lambda functions that are eligible for scanning within the enabled region. It then delivers near real-time vulnerability scanning for software vulnerabilities and unintended network exposure. The service continuously scans these resources based on specific conditions for each service without requiring any manual intervention.</p><p>By default, EC2 scanning, ECR scanning, and Lambda scanning are activated. However, you have the flexibility to deactivate any of these scan types if they are not needed.</p><p>AWS Inspector requires permissions to access other services for scanning, which are granted through a service-linked role called <em>AWSServiceRoleForAmazonInspector2</em>, created globally for your account when the service is activated for the first time.</p><p>The scan results are organized into findings, which are detailed reports of the vulnerabilities detected in your environment, categorized by severity level. Each finding describes the vulnerability, identifies the affected resource, rates the severity, and provides remediation guidance. While AWS Inspector does not have built-in remediation capabilities, it has integration with AWS Security Hub and Amazon EventBridge to allows you take action on the findings. All active findings are stored by AWS Inspector until they are remediated.</p><p><em>Note. Once you activate Amazon Inspector for the first time in a region, you have a 15-day trial.</em></p><h3><strong>Amazon Inspector Vulnerability database</strong></h3><p>The Amazon Inspector Vulnerability Database is continuously updated with the latest CVEs (Common Vulnerabilities and Exposures). You can utilize the vulnerability database search feature in the AWS console to find detailed information about a specific CVE or to check if it is covered by Inspector, simply by entering the CVE ID.</p><h3><strong>EC2 instance scanning</strong></h3><p>AWS Inspector scans all running EC2 instances in your environment upon activation to detect operating system package vulnerabilities.</p><p>With <a href="https://docs.aws.amazon.com/inspector/latest/user/deep-inspection.html">EC2 deep inspection</a>, which is automatically enabled as part of Amazon EC2 scanning for accounts activated after April 1, 2023, Amazon Inspector also detects vulnerabilities in application programming language packages on your Linux-based EC2 instances. By default, Amazon Inspector scans the standard paths for these package libraries, but you can configure custom paths to be included in the scan. Currently, deep inspection is not supported for Windows or Mac instances.</p><p>To focus your security scanning efforts on the most critical resources, you can exclude specific EC2 instances from scanning by adding a resource tag with the key <em>InspectorEc2Exclusion</em> and any optional value.</p><p>AWS Inspector offers two EC2 scanning modes: Agent-based scanning and hybrid scanning.</p><p><strong>Agent-based scanning</strong></p><p>In <a href="https://docs.aws.amazon.com/inspector/latest/user/scanning-ec2.html#:~:text=Agent%2Dbased%20scan%20behaviors">this scan mode</a>, Amazon Inspector exclusively scans instances managed by AWS Systems Manager (SSM), where the SSM Agent is installed, running, and has the necessary permissions to manage the instance.</p><p>Rescans are triggered automatically when a new software package is installed or uninstalled, when a new CVE is published, or when a vulnerable package is updated.</p><p><em>Note: The SSM Agent is preinstalled on some Amazon Machine Images (AMIs) provided by AWS. If you launch an EC2 instance from one of these AMIs, the SSM Agent will already be installed and running.</em></p><p><strong>Hybrid scanning</strong></p><p>The hybrid mode is particularly useful when it’s not feasible to install the SSM agent on all hosts in your environment. In such scenarios, Amazon Inspector can still effectively perform scans using the agentless method to ensure that all eligible instances are covered.</p><p>In hybrid mode, Amazon Inspector combines both agent-based and agentless scanning to provide comprehensive vulnerability assessments. For instances managed by SSM, Inspector relies on the SSM agent to perform detailed scans. However, when the SSM agent is not installed or configured, Inspector automatically switches to the agentless method for eligible EBS-backed instances.</p><p>In <a href="https://docs.aws.amazon.com/inspector/latest/user/scanning-ec2.html#:~:text=Agent%2Dbased%20scan%20behaviors">the agentless method</a>, Amazon Inspector takes a snapshot of the EBS volume to extract data about the system and configuration of the instances, enabling accurate vulnerability assessments. The agentless rescans are performed every 24 hours, ensuring that your environment remains continuously monitored.</p><h4><strong><em>EC2 </em>CIS Benchmark assessments</strong></h4><p>In addition to Amazon Inspector CVE scans, you might also want to evaluate your Amazon EC2 instances for compliance with CIS (Center for Internet Security) Benchmarks.</p><p><a href="https://aws.amazon.com/what-is/cis-benchmarks/"><em>CIS Benchmarks</em></a><em> are a set of globally recognized best practices developed by a global community of security experts to help organizations proactively safeguard against emerging risks.</em></p><p><a href="https://docs.aws.amazon.com/inspector/latest/user/scanning-cis.html">Amazon Inspector CIS scans</a> scan a collection of your resources for compliance with CIS Benchmarks. It can perform on-demand and targeted assessments for level 1 and 2 configurations checks. These assessments evaluate your Amazon EC2 instance operating systems to ensure they are configured according to best practice recommendations established by CIS.</p><p><strong><em>Note:</em></strong><em> The instance should be managed by Amazon EC2 Systems Manager and must have the AmazonSSMManagedInstanceCore and AmazonInspector2ManagedCisPolicy permissions.</em></p><h3><strong>ECR Scanning</strong></h3><p>When you activate Amazon ECR scanning in Amazon Inspector, you upgrade from basic to enhanced ECR scanning, assessing your container images for both operating system and programming language package vulnerabilities. Inspector scans all eligible ECR images pushed within the last 30 days or pulled within the last 90 days.</p><p>To ensure that only relevant repositories are scanned, you can apply filters to specify which ones should be included in the scanning process.</p><p>You have the option to select between two scanning modes: on-push scanning or continuous scanning.</p><ul><li><strong>On-push scanning</strong> only occurs when you push a new image to the repository.</li><li><strong>Continuous scanning</strong>, which is the default option, includes on-push scans as well as automated rescans.</li></ul><p>In continuous scanning, rescans are automatically triggered when a new CVE affecting an eligible image is published. The eligibility for rescans is determined by the ECR re-scan duration, a setting that specifies how long Amazon Inspector continues to monitor container images in repositories. By default, the re-scan duration is set to 90 days for both the image push date and image pull date. If an image hasn’t been pushed or pulled within these configured durations, Amazon Inspector will stop monitoring it.</p><h3><strong>Lambda Scanning</strong></h3><p>All new Lambda functions are initially assessed upon discovery and continually reassessed whenever there is an update to the Lambda function code, its dependencies, or its layers, or when a new CVE item is added to the Inspector database that is relevant to the function. If a function has not been invoked or updated in the last 90 days, it is automatically excluded from scanning. However, it will be included again automatically if it is invoked or if changes are made to the Lambda function code.</p><p>Amazon Inspector offers two types of Lambda scanning: Lambda standard scanning, which is the default, and Lambda code scanning. You have the option to either activate Lambda standard scanning alone or enable both Lambda standard and code scanning together. However, you cannot activate only the code scanning.</p><ul><li><strong>Lambda standard scanning</strong> identifies software vulnerabilities in the dependencies of your Lambda function code and layers.</li><li><strong>Lambda code scanning</strong> provides additional security value by scanning your lambda custom code for code security vulnerabilities, based on AWS security best practices. Amazon Inspector generates security findings that provide details such as the security detector name, impacted code snippets, and remediation suggestions to address the vulnerabilities.</li></ul><p>To maintain flexibility and control over what gets scanned, Amazon Inspector allows you to exclude specific Lambda functions from scanning by adding a resource tag. For standard scanning exclusion, use the key <em>InspectorExclusion</em> and the value <em>LambdaStandardScanning</em>. For code scanning exclusion, use the key <em>InspectorCodeExclusion</em> and the value <em>LambdaCodeScanning</em>.</p><p><strong><em>Note:</em></strong><em> Amazon Inspector scans only the $LATEST version of the Lambda function.</em></p><h3><strong>Suppression rules</strong></h3><p>Amazon Inspector supports the creation of suppression rules, allowing you to suppress findings based on specific criteria that you define. This feature is particularly useful for eliminating low-value findings or those that are irrelevant to your specific environment, helping you focus on the most critical security issues.</p><h3><strong>CI-CD integration</strong></h3><p>The scans performed by Amazon Inspector are typically conducted after code is deployed to an EC2 instance, pushed to an ECR registry, or deployed as a Lambda function. However, if you want to implement security checks earlier in the software development lifecycle, you can <a href="https://docs.aws.amazon.com/inspector/latest/user/scanning-cicd.html">integrate Amazon Inspector directly into your CI/CD pipeline</a>. This can be done using dedicated plugins provided by Amazon Inspector, currently available for Jenkins and TeamCity. Once installed, these plugins allow you to add a step in the pipeline to perform assessments, such as evaluating container images, and take necessary actions like blocking the pipeline based on the assessment results.</p><p>If Amazon Inspector doesn’t offer a plugin for your CI/CD solution, you can create a custom integration using the <a href="https://docs.aws.amazon.com/inspector/latest/user/sbom-generator.html">Amazon Inspector SBOM Generator</a> and the Amazon Inspector Scan API.</p><p>There are no restrictions on where your CI/CD tools are hosted — they can be in AWS, on-premises, or in hybrid cloud environments. This flexibility allows developers to maintain consistency across all development pipelines using a single security solution.</p><h3><strong>Inspector at Scale</strong></h3><p>For AWS environments with multiple accounts, you can simplify security management by centrally managing Amazon Inspector through a single account using AWS Organizations. Additionally, you can automate Inspector activation for new accounts as they join your organization, ensuring consistent security coverage across your entire AWS environment.</p><h3><strong>Conclusion</strong></h3><p>In summary, Amazon Inspector enhances your AWS security by continuously scanning for vulnerabilities in EC2 instances, ECR images, and Lambda functions. Integrating Inspector into your DevSecOps workflow ensures that these vulnerabilities are identified and addressed early, helping you proactively protect your applications and data.</p><p>AWSharing: Together, We Keep Growing! ❤️💪🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54048160eb6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why AWS Config?]]></title>
            <link>https://medium.com/@meriemiag/why-aws-config-ff0f33f7715f?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff0f33f7715f</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[aws-config]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-system-manager]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 04:46:12 GMT</pubDate>
            <atom:updated>2024-08-19T05:04:57.924Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPPbmfG5XUjRfQaD4xcXIA.jpeg" /></figure><p>As your AWS application scales and adapts to meet new demands, keeping a close eye on your cloud resources and ensuring they remain compliant with internal and industry standards is essential. AWS Config is a monitoring and management service that helps you achieve this. It provides an inventory of your account resources, how they are interconnected, tracks their configuration changes, and ensures they comply with predefined rules. Additionally, AWS Config can automate the remediation of non-compliant changes and offers many other features to enhance your cloud management.</p><p>In this article, I will guide you through the key functionalities of AWS Config, including managing your resource inventory, tracking change history, evaluating compliance, and implementing remediation actions to automatically address non-compliant configurations.</p><h3><strong>Resources Inventory</strong></h3><p>AWS Config is a regional service that is not enabled by default. When you turn on AWS Config, it first discovers the resources in the selected region of your account and provides you with an inventory of all those resources. Any changes to these resources will then be tracked and recorded by AWS Config.</p><p>In the following section, I will show how to turn on AWS Config using the console and outline the most important parameters that need to be defined during this process.</p><h4><strong><em>Get started</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*wqrlyLbP3UsjV_dVC_vPKA.png" /></figure><h4><strong><em>Define Recording strategy</em></strong></h4><p>You can choose to monitor <a href="https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html">all resources supported by AWS Config</a> within the region, or you can opt to monitor only specific resource types. This flexibility allows you to tailor the monitoring to your specific needs, ensuring that only the resources critical to your operations are tracked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtJa__wQ8IlorTYesGBSEQ.png" /></figure><h4><strong><em>Define recording frequency</em></strong></h4><p>It can be continuous, or daily recording.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*5dZURpqp6BJb1e542mxoVA.png" /></figure><h4><strong><em>Override settings if needed</em></strong></h4><p>When you choose to record all resources and set a recording frequency, this frequency applies to all your resources. However, you can “override” these settings by excluding specific resources, or by setting a different recording frequency for certain resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*74mRJJl_6QKarg39fdN_PQ.png" /></figure><h4><strong><em>Define AWS Config role</em></strong></h4><p>AWS Config needs permissions to interact with other AWS services, which requires an IAM role. You can either use the existing AWS Config AWS-managed service-linked role, or choose a custom IAM role from your account with the necessary permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*eoIylsclF1ozQvkFXKa6vg.png" /></figure><h4><strong><em>Define the delivery method</em></strong></h4><p>AWS Config automatically delivers configuration files to a specified S3 bucket. You have control over this process, allowing you to specify whether the bucket is to be created by AWS Config, or one of your existing buckets, or even a bucket in another account. Additionally, you can opt to receive email notifications for each configuration change.</p><p><em>AWS Config delivers three types of configuration files to the S3 bucket, and the delivery frequency depends on the file type. For instance, the history file is sent to S3 every six hours.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*55YEdUHwM54U_IvnEMqS2g.png" /></figure><h4><strong>Review and confirm</strong></h4><p>Defining rules is not mandatory when enabling AWS Config. You can simply review the AWS Config setup details and then confirm to complete the configuration.</p><h4><strong><em>AWS config Dashboard</em></strong></h4><p>Once enabled, AWS Config provides a visual dashboard that helps you maintain control and visibility over your AWS environment, allowing you to manage configurations and compliance more effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*2du-52-SF3tnWpYZaTOVnA.png" /></figure><h4><strong>View you resource inventory</strong></h4><p>AWS Config detects all resources in your environment and lists them in the resource inventory. You can filter the inventory using various criteria and even include deleted resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*HU-wLCSlSSZX1kASwXy5_Q.png" /></figure><h3><strong>Configuration change history</strong></h3><p>AWS Config continuously monitors and records changes to your AWS resource configurations, providing you with a detailed history of all changes. It integrates with CloudTrail to capture these details. It allows you to review and troubleshoot issues in your environment by correlating configuration changes with specific events in your account.</p><p>While AWS Config aims to capture changes as soon as they are detected, there may be a slight delay in recording the changes.</p><p>In the following section, I will show you how to view the change history of an AWS resource using the console.</p><h4><strong><em>Select your resource and access the Resource Timeline</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*GF7N4hF9iVgnlgGKz_oQ5w.png" /></figure><h4><strong><em>Review the Change History</em></strong></h4><p>The resource timeline will display a history of all events that have impacted the selected resource. You can click on each event to access detailed information</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*2l9vyxutgG4QQFDGgP1sqg.png" /></figure><h3><strong>Compliance evaluation</strong></h3><p>AWS Config helps you continuously evaluate the compliance of your resource configurations against your defined standards. To do this, you need to set up compliance rules in AWS Config, which will automatically check and verify if these rules are being respected after any configuration changes. If a resource violates a rule, AWS Config flags both the resource and the rule as non-compliant. Optionally, you can choose to receive email alerts and even trigger automatic remediation actions.</p><p>In the following section, I will demonstrate how to define AWS Config rules using the console, focusing on the most important parameters for this process.</p><p><em>The example resource will be a security group, and the rule goal will be to mark as non-compliant any security group that is not attached to an Elastic Network Interface (ENI).</em></p><h4><strong><em>Add rule</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*6JgpreY-UvRMh5Zf3Oydmw.png" /></figure><h4><strong><em>Specify rule type</em></strong></h4><p>AWS Config provides you with a list of <a href="https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html">pre-built rules</a> to evaluate the configurations of your cloud resources. You can select from this list, or create your own custom rules tailored to your specific needs.</p><p>Examples of AWS-managed Config Rules include:</p><ul><li>Checking if running EC2 instances are using specified Amazon Machine Images (AMIs)</li><li>Verifying if S3 buckets are publicly accessible</li><li>Ensuring that logging is enabled for your S3 buckets</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*r-ViFllH2WajuZmgTq0yHA.png" /></figure><h4><strong><em>Choose an AWS-Managed Config rule</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*UR0mv0BI_lG_oJaSDJ_tjg.png" /></figure><h4><strong><em>Define the Evaluation mode</em></strong></h4><p>Each AWS-managed Config Rule supports one, or more evaluation modes: Proactive, Detective, or both.</p><p>The <strong><em>Proactive Evaluation</em></strong> verifies the rule against resource configurations before they are deployed. If the resource doesn’t comply, it will be flagged as non-compliant, but the deployment is not prevented, and no automatic remediation occurs.</p><p>The<strong><em> Detective Evaluation</em></strong> checks the rule against resources that have already been deployed.</p><h4><strong>Define the trigger type</strong></h4><p>In the case of detective evaluation, you can decide when the rule evaluation should occur after resource deployment. It can be triggered at regular intervals, whenever a configuration change takes place, or both.</p><h4><strong>Define the scope of changes</strong></h4><p>If the trigger type is configuration change, you can specify whether the evaluation should be triggered: by any change in the environment, OR changes to the specific resource types defined in the rule, OR changes to resources with specific tags</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*h_2uWU3dAnHSeVFnZNtnCw.png" /></figure><p><strong><em>Note</em></strong><em>: This screenshot illustrates the various options you may need to define for an AWS Config rule. It does not concern the AWS Config rule “ec2-security-group-attached-to-eni.”</em></p><h4><strong>Give rule parameters</strong></h4><p>You should specify parameters if the rule has required parameters (or optional) to execute correctly</p><h4><strong><em>Review and create</em></strong></h4><p>Once the rule is evaluated, AWS Config will flag non-compliant resources in the dashboard, on the rules page, and within the timeline of the non-compliant resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*df9PNnTwZp7mPos9xEgxdw.png" /></figure><h4><strong><em>List non-complaint resources</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*KuNEFQ0hScx5NGjm5M1rSw.png" /></figure><h3><strong>Remediation</strong></h3><p>It’s helpful to have a list of non-compliant resources, but it’s even better to automatically remediate them, which you can do with AWS Config by applying remediation actions to AWS Config rules.</p><p>In the following section, I will show you how to define a remediation action for an AWS Config rule using the console and outline the most important parameters for remediation.</p><p><em>The example will use the AWS Config rule “ec2-security-group-attached-to-eni.”</em></p><h4><strong><em>Manage remediation</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*75tPOa-Fj_fMz4yz1QEVdQ.png" /></figure><h4><strong><em>Select remediation method</em></strong></h4><p>The remediation action is a process that can be triggered automatically when a resource is detected as non-compliant, or it can be triggered manually requiring your intervention to initiate it.</p><p><em>In my example, I choose to trigger the remediation action manually, as I don’t want it to be applied to all non-compliant security groups.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*oft-xLOb2lekmsYBEtwJ1w.png" /></figure><h4><strong><em>Choose the remediation action</em></strong></h4><p>Remediation actions are based on AWS Systems Manager Automation documents (SSM documents), which define the steps to correct non-compliance. These documents can execute tasks like running scripts, or invoking AWS API calls. AWS offers a variety of managed SSM documents for common remediation tasks, and you can also create custom ones for your specific needs.</p><p>For my example, I chose the AWS-managed remediation action <em>AWS-CloseSecurityGroup,</em> which closes traffic to and from a security group by removing all ingress and egress rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*m7d_TleLlTCsoE_D7GVvzA.png" /></figure><h4><strong>Provide parameters and save changes</strong></h4><p>You need to specify the required parameters for the remediation action if they exist. Optional parameters can also be included if desired.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*jOdbb9TL37rU9U-o7EY2YA.png" /></figure><h4><strong>Start Remediation</strong></h4><p>Since I chose a manual trigger, I need to select the resource and manually launch the remediation. This will execute the SSM document associated with the remediation action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Wr2F5Gr0U6WGVQ_v2GOgXw.png" /></figure><h4><strong>Wait for Remediation Completion</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*3Ilip3zKCBde_Ja-2Oy0tg.png" /></figure><p>The result is that all inbound and outbound rules of the security group are removed, which can be verified by viewing the resource timeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*xE7kXfyPeMtYcC3dLAkgMg.png" /></figure><h3><strong>More about AWS Config</strong></h3><p>AWS Config isn’t just for tracking changes to your AWS resources, it can also record configurations for third-party resources, or custom resource types, including on-premises servers. Additionally, it tracks software configuration changes on EC2 instances, on-premises servers, and servers or virtual machines from other cloud providers.</p><p>AWS Config automatically discovers and tracks relationships between your AWS resources. This lets you see how a resource is connected to others and understand the impact of changes before making it.</p><p>In multi-account or multi-region environments, AWS Config data aggregation feature allows you to centrally manage auditing and governance of your AWS resources.</p><p>To maintain consistent policies and best practices across multiple accounts, you can use AWS Config Compliance Packs. These help you apply the same standards efficiently across your organization.</p><p>For deeper insights into your environment, AWS Config offers Advanced Queries to run complex searches on your resource configuration data.</p><p><strong>Conclusion</strong></p><p>AWS Config is a valuable service for monitoring and managing your AWS environment. It helps track changes, ensure compliance, and manage resources across multiple accounts and regions, making it easier to keep your cloud environment secure and well-organized.</p><p>AWSharing: Together, We Keep Growing! ❤️💪🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff0f33f7715f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding dual-stack VPC in AWS]]></title>
            <link>https://medium.com/@meriemiag/understanding-dual-stack-vpc-in-aws-65bf7a77474c?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/65bf7a77474c</guid>
            <category><![CDATA[ipv6]]></category>
            <category><![CDATA[ipv6-only-subnet]]></category>
            <category><![CDATA[ipv4]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Tue, 11 Jun 2024 05:34:50 GMT</pubDate>
            <atom:updated>2024-06-11T06:45:50.589Z</atom:updated>
            <content:encoded><![CDATA[<p>IPv4 has been the primary protocol for identifying and communicating with devices on the internet for many years. IPv4 addresses consist of 32 bits, allowing for approximately 4.3 billion unique addresses, which was initially sufficient when IPv4 was introduced. However, as the number of internet-connected devices has grown, and to address the problem of address exhaustion, IPv6 was developed with 128-bit addresses, providing a vastly larger address space.</p><p>Although IPv6 has been available for many years, its adoption has been slow, with IPv4 remaining the dominant protocol until recent years. The exponential growth of connected devices, including IoT, has significantly accelerated the shift towards IPv6. IPv6 offers not only a larger address space but also additional features that simplify aspects of address configuration and network renumbering. Furthermore, IPv6 helps reduce costs associated with IPv4, as the acquisition costs for IPv4 addresses continue to rise. This makes IPv6 a more cost-effective and scalable solution in the long term.</p><p>If you want a future-proof AWS infrastructure that takes advantage of the protocol’s benefits and prepares for the inevitable increase in IPv6 traffic, you can begin by creating a dual-stack VPC in which you can create IPv6-only subnets.</p><p>In this article, I will present dual-stack VPC and explain the changes compared to VPCs with only IPv4 CIDR blocks, which I discussed in my <a href="https://medium.com/@meriemiag/exploring-ipv4-vpc-components-with-single-and-multiple-cidr-blocks-3f68e705b112">first article</a> about VPCs.</p><h3>Dual-stack VPC</h3><p>A VPC must have an associated IPv4 CIDR block. Optionally, you can associate additional IPv4 CIDR blocks and one or more IPv6 CIDR blocks. Your VPC can have up to five IPv6 CIDR blocks. In AWS, you cannot create an IPv6-only VPC, but you can create a dual-stack VPC with IPv6-only subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*kkSRTEan3sM9vG88G74E5w.png" /><figcaption>Example of VPC with 2 IPv4 CIDR blocks and one IPv6 CIDR Block</figcaption></figure><p>For both existing and new VPCs, enabling IPv6 involves associating one /56 IPv6 CIDR block. You can allocate the IPv6 CIDR from the Amazon pool of IPv6 addresses or use a /56 from a BYOIPv6 (Bring Your Own IPv6) pool defined with IPv6 addresses you own.</p><p>If you no longer want IPv6 support in your VPC but still want to use your VPC for IPv4 resources, you can remove the resources created with the IPv6 CIDR block and then remove the IPv6 CIDR block.</p><h3><strong>Dual-stack VPC Route table</strong></h3><p>In a dual-stack VPC, each route table has default local routes for both IPv4 and IPv6 CIDR blocks. This ensures that resources within the VPC can, by default, find each other and communicate using either IPv4 or IPv6 .</p><h3><strong>Dual-stack VPC Subnets</strong></h3><p>In a dual-stack VPC, you have the flexibility to create a mix of subnet types based on your requirements. You can have IPv4-only subnets, IPv6-only subnets, or dual-stack subnets, all within the same VPC. For each of these types, you can choose to make it public or private. This allows you to tailor your network configuration to accommodate both systems that rely on IPv4 and modern applications that benefit from the expanded address space and features of IPv6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Ek8zFAMEt3anmjNhjv18iA.png" /><figcaption>Example of Subnets in Dual-Stack VPC</figcaption></figure><h4><strong>IPv4-Only subnets</strong></h4><p>When configuring an IPv4-only subnet, you need to select a CIDR block from one of the IPv4 CIDR blocks associated with your VPC. The subnet will handle IPv4 traffic and is suitable for resources that do not require IPv6 connectivity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*9J3chKr2wpUH3yTl5pK5VQ.png" /></figure><h4><strong>IPv6-Only subnets</strong></h4><p>For IPv6-only subnets, the CIDR block must be chosen from one of the IPv6 CIDR blocks associated with your VPC. This setup enables the subnet to support IPv6 addresses exclusively, facilitating communication over IPv6 networks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*u1yZM-rtsvCLHLTRKJMFAw.png" /></figure><h4><strong>Dual stack subnet</strong></h4><p>Dual-stack subnets are designed to support both IPv4 and IPv6 traffic simultaneously. When creating a dual-stack subnet, you must select two CIDR Blocks: one CIDR block from the IPv4 CIDR blocks and one from the IPv6 CIDR blocks associated with your VPC. This configuration allows resources within the subnet to have both IPv4 and IPv6 addresses, enabling seamless communication over both protocols.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*K0Rxxl3fTvGkj1CXp3m-1g.png" /></figure><h4><strong>Communication between resources of dual-stack VPC</strong></h4><p>Resources (ENIs) in a dual-stack subnet can communicate over both IPv4 and IPv6. Resources in an IPv4-only subnet can communicate only over IPv4, meaning they can interact with resources in IPv4-only subnets or dual-stack subnets using IPv4. Similarly, resources in an IPv6-only subnet can communicate only over IPv6, allowing interaction with resources in IPv6-only subnets or dual-stack subnets using IPv6.</p><p>Communication between IPv4-only and IPv6-only resources in a VPC is not possible by default, as there is no direct compatibility between the IPv4 and IPv6 protocols. For addressing this challenge in a dual-stack environment, solutions such as enabling DNS64 and NAT64 for IPv6-only subnets are available. I will not cover these solutions in this article, but you can find more details in <a href="https://aws.amazon.com/blogs/aws/let-your-ipv6-only-workloads-connect-to-ipv4-services/">1</a>, <a href="https://repost.aws/questions/QUh32by6hgT6Cx7DmlWCX72A/how-to-provide-communication-between-ipv6-only-host-to-ipv4-only-and-vice-versa-in-a-vpc">2</a> and <a href="https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-nat64-dns64.html">3</a>.</p><p><em>In the rest of the article, when I refer to communication within the VPC, it is assumed that all necessary compatibility layers are set up and communication between different IP protocols is possible.</em></p><h3><strong>Dual-stack VPC gateways</strong></h3><h4><strong>Internet Gateway</strong></h4><p>The Internet Gateway (IGW) can handle both IPv4 and IPv6 traffic. You need only one Internet Gateway attached to your VPC to manage traffic coming from the Internet to public resources and going from local public resources to the Internet, regardless of the type of IP traffic.</p><h4><strong>NAT Gateway</strong></h4><p>The NAT Gateway handles only IPv4 traffic and you need it for your private IPv4 resources to reach the Internet.</p><h4><strong>Egress-Only Internet Gateway</strong></h4><p>An Egress-Only Internet Gateway is a horizontally scaled, redundant, and highly available VPC component that allows outbound IPv6 communication from your VPC to the Internet. It functions similarly to a NAT Gateway but for IPv6 traffic. You need only one Egress-Only Internet Gateway per VPC for all your outbound IPv6 traffic from your private resources.</p><h3>Dual-stack VPC public subnets</h3><p>You have the possibility to launch a public IPv4-only subnet, a public IPv6-only subnet or public dual-stack subnet</p><h4><strong>Public IPv4-only subnet</strong></h4><p>You need an Internet Gateway (IGW) attached to the VPC, a route to this IGW ID for IPv4 internet traffic in the route table associated with the subnet, and elastic IP or public IP attached to the subnet resources.</p><p><em>For more details, you can refer to </em><a href="https://medium.com/@meriemiag/exploring-ipv4-vpc-components-with-single-and-multiple-cidr-blocks-3f68e705b112"><em>my first article</em></a><em>, as the conditions for making an IPv4-only subnet public in a dual stack VPC remain unchanged compared to public subnets in VPCs with only IPv4 CIDR blocks.</em></p><h4><strong>Public IPv6-Only subnet</strong></h4><p>You need to attach an IGW to the VPC to handle IPv6 internet traffic. Next, add a route in the subnet route table for IPv6 internet traffic pointing to the IGW ID. The route must have the destination ::/0 and the target set to the IGW ID.</p><p>With these configurations, the subnet is now public and resources can interact with Internet.</p><p>Unlike IPv4 subnets, where you need to assign a public IP or Elastic IP to your resources to be publicly reachable, resources with IPv6 addresses can be publicly reachable by default.</p><p><strong><em>Remark:</em></strong><em> The IPv6 addresses for VPCs are by default routable on the internet, but that doesn’t mean all IPv6 addresses used inside your VPC will actually be able to reach or be reachable from the internet. You need to allow this by configuring the gateways, the route tables and SG and NACL rules.</em></p><h4><strong>Public dual-stack subnet</strong></h4><p>Running subnets as dual-stack means that nodes have both IPv4 and IPv6 addresses simultaneously. The two types of traffic need to be treated independently.</p><p>For public traffic, you need to attach an IGW to the VPC. Then, update the route table attached to this subnet by adding two routes to direct both IPv4 and IPv6 public traffic through the IGW to reach the Internet.</p><ul><li>The first route has the destination 0.0.0.0/0 (all IPv4 traffic) and the target set to the IGW ID.</li><li>The second route has the destination ::/0 (all IPv6 traffic) and the target also set to the IGW ID.</li></ul><p>Public dual-stack subnet resources have a private IPv4 address, a public IPv4 address, and an IPv6 address. The private IPv4 address is used for internal IPv4 VPC communication, the public IPv4 address for IPv4 internet communication, and the IPv6 address for both IPv6 VPC and internet communication.</p><h3><strong>Dual-stack VPC private subnets</strong></h3><p>You have the possibility to launch a private IPv4-only subnet, a private IPv6-only subnet or private dual-stack subnet.</p><h4><strong>Private IPv4-only subnet</strong></h4><p>Subnets are private by default and resources in an IPv4-only subnet can communicate with other resources within the VPC. If you need your IPv4-only resources to initiate traffic to the Internet, you need a NAT Gateway in a public IPv4 subnet, associated with an Elastic IP address, and a route pointing to the NAT Gateway for IPv4 internet traffic in the route table of the private IPv4-only subnet.</p><p><em>For more details, you can refer to </em><a href="https://medium.com/@meriemiag/exploring-ipv4-vpc-components-with-single-and-multiple-cidr-blocks-3f68e705b112"><em>my first article</em></a><em>, as the conditions for allowing an private IPv4-only subnet resources to send traffic to the Internet remain unchanged compared to private subnets in VPCs with only IPv4 CIDR blocks.</em></p><h4><strong>Private IPv6-only subnet</strong></h4><p>Private resources can communicate by default within the VPC. If you need your resource to initiate IPv6 traffic to the internet, you need to attach a IPv6 Egress-Only Internet Gateway to the VPC and add a route to the private IPv6-only subnet to point to the Egress-only Internet Gateway for IPv6 internet traffic (::/0)</p><h4><strong>Private dual-stack subnet</strong></h4><p>A private dual-stack subnet is designed to handle both IPv4 and IPv6 traffic within the VPC. To enable your private resources to initiate internet traffic, you need to configure different gateways for IPv4 and IPv6 traffic and update the route table of the subnet.</p><p>For IPv6 traffic, attach an Egress-Only Internet Gateway to your VPC. Update the route table associated with the private dual-stack subnet to include a route for ::/0, pointing to the Egress-Only Internet Gateway ID. This setup ensures that internet IPv6 traffic from your private instances is routed to the internet through the Egress-Only Internet Gateway.</p><p>For IPv4 traffic, create a NAT Gateway in a public IPv4 subnet and associate it with an Elastic IP address. Then, update the private dual-stack subnet route table by adding a route for 0.0.0.0/0, directing traffic to the NAT Gateway.</p><p>Private resources within a dual-stack subnet will have both private IPv4 and IPv6 addresses for internal communication. The private IPv4 addresses will be translated to the Elastic IP of the NAT Gateway for outbound IPv4 internet traffic, while the IPv6 addresses will be used directly for traffic passing through the Egress-Only Internet Gateway to the internet.</p><h4>Diagram of dual-stack VPC key elements</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*JlXZVjzBDSDhSu6RbCLxfA.png" /><figcaption>Dual-stack VPC</figcaption></figure><h3><strong>Dual stack VPC traffic control</strong></h3><p>Security Groups (SG) and Network Access Control Lists (NACL) continue to play a crucial role in controlling traffic within a VPC.</p><p><em>For more information about NACLs and SGs, please refer to </em><a href="https://medium.com/@meriemiag/exploring-ipv4-vpc-components-with-single-and-multiple-cidr-blocks-3f68e705b112"><em>my first article.</em></a></p><h4><strong>NACL</strong></h4><p>You should configure NACLs to allow or deny communication between subnets from different CIDR blocks and protocols. Ensure that your NACL entries include rules for both IPv4 and IPv6 traffic.</p><p>The default NACL allow all IPv4 and IPv6 traffic in a dual-stack VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*Z0WoeeDkq1ruW0Bqiq4y0g.png" /><figcaption>Default NACL</figcaption></figure><h4><strong>Security Groups</strong></h4><p>Update your security group rules to include entries for IPv6 addresses. This enables IPv6 traffic to flow to and from your instances effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ROvX1uSafIsLJ_mC5w7XBQ.png" /><figcaption>Example of SG</figcaption></figure><h3>AWS services that support IPv6</h3><p>If you are seeking an IPv6-only solution on AWS, it is not possible at this time to completely avoid using IPv4. While many AWS services support IPv6, there are still some that do not or support it with some restrictions. For example, Amazon EC2 supports IPv6, but this support is restricted to instance types based on the Nitro system. You find in <a href="https://repost.aws/questions/QUJN0ASI4wQyWz9bm_ui68Rw/which-ec2-types-support-ipv6">1</a> and <a href="https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html">2</a> details about services that support IPv6.</p><p>Given the current state of IPv6 support, a dual-stack configuration is the best step at the moment. This approach allows you to leverage the benefits of IPv6 while maintaining compatibility with services dependent on IPv4.</p><h3><strong>Enable IPv6 on an existing public EC2 instance</strong></h3><p>If you want to enable IPv6 on your existing instances, you need to configure it at the VPC, subnet, and instance levels. Here are the steps:</p><ol><li>Add a new IPv6 CIDR block to your VPC</li><li>Asscoiate an IPv6 CIDR block to the subnet where your EC2 instance is located.</li><li>Associate an IPv6 address to your EC2 instance.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*mLgiHX8UCz2YpGTQdWgwZw.png" /></figure><p>4. Add a new route to the route table of the EC2 instance subnet that point Internet IPv6 traffic to the IGW ID attached to the VPC</p><p>5. Modify the SG linked to your EC2 instance to allow IPv6 traffic on the required protocol and port</p><h3><strong>Testing traffic in a dual-stack VPC</strong></h3><p>Here are some tests done in a dual-stack VPC. If you want to reproduce them, ensure that the instance types are based on the Nitro system (all instance types, except C1, M1, M2, M3, and T1) to handle IPv6 traffic. The route tables should be configured to route internet traffic to the appropriate gateway. The security groups of the instances should allow the traffic from the internet or between instances within the VPC, and the NACL should not deny traffic.</p><h4><strong>IPv6 traffic from public dual-stack instance to the Internet</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*K5FLlVXId_NtN59MrzTZuQ.png" /></figure><h4><strong>IPv4 and IPv6 traffic from the Internet to public dual-stack instance</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*fvDjycqytbpCSbQyz9BA7A.png" /></figure><p><em>To test this, run the following commands on your EC2 instance:</em></p><pre>sudo yum install httpd -y<br>sudo service httpd start</pre><h4><strong>IPv4 and IPv6 traffic from public dual-stack instance to private dual-stack instance</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Ok6KuKfHOWsZyaT2WmWVxA.png" /></figure><h4><strong>IPv6 traffic from public dual-stack instance to private IPv6-Only instance</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*rbhuDRrhwwW2RroWKHDucA.png" /></figure><h4><strong>IPv6 traffic from private IPv6-Only instance to the Internet</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*EZIDJ06wc-e7iKP4fPvjrQ.png" /></figure><p><em>For this test, I SSHed from apublic dual-stack instance to the private IPv6-only instance, then launched IPv6 traffic to the internet from the private instance.</em></p><p>I hope this article gave you a clear overview of dual-stack VPCs and helps you make informed decisions for your AWS infrastructure.</p><p>AWSharing: Together, We Keep Growing! ❤️💪🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65bf7a77474c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS VPC with single and multiple IPv4 CIDR blocks]]></title>
            <link>https://medium.com/@meriemiag/exploring-ipv4-vpc-components-with-single-and-multiple-cidr-blocks-3f68e705b112?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f68e705b112</guid>
            <category><![CDATA[ipv4]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[aws-nacl]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-security-group]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 03:56:54 GMT</pubDate>
            <atom:updated>2024-06-11T14:28:48.643Z</atom:updated>
            <content:encoded><![CDATA[<p>Building a strong network is crucial for any successful solution, impacting how well it scales and performs in the future. Therefore, when designing a solution in AWS, it’s crucial to understand how to effectively create and manage the network where resources will be deployed. One of the fundamental services to master for this purpose is Amazon Virtual Private Cloud (VPC), which allows you create isolated networks with full control over the virtual networking environment.</p><p>This article is the first in a two-part series designed to provide an in-depth understanding of VPC components and how to tailor them to meet your specific needs in AWS. The series will cover:</p><ol><li>VPC with single and multiple IPv4 CIDR blocks</li><li><a href="https://medium.com/@meriemiag/understanding-dual-stack-vpc-in-aws-65bf7a77474c">Dual-stack VPC</a></li></ol><p>In this first article, we will focus on detailing the components of an IPv4 VPC with a single CIDR block. We will also explore the implications and adjustments required when extending an IPv4 VPC to include multiple CIDR blocks, ensuring you have the knowledge to manage and scale your network effectively within AWS.</p><h3>Creating a VPC with a Single IPv4 CIDR Block</h3><p>AWS VPC (Amazon Virtual Private Cloud) is a service that enables the creation of private and isolated networks within AWS in order to launch and manage your resources. Think of it as your private apartment within a larger building: you have your own space, and you control what happens inside, ensuring no one can access it without your authorization.</p><h4><strong>VPC Design Considerations</strong></h4><p>When designing a VPC, several decisions need to be made according to the solution’s requirements. You must decide on the region where the VPC will be created, the size of the VPC, how it will be segmented, the distribution of resources within the network, and how these resources will interact both within the VPC and with external networks. Once these decisions are made, the next step is to implement them within the VPC service.</p><h4><strong>VPC region</strong></h4><p>A VPC is a regional resource, meaning it belongs to a specific AWS region and spans all its availability zones. Choosing the right region is crucial for reducing latency, ensuring compliance with regional data residency laws, optimizing costs, and guaranteeing the availability of required AWS services and features.</p><h4><strong>VPC size</strong></h4><p>When designing your VPC, consider the number of IP addresses you’ll need, potential connections with on-premises networks or other VPCs, and future scalability. This helps you choose the correct CIDR block (Classless Inter-Domain Routing) for your VPC.</p><p>In AWS, it is mandatory to specify an IPv4 CIDR block for the VPC, with a size between a /16 netmask and a /28 netmask.</p><h4><strong>VPC Subnets</strong></h4><p>Subnets in AWS VPC are used to divide a VPC into multiple logical networks, giving you full control over their size, location, and access. Subnets are zonal resources, meaning you choose in which Availability Zone (AZ) within your VPC you want to create each subnet. You also define the size of each subnet by specifying a range of IP addresses (CIDR block) from the VPC’s CIDR block range. You should consider that there are five reserved IP addresses in each subnet (the first four and the last one of each subnet CIDR block). You can create multiple subnets within your VPC, as long as their CIDR blocks do not overlap.</p><p>Subnets enable you to place your resources strategically within a VPC and manage access control based on your architectural needs. Resources with different access requirements should be placed in different subnets. For example, resources that need to be reachable from the internet, such as web servers, should be placed in public subnets, which have access to the internet. In contrast, resources that need to be secured, such as databases, should be placed in private subnets, which do not have direct internet access.</p><h4><strong>VPC Gateways</strong></h4><p>To configure public or private subnets within a VPC, specific gateway components must be set up correctly to ensure resource access aligns with your solution’s requirements.</p><p><strong>Internet Gateway</strong></p><p>An Internet Gateway is a horizontally scaled, redundant, and highly available VPC component that makes your resources reachable from the internet and enable them to initiate communication with the internet.<strong> </strong>You only need one Internet Gateway attached to your VPC.</p><p><strong>NAT gateway</strong></p><p>A NAT (Network Address Translation) gateway allows instances in a private subnet to initiate outbound IPv4 traffic to the internet while preventing inbound traffic initiated by the internet. Alternatively, a NAT instance can be used, which is a less expensive solution but you need to manage the instance yourself.</p><h4><strong>VPC route tables</strong></h4><p>VPC route tables define how traffic flows within a VPC and between the VPC and external networks. They contain a set of rules, known as routes. A route consists of a destination and a target. The destination is the IP range that the traffic is being sent to, and the target is the network interface or gateway through which the traffic is sent. When a source tries to reach a destination, it looks up the route table and routes the traffic to the target based on the configured routes. This process ensures that traffic is correctly directed within the VPC and to external networks.</p><p><strong>Main Route Table</strong></p><p>A main route table is automatically created when you create a VPC. It includes a local route, allowing traffic to flow between subnets within the VPC. By default, when you create a new subnet, it is implicitly associated with this main route table. The main route table cannot be deleted, but it can be customized by adding or removing routes.</p><p><strong>Custom Route Tables</strong></p><p>You can create custom route tables and associate them with specific subnets, overriding the default association with the main route table.</p><h4><strong>Public Subnet</strong></h4><p>When resources in a subnet need to be reachable from the Internet, they must be placed in a public subnet. By default, newly created subnets are private, so certain configurations at the VPC, subnet, and resource levels are required to make a subnet public and its resources accessible from the Internet.</p><p>You have to attach an Internet Gateway to the VPC to have a gateway to the Internet. Then, update the route table associated with the subnet by adding a route that directs traffic destined for the Internet to the Internet Gateway. Specifically, the route destination should be 0.0.0.0/0, which represents all Internet traffic, and the target should be the Internet Gateway ID.</p><p>With these configurations, the subnet is considered a public subnet. However, this does not automatically make all resources public. Each resource that needs to communicate with the Internet must have a public IP address or elastic IP address.</p><p><strong>Elastic IP address</strong></p><p>Public IP addresses assigned to your resources by AWS are temporary and not tied to your account. They are returned to the AWS pool when no longer in use. If you need a static public IPv4 address, you should use an Elastic IP (EIP) which remains associated with your account until you explicitly release it. This ensures continuity even if instances are stopped and restarted or fail.</p><h4><strong>Private subnet</strong></h4><p>Resources in a private subnet have private IP addresses and can communicate with other resources within the same VPC but cannot directly access the Internet or receive inbound traffic from the Internet. However, private resources may need to reach the Internet for tasks such as downloading software, accessing container images, or accessing public AWS services.</p><p>In this case, you need to create a NAT Gateway in a public subnet and assign it an elastic IP. Then, update the private subnet route table by adding a route to the NAT Gateway for traffic going to the internet.</p><p><em>Note: NAT Gateways are deployed in a specific subnet and provide redundancy at the Availability Zone level. For high availability, you should create NAT Gateways in each Availability Zone used by your VPC.</em></p><p>A picture is worth a thousand words 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*QDV6Y-GSylhR36vK6luQuQ.png" /></figure><h3>VPC traffic control</h3><p>While the configurations we’ve covered make communication possible, it is not permitted by default until explicitly allowed at both the subnet and instance levels.</p><p>Security groups (SG) and Network Access Control Lists (NACLs) are two security layers in a VPC that act as virtual firewalls to protect your network.</p><p><strong>NACL</strong></p><p>A NACL allows or denies specific inbound or outbound traffic at the subnet level using defined rules. NACL rules are evaluated when traffic enters or leaves the subnet, applying control to all resources within the associated subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*s9Lyu2_OeYyJI5Dwi2vENA.png" /><figcaption>NACL</figcaption></figure><p>Each subnet in your VPC must be associated with a single NACL. You can associate a NACL with multiple subnets. If you don’t explicitly associate a subnet with a NACL, it is automatically associated with the default NACL created by default in each VPC. The default NACL is configured to allow all traffic to flow in and out of the subnets with which it is associated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*EKy_kfQWU1HpKYQSiQEpgg.png" /><figcaption>Default NACL of a VPC with one IPv4 CIDR bloc</figcaption></figure><p>In a NACL rule, you specify the rule number, the type of traffic, the protocol, the source or destination of the traffic, and whether to allow or deny the specified traffic. Each rule has a number from 1 to 32766. The rules are evaluated in order, starting with the lowest numbered rule. If the traffic matches a rule, the rule is applied regardless of any higher-numbered rule that might contradict it. NACL rules only allow CIDR blocks as a source or destination.</p><p>NACLs are stateless, meaning that when traffic is allowed in one direction (inbound or outbound), responses to that traffic are not automatically allowed. Therefore, you must define your NACL rules carefully to ensure that legitimate traffic can both enter and leave the subnet as required.</p><h3>Security Groups (SGs)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*55MugJcBFif6di5PlbnNcQ.png" /><figcaption>Security Groups</figcaption></figure><p>Security Groups operate at the instance level, managing both inbound and outbound traffic through defined rules. These rules specify the protocol, port or port range, and the source or destination of the traffic. The protocol can be common ones like SSH, HTTP, or HTTPS, or custom protocols. The source or destination can be an IPv4 address, CIDR block, security group, or a prefix list. A specific IPv4 address is given with the /32 prefix. Specifying a security group as the source allows instances associated with this SG to communicate with your instance using the defined protocol and port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*ky7c_SshDDWXn9SDG5Brqg.png" /><figcaption>SG sources</figcaption></figure><p>SGs are stateful, meaning if traffic is allowed in one direction (inbound or outbound), the response traffic is automatically allowed. Each security group can be linked to multiple instances in a VPC, and each instance must be associated with at least one security group. The rules from all associated security groups are aggregated to determine access.</p><h4><em>Note:</em></h4><p><em>Security Groups are technically associated with Elastic Network Interfaces (ENIs), so they can be applied not only to EC2 instances but also to other resources such as RDS instances and Application Load Balancers (ALBs).</em></p><h3><strong>Expanding VPCs with Multiple CIDR Blocks</strong></h3><p>In the first part of this article, we discussed the basics of creating a VPC with a single IPv4 CIDR block. As your network grows, you may need to scale your VPC to accommodate more resources. One way to achieve this is by adding additional CIDR blocks to your VPC. This section provides an overview of VPC with multiple CIDR blocks and outlines the changes compared to a VPC with only one IPv4 CIDR block.</p><h4><strong>Adding Secondary CIDR Blocks</strong></h4><p>A VPC must have an associated IPv4 CIDR block, which cannot be decreased or increased once set. However, to accommodate growth and scalability, you can optionally associate additional IPv4 CIDR blocks.</p><p>By default, your VPC can have up to five IPv4 CIDR blocks: one primary and four secondary blocks. The CIDR blocks must not overlap with any existing CIDR block associated with the VPC. There are <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-cidr-blocks.html">specific restrictions</a> on choosing secondary CIDR blocks based on your primary CIDR block.</p><p>Secondary CIDR blocks can be removed after deleting all resources and subnets associated with them. However, this is not possible for the primary CIDR block, which remains a permanent part of the VPC configuration.</p><p><strong>Route table changes</strong></p><p>Upon associating a secondary CIDR block with your VPC, a new local route is automatically added to all VPC route tables. This route has the destination set to the newly added CIDR block, enabling internal routing within the VPC.</p><p><strong>Subnets</strong></p><p>You can create subnets from any of the VPC’s CIDR blocks, whether they are primary or secondary. The process for configuring public and private subnets remains unchanged compared to the configuration in a VPC with a single IPv4 CIDR block. Subnets created from different CIDR blocks can communicate with each other within the same VPC if permitted by the NACL and SG configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*o_5y4gBgDY8CyjzkpNRMlg.png" /><figcaption>Changes after adding new IPv4 CIDR block</figcaption></figure><p><strong>VPC Traffic Control</strong></p><p>With the addition of new CIDR blocks, it’s crucial to revisit your VPC’s traffic control settings. Review and update SGs to ensure they allow communication between resources from different CIDR blocks. Similarly, adjust NACLs to permit or deny traffic between subnets from different CIDR blocks as required.</p><p>AWSharing: Together, We Keep Growing! ❤️💪🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f68e705b112" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure File Uploads and Downloads in S3 Using Presigned URLs]]></title>
            <link>https://medium.com/@meriemiag/secure-file-uploads-and-downloads-in-s3-using-presigned-urls-a47351a4753e?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a47351a4753e</guid>
            <category><![CDATA[presigned-url]]></category>
            <category><![CDATA[upload]]></category>
            <category><![CDATA[download]]></category>
            <category><![CDATA[s3]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Tue, 04 Jun 2024 03:44:44 GMT</pubDate>
            <atom:updated>2024-06-04T04:27:44.056Z</atom:updated>
            <content:encoded><![CDATA[<p>When deciding the visibility of an S3 bucket, it’s crucial to consider the security requirements of your application and the intended use of the files. Sometimes, we face conflicting needs: maintaining a private bucket for security while allowing users or applications to read or upload files directly in S3.</p><p>Possible solutions include providing AWS credentials or IAM permissions to each entity that needs access, which is impractical, or making the bucket public, which compromises security. A more effective solution is to use presigned URLs. They allow you to keep your bucket private while granting temporary read or upload permissions for specific objects to users or applications. This ensures secure, controlled access without compromising the bucket’s privacy.</p><p>In this article, I will focus on using presigned URLs for uploading and downloading files, which are the most common use cases. However, presigned URLs can also be used for other operations. I will explain what an S3 presigned URL is, discuss the GET and PUT presigned URLs, explore various ways to generate them, and conclude with a simple React app example that uploads files to a private S3 bucket using a presigned URL generated by a Lambda function.</p><h3><strong>S3</strong></h3><p>S3 (Simple Storage Service) is AWS object storage service. It is one of the most widely used AWS services due to its ability to handle various use cases, its scalability, data availability, performance, and security. For security, you can configure your bucket to be public, private, or grant specific users access to perform certain actions, either permanently or temporarily. This flexibility makes S3 suitable for a wide range of applications while ensuring data protection and access control.</p><h3>S3 Presigned URL</h3><p>When you create an S3 bucket, it is private by default, and it is up to you to change this setting based on your needs. If you want a user to upload or download files in a private bucket without making the bucket public or requiring AWS credentials or IAM permissions, you can create a presigned URL.</p><p>Presigned URLs work even if the bucket is public, but the main purpose of presigned URLs is to help you keep objects private while allowing limited and controlled access when necessary.</p><p>A presigned URL is an URL that grants temporary access to a specific object in an S3 bucket. It is generated for a specific object key within a specific S3 bucket, with an expiration time and a specified HTTP method (Get or Put).</p><p><strong>Requirements for Generating Presigned URLs</strong></p><p>A presigned URL must be generated by an AWS user or an AWS application that has access to the bucket and the object in the bucket at the time of creation. Generating a presigned URL does not require a call to the S3 service APIs. When a user makes an HTTP call with the presigned URL, AWS processes the request as if it was performed by the entity that generated the presigned URL.</p><p><strong>Usage and Expiration</strong></p><p>Presigned URLs can be shared with temporarily authorized users to allow them to download or upload objects. They can only be used for the method specified when generating the URL. For example, a GET presigned URL cannot be used for a PUT operation.</p><p>There is no default limit on the number of times a presigned URL can be used until it expires.</p><h3><strong>Get presigned URLs</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*yUyUB8qW46nQRSYA3k7Kwg.png" /></figure><p>Get presigned URLs are particularly useful for scenarios involving file sharing, secure download links and temporary access. For example, an educational platform can provide downloadable study materials to students using presigned URLs. A photographer can share high-resolution images with a client securely. A software company can distribute updates to its clients.</p><p>A GET presigned URL can be used directly in a browser or integrated into an application or webpage to download an object from an S3 bucket. It can be generated using the AWS Management Console, AWS CLI, or AWS SDK.</p><p>In the following, I will demonstrate how to generate a GET presigned URL using the AWS Management Console.</p><p><strong>Generating Get presigned URL with the console</strong></p><ol><li>Choose the option “<em>Share with a presigned URL</em>” for your private object</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*GkmvkffmnMLl1NLgf8smKQ.png" /></figure><p>2. Define the expiration time of the presigned URL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*UGkq5EP-2I9sBybNKb7oNw.png" /></figure><p>3. Access the private object using the presigned URL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*k6_eN0YM-asu1YAYj597Rw.png" /></figure><p><strong>Accessing a private object using object URL or presigned URL after expiration</strong></p><p>Attempting to access a private object using its direct URL or a presigned URL after it has expired will result in an access denied message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*Pcdh_opxSFjh27Rea8zuwQ.png" /></figure><h3><strong>Put presigned URLs</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*Qlily3zxB4d33fkm30q1BQ.png" /></figure><p>Put Presigned URLs are commonly useful for scenarios where direct client-side uploads are beneficial. For instance, a social media platform can allow users to upload profile pictures directly to S3, bypassing the application server. An insurance company can enable clients to submit claim documents. A video-sharing platform can facilitate content creators in uploading their videos</p><p>When someone uses the Put presigned URL to upload an object, Amazon S3 creates the object in the specified bucket. If an object with the same key already exists in the bucket, Amazon S3 replaces the existing object with the newly uploaded object.</p><p>Put presigned URLs are typically generated using the AWS SDK. In the following section, I will show you how to generate a presigned URL using a Python script available in my <a href="https://github.com/mariemssi/Presigned_URL">GitHub repository </a>and how to use it.</p><p><strong>Generating Put presigned URL using python script</strong></p><p>The Python script “<em>generate_presigned_url.py</em>” is available in my GitHub repository <a href="https://github.com/mariemssi/Presigned_URL/blob/main/python_code_to_generate_put_presigned_url/generate_put_presigned_URL.py">here</a>.</p><p><strong><em>Steps to Generate and Use a Presigned URL</em></strong></p><ol><li>Copy the Python script from my repository.</li><li>Run the following command to generate the presigned URL:</li></ol><pre>python generate_put_presigned_url.py your-bucket-name your-object-key --expiration 3600</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*IcfmXXQE2Ifd54t87iCXRw.png" /></figure><p>3. Use the generated presigned URL to upload the file.</p><p>Ensure that the object key to upload and the bucket name where you need the upload match those used in the previous command to avoid errors. You can use tools like curl or Postman for this purpose.</p><pre>curl -X PUT -T &quot;/path/to/your-file.extension&quot; &quot;$PRESIGNED_URL&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*NBEzhTkJCxCQfkvjK2dAxw.png" /></figure><h3><strong>A simple use case: React app file upload using presigned URL generated by lambda function</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*KN_dldcU2qrwwlHdrSoa7g.png" /><figcaption>Simple React app file upload using presigned URL generated by lambda function</figcaption></figure><p>In this section, I show you how to set up a simple React application that allows users to upload files directly to an Amazon S3 bucket using Put presigned URLs generated by an AWS Lambda function. I used a public S3 bucket for hosting the frontend react code, which directly calls a lambda function via its URL to generate the presigned URL. This presigned URL is then used to upload files to a private S3 bucket.</p><p><strong>Lambda function URL</strong></p><p>The frontend calls the Lambda function using the Lambda function URL. A function URL is a dedicated HTTP(S) endpoint for your Lambda function. You can create and configure a function URL through the Lambda console or the Lambda API. Once created, the URL endpoint of the function URL never changes.</p><p><em>Note that, currently, function URLs are not supported in all regions, and they can only be accessed through the public Internet.</em></p><p><strong>CORS</strong></p><p>Cross-Origin Resource Sharing (CORS) defines a way for client web applications loaded in one domain to interact with resources in a different domain. To configure your bucket to allow cross-origin requests, you add a CORS configuration to the bucket.</p><p>A CORS configuration is a document that defines rules identifying the origins that are allowed to access your bucket, the HTTP methods supported for each origin, and other operation-specific information.</p><p><strong>Steps to set up the simple app</strong></p><p><strong><em>A. Create the private S3 bucket</em></strong></p><p>1. Create the private S3 bucket that will store the uploaded documents. This will be referred to as the “<em>Documents bucket</em>”.</p><p>2. Setup the CORS configuration of this bucket to allow interaction between «<em>Frontend bucket</em>» and «<em>Documents bucket </em>». You can defer this step until after enabling the website feature for «<em>Frontend bucket</em>» if you want a more restrictive CORS policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*zvrn8fvOOF6k-OfABlQqHw.png" /></figure><p><strong><em>B. Create lambda function</em></strong></p><p>1. Create the lambda function that will generate the presigned URL for the files that we want to upload. I name it “<em>put_presigned_URL_generator</em>”</p><p>2. Add the Lambda function code from <a href="https://github.com/mariemssi/Presigned_URL/tree/main/simple_react_app_using_lambda_to_generate_put_presigned_url/lambda_python_code">here</a></p><p>3. Update the lambda function role. Since the Lambda function generates the presigned URLs, the permissions assigned to the Lambda function will be those used by the presigned URL. Therefore, the Lambda role should include permissions for the put actions for &quot;<em>Documents bucket</em>&quot;.</p><p>4. Go to the configuration section and enable the Function URL for your Lambda function with the authentication type of NONE</p><p>5. Add the name of the “<em>Documents bucket</em>” to the environment variables of your Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*GYJZiCEqgqIlJP3QGzGExw.png" /></figure><p><strong><em>C. Create the S3 frontend bucket</em></strong></p><p>1. Create an S3 bucket to host the react app. I name it «<em>Frontend bucket</em> »</p><p>2. Change the settings of «<em>Frontend bucket</em>» to make it to public. This involves disabling block public access and updating the bucket policy to allow public access.</p><p>3. Clone the React application code from my GitHub repository <a href="https://github.com/mariemssi/Presigned_URL/tree/main/simple_react_app_using_lambda_to_generate_put_presigned_url/react_frontend">here</a>.</p><p>4. Replace the placeholder Lambda function URL in the code with your actual Lambda function URL.</p><p>5. Build your React app by running npm run build and upload the contents of the build folder to &quot;<em>Frontend bucket</em>&quot;. You can use the following command:</p><pre>aws s3 sync build/ s3://your-frontend-bucket-name</pre><p>6. Enable the static website hosting feature for «<em>Frontend bucket</em>» and set the index.html file as the index document for the website</p><p>7. Access the bucket website endpoint to test the solution and ensure everything is working correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*0VhN-gtXk6lh1viCw_0u9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*lHKU-GLmFroWMtBwHm-SdQ.png" /></figure><p><strong><em>To go further</em></strong></p><p>This simple app provides a basic overview of how Lambda and S3 presigned URLs can be used for secure file uploads. However, for enhanced security and functionality, additional layers should be implemented to ensure that only authenticated users can generate presigned URLs.</p><p>I hope this guide helps you implement secure file management in your projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a47351a4753e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reduce AWS Costs by Stopping Idle EC2 Instances with CloudWatch Alarms]]></title>
            <link>https://medium.com/@meriemiag/reduce-aws-costs-by-stopping-idle-ec2-instances-with-cloudwatch-alarms-ecca40ebf85a?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecca40ebf85a</guid>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[sns]]></category>
            <category><![CDATA[cloudwatch-alarm]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Mon, 27 May 2024 01:46:34 GMT</pubDate>
            <atom:updated>2024-05-27T02:04:33.222Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing cloud resources efficiently is crucial for anyone using cloud services, especially when it comes to controlling costs. One common issue is forgetting to stop EC2 instances used for purposes, such as development, testing, or temporary workloads, which can lead to unexpectedly high bills.</p><p>In my case, I have an EC2 instance where I installed tools specifically for testing purposes. This instance is used for short periods. After completing my tasks, I usually stop the instance. However, sometimes I get distracted or move on to other tasks and forget to stop it 😓. When I return, I’m surprised to find it still running, which increases my billing 😲.</p><p>To solve this, I realized I can’t rely solely on myself to remember to stop the instance and I have to automate it. The solution I found is to create a CloudWatch alarm that automatically stops the instance if it detects no activity for 1 hour, ensuring I only pay for what I actually use.</p><p>In this article, I will share this solution with you. I will start by introducing the CloudWatch alarm then I will provide a step-by-step guide on configuring the alarm both through the AWS Management Console and using Terraform to automatically stop an inactive EC2 instance.</p><h3><strong>Cloudwatch Alarm</strong></h3><p>Amazon CloudWatch is a monitoring service for AWS. It serves as a centralized repository for metrics and logs that can be collected from AWS services, custom applications, and on-premises applications. One of its important features is CloudWatch Alarms, which allows you to configure alarms based on the collected data.</p><p>A CloudWatch alarm checks the value of a single metric, either simple or composite, over a time period you specify and launches the actions that you specify once the metric reaches a threshold that you define.</p><p>Imagine CloudWatch Alarms as a security camera specifically watching your front door. Its job is to track the door’s status — whether it’s open or closed. When the camera detects an unusual event, such as the door being left open for too long, it triggers an alarm to alert you. Similarly, CloudWatch Alarms monitor specific metrics of your AWS resources, like CPU usage. If a metric exceeds a predefined threshold — just like the door being left open — the alarm is triggered, notifying you of the issue so you can take action.</p><h3><strong>Key Components of CloudWatch Alarms</strong></h3><ol><li><strong>Metric</strong> : A metric is performance data that you monitor over time. Like a variable that will have different values over time, the variation in these values is important to make decisions to ensure that the application works as it should. Metrics can include CPU utilization, disk I/O, memory usage, and custom application metrics. They are collected at regular intervals and stored in CloudWatch.</li><li><strong>Threshold</strong> : This is the value against which the metric data is evaluated. For example, you might set a threshold of 70% CPU utilization. Depending on whether the metric value is under, equal to, or greater than the threshold, you can trigger actions.</li><li><strong>Period (in seconds)</strong> : The period determines the frequency at which the value of the metric is collected. This can range from seconds to several hours, depending on your needs.</li><li><strong>Statistic</strong> : This specifies how the metric data is aggregated over each period. Common statistics include Average, Sum, Minimum and Maximum. If the metric is collected every minute and you choose an alarm period of 5 minutes, the metric value for each period will be calculated as the average of the 5 values collected within the 5-minute period.</li><li><strong>Evaluation Periods</strong> : The number of recent periods that will be considered to evaluate the state of the alarm, based on the metric values during these periods.</li><li><strong>Datapoints to Alarm</strong> : The number of evaluation periods during which the metric must breach the threshold to trigger the alarm. For instance, if you have 3 evaluation periods and set 2 datapoints to alarm, the threshold must be breached in at least 2 of the 3 periods to trigger the alarm.</li><li><strong>Alarm Actions</strong> : Actions that are taken when the alarm state changes. These can include sending notifications via Amazon SNS, stopping, terminating, or rebooting an EC2 instance, invoking an AWS Lambda function, or performing an Auto Scaling action. Multiple actions can be configured for a single alarm.</li></ol><h3><strong>Cloudwatch alarm example</strong></h3><p>Let’s consider an example to illustrate the role of each of the components of a cloudwatch alarm and the evaluation of the alarm state over time.</p><p>The alarm example is set to monitor the average CPU utilization of an EC2 instance. The CPUUtilization metric is collected and aggregated into 5-minute periods. The alarm evaluates the average CPU utilization over 3 consecutive periods. If the average CPU utilization exceeds the threshold of 70% for at least 2 out of the 3 evaluation periods, the alarm triggers the defined actions.</p><ul><li><strong>Metric</strong> : CPUUtilization</li><li><strong>Statistic</strong> : Average</li><li><strong>Period</strong> : 300 seconds (5 minutes)</li><li><strong>Threshold</strong> : 70%</li><li><strong>Alarm condition</strong> : Greater or Equal</li><li><strong>Evaluation Periods</strong> : 3</li><li><strong>Datapoints to Alarm</strong> : 2</li></ul><p>The table below illustrates how the alarm will be triggered over time :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*DkoiqspH465S01NZyzmOSA.png" /></figure><p>In this example, the average CPU utilization exceeds the 70% threshold in period 3 but doesn’t trigger the alarm because the threshold is exceeded only in 1 out of 3 evaluation periods (65–60–70). The average CPU utilization exceeds the 70% threshold again in period 5, which is the second exceedance in the evaluation periods (70-60-75), So the alarm is triggered and goes into the ALARM state.</p><h3><strong>Setting Up a CloudWatch Alarm to Automatically Stop Inactive Instances</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*G5i935-sXwa2IiD2F5PWPw.png" /></figure><p>The metric that I choose to detect an inactive instance is CPUUtilization, which is collected by default every 5 minutes and sent to CloudWatch. The alarm is triggered only if the CPU utilization remains below 2% at any period during one hour (12 consecutive periods of 5 minutes each). The actions triggered by the alarm are stopping the instance and notifying me by email.</p><ul><li><strong>Metric</strong> : CPUUtilization</li><li><strong>Statistic</strong> : Average</li><li><strong>Period</strong> : 300 seconds (5 minutes)</li><li><strong>Threshold</strong> : 2%</li><li><strong>Alarm condition</strong> : Lower or Equal</li><li><strong>Evaluation Periods</strong> : 12</li><li><strong>Datapoints to Alarm</strong> : 12</li><li><strong>Actions</strong> : SNS mail notification + EC2 stop Instance</li></ul><h3><strong>Solution with Console</strong></h3><h4>Step 1. Specify metric and conditions</h4><p>Select the <strong>CPUUtilization</strong> metric of the instance that you need to monitor, then specify the conditions for the alarm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*h1GmJ2SjYT1ALVG-N3LvMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*fTSePLllzZe9BlgHSy1Qow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ihDr2qKmwGATx_AYTfpu8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Bs_QZFqcwaVTGbEuSD7zaA.png" /></figure><h4>Step 2. Configure actions</h4><p>The first action is to send a notification to an SNS topic with an email subscription. This ensures that you will be notified when the alarm stops the instance. You can create the SNS topic at this step, or you can reference an existing one if you have already created it.</p><p>The second action is to stop the instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*bP0LyvUkGV6_Qo_13uQe0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*mCN5D_z1OssLKsmCdJxZFQ.png" /></figure><h4>Step3. Add name and description</h4><p>Provide a name for the alarm, and you can also add a description</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*2zaUcg2GuEgk-0bm2Q0ReA.png" /></figure><h4>Step4. Preview and create</h4><p>Review a summary of all your configurations. If everything is correct, confirm the alarm creation.</p><p>The result should look like the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*vVG8eybNEF2FD5OLw_UbYA.png" /></figure><p>An alarm can have the state «<strong> Insufficient data</strong> » when it is newly created or when there is not enough data to determine the alarm state based on the specified criteria.</p><p>The<strong> warning</strong> text is : « This action sends a message to an SNS topic with an endpoint that is pending confirmation. It will not work as expected until the endpoint is confirmed. Look for a subscription confirmation email or review the topic in SNS. » . This message is about confirming the subscription of your email to the created SNS topic. You should open the email that you received in your inbox (the email address provided when you created the SNS topic) and confirm the subscription.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*1I7Vqqkz64n1QEvgBNe3KA.png" /></figure><p>After confirming the subscription and the alarm reaches the specified metrics, you should have a result like the screenshot below. All is fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*zWHJMIjSz4xGNthIZU3dlg.png" /></figure><p>The CloudWatch alarm is correctly set up and ready to trigger actions once it meets the conditions. In that case, you will see a result like the screenshots below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ldg8gpoLUQvOakxLmhrdaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*l7Ow3fQ4m_oMFvZFOPDsww.png" /></figure><h3><strong>Solution with terraform</strong></h3><p>If you want a quick, automated, and consistent way to set up your CloudWatch alarm, using Terraform is an excellent choice. Below, I present the main files which are the cloudwatch_alarm.tf and sns.tf files. You can find the complete Terraform code in my <a href="https://github.com/mariemssi/CloudWatch_Alarm_To_Stop_Inactive_EC2_Instance">GitHub repository</a>.</p><pre>resource &quot;aws_cloudwatch_metric_alarm&quot; &quot;ec2_cpu_alarm&quot; {<br>  comparison_operator       = &quot;LessThanOrEqualToThreshold&quot;<br>  evaluation_periods        = &quot;12&quot;<br>  datapoints_to_alarm       = &quot;12&quot;<br>  metric_name               = &quot;CPUUtilization&quot;<br>  namespace                 = &quot;AWS/EC2&quot;<br>  period                    = &quot;300&quot; #seconds<br>  statistic                 = &quot;Average&quot;<br>  threshold                 = &quot;2&quot;<br>  alarm_description         = &quot;This alarm stops the EC2 instance if it remains inactive for one hour.&quot;<br>  treat_missing_data        = &quot;missing&quot;<br>  insufficient_data_actions = []<br>  alarm_actions             = [aws_sns_topic.topic.arn, &quot;arn:aws:automate:${var.region}:ec2:stop&quot;]<br><br>  alarm_name = &quot;stop_test_instance_alarm&quot;<br>  <br>  dimensions = {<br>    InstanceId = var.instance_ID<br>  }<br>}</pre><pre>resource &quot;aws_sns_topic&quot; &quot;topic&quot; {<br>  name = &quot;stop_test_instance_alarm_topic&quot;<br>}<br><br>resource &quot;aws_sns_topic_subscription&quot; &quot;topic_email_subscription&quot; {<br>  topic_arn = aws_sns_topic.topic.arn<br>  protocol  = &quot;email&quot;<br>  endpoint  = var.email_address<br>}</pre><p>After all resources are created, you need to confirm the subscription to the created SNS topic by following the instructions in the email received in your inbox (like described in the console solution).</p><p>I hope this article assists you in efficiently managing your EC2 instances by preventing unnecessary usage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecca40ebf85a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Ways to Connect to RDS MySQL Database]]></title>
            <link>https://medium.com/@meriemiag/exploring-ways-to-connect-to-mysql-rds-database-102aec995673?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/102aec995673</guid>
            <category><![CDATA[remote-access]]></category>
            <category><![CDATA[mysql-workbench]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Mon, 06 May 2024 04:03:18 GMT</pubDate>
            <atom:updated>2024-05-06T14:17:54.970Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon RDS (Relational Database Service) simplifies the process of setting up, managing, and scaling relational databases in the cloud. It currently supports PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, and Db2 databases.</p><p>Direct remote access to RDS databases (RDS DB) is often required for various purposes. Administrators need it for maintenance, debugging, or troubleshooting, while developers require it when defining the schema or inserting initial data into their databases for testing purposes.</p><p>This article presents various methods to connect to MySQL RDS database and run SQL queries for defining the schema and initializing the database, depending on whether it is hosted in a public or private subnet. It covers connecting via MySQL Workbench, command lines, and introduces an automated method employing GitHub Actions to streamline the process, making database management more efficient and hassle-free. All cases can be tested using the Terraform code provided in <a href="https://github.com/mariemssi">my GitHub repo</a>.</p><h3><strong>Public RDS MySQL DB 😱</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ZfVaf2yIFgiDhZ0UOOVRbA.png" /><figcaption>Connection to Public RDS DB</figcaption></figure><p>I know that the title might surprise you! Typically, databases shouldn’t reside in a public subnet, but there are cases, such as testing scenarios, where it’s feasible.</p><p>To establish a connection to an RDS MySQL DB in a public subnet, ensure that the database is operational within a public subnet. Additionally, configure the security group associated with the database to permit inbound traffic on port 3306 from your IP address.</p><p>Once these prerequisites are met, you can connect to the RDS MySQL DB using various methods such as MySQL Workbench or command-line tools.</p><p><strong>Using MySQL Workbench</strong></p><p>MySQL Workbench is a GUI-based application that allows you to connect to a MySQL database. You install it on your computer, providing you with a graphical and user-friendly interface to interact with your database. To use it with an RDS MySQL DB, you should configure the connection parameters as mentioned in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Jj338sJDe9VzJxmJEKxw2Q.png" /><figcaption>Connection to public RDS DB with MySQL Workbench</figcaption></figure><p>Once you successfully establish the connection, you can run SQL queries in your database, as demonstrated in the figure below, with <em>dbtest</em> representing the database name chosen at the creation of the DB RDS instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*62D0-kDfqSDzQ7tbyRxi2A.png" /></figure><p><strong>Would you like to test this method?</strong></p><p>You can simulate the scenario using the Terraform code provided in <a href="https://github.com/mariemssi/Test_Connect_To_Public_RDS-MySQL_DB/tree/main">my GitHub repository</a>. It sets up a custom VPC with two public and private subnets. One of the public subnets contains the RDS MySQL DB (single AZ Instance) with a security group that permits 3306 traffic from anywhere (Can be set up to only allow access from your specific IP address)</p><h3><strong>Private RDS MySQL DB</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcsbQWkKUDsdmnc6vhDt2w.png" /><figcaption>Connexion To private RDS MySQL DB</figcaption></figure><p>The recommended approach for enhanced security involves placing the database in a private subnet where it cannot be accessed directly from the internet. While this isolation adds an extra layer of security, it can present challenges for remote access.</p><p>To connect to this database securely, the solution is to use an intermediate public entity that establishes a private connection with the database. Developers connect to this intermediate entity, which then securely connects to the database.</p><p>This intermediate entity can be a public EC2 instance in the same VPC as the database, used to establish an SSH tunnel to the database. Known as a bastion host, jump box, or jump server, it serves as a controlled access point, allowing authorized users to connect to resources within the private network from remote locations.</p><p>To establish a connection to an RDS MySQL DB located in a private subnet, several prerequisites are necessary. Firstly, ensure that the database is operational within the private subnet. Then, deploy an EC2 bastion host (EC2-BH) within a public subnet. Additionally, you need an SSH private key pair to access your EC2-BH; the corresponding public key should already be configured during the EC2-BH creation process.</p><p>Furthermore, the security group associated with the database must permit SSH traffic from your IP address. Similarly, the security group should allow inbound traffic on port 3306 exclusively from your EC2-BH. This setup ensures secure and controlled access to the RDS MySQL DB while leveraging the bastion host for connectivity from outside the private subnet.</p><p>Once you have these prerequisites in place, you can establish a connection to the RDS MySQL database using MySQL Workbench or command-line tools.</p><p><strong>With MySQL Workbench</strong></p><p>MySQL Workbench offers a method to connect to a private RDS MySQL database via the bastion host. To do so, the connection method to select is: “Standard TCP/IP over SSH” and you should provide the necessary details as shown in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*s8E4I2z0arrcrzXIlNl1Cg.png" /></figure><p>Note: If you encounter any issues with your private key using this method, refer to the solution provided <a href="https://stackoverflow.com/questions/65145221/mysql-could-not-connect-the-ssh-tunnel-access-denied-for-none">here</a>.</p><p>After successfully connecting, you will have the same screen as connecting to a public database using MySQL Workbench and you can run whatever you want in your DB.</p><p><strong>With command lines</strong></p><p><strong>Step1</strong>. SSH into the EC2-BH using the private key</p><pre>ssh -i &quot;path-to-private-key&quot; bastion-host-dns-name</pre><p>The screeshot below demonstrates an SSH connection to an EC2-BH (from another ec2 instance used for testing, but you can use you computer as well)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*O7Tu7YlXuB70S8CeNR9nww.png" /></figure><p><strong>Step 2.</strong> Install MySQL on the EC2-BH if it is not already installed</p><p>You can follow the installation steps <a href="https://www.sammeechward.com/mysql-on-aws-ec2-amazon-linux-2">here</a> and <a href="https://medium.com/@srikar.appal/uninstall-mysql-from-ec2-6910c4597c6">here</a>.</p><p>Alternatively, you can omit this step by including the MySQL installation script in the user data of the EC2-BH. This ensures that MySQL is installed automatically upon instance launch.</p><p><strong>Step3.</strong> Connect to the RDS DB from the EC2-BH</p><pre>mysql -h database-endpoint -p 3306 -u username -p</pre><p>Once connected, you can interact with your database like this screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*-vbMSBguhPbXor2Gb9X2OQ.png" /></figure><p><strong>Would you like to test these two connection methods ?</strong></p><p>Here’s how you can do it: The solution in <a href="https://github.com/mariemssi/Test_Connect_To_Private_RDS-MySQL_DB_1">my GitHub repository</a> guides you through setting up a custom VPC with two public and private subnets. It creates an EC2 bastion host (EC2-BH) in one of the public subnets and an RDS MySQL database (single AZ Instance) in one of the private subnets. The security group of the EC2-BH allows SSH traffic from anywhere, while the database security group only permits 3306 traffic from the security group of the EC2-BH.</p><p><strong>With github actions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0oMXD6OUrW04eW9K" /><figcaption>GitHub actions for connection to private RDS DB</figcaption></figure><p>If you want to avoid repeatedly typing the same commands to connect and initialize your database, automation is the key. GitHub Actions workflows is a solution to automate the execution of command lines for connecting to the database and running SQL queries. These workflows are executed by GitHub runners, which are virtual machines managed by GitHub (can be self hosted). In this scenario, the GitHub runner SSHes into the EC2-BH to connect to the database and then executes SQL queries.</p><p>To establish a connection to a private RDS MySQL DB using GitHub action workflow, along with the prerequisites outlined in the previous section, you’ll also require a GitHub repository and a GitHub Actions workflow.</p><p><strong>Would you like to test it ?</strong></p><p>Here’s how you can do it: The Terraform code in <a href="https://github.com/mariemssi/Test_Connect_To_Private_RDS-MySQL_DB_2">my GitHub repository</a> enables you to create the same infrastructure as described in the previous section. Additionally, there’s a GitHub Actions workflow provided. You need to define the necessary parameters of the workflow to execute the provided SQL script file on the private RDS DB. The test workflow gives you a result similar to the following screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*Ga5QlZF8Gd1CQkCLW6sJhA.png" /></figure><p><strong>Conclusion</strong></p><p>In conclusion, this article has explored various methods for connecting to a MySQL RDS database, in both public and private subnet scenarios.</p><p>Hope you find it helpful 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=102aec995673" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TTS Converter App — Challenge3 — Adding React Frontend (S3, Route53, Cloudfront, ACM)]]></title>
            <link>https://medium.com/@meriemiag/tts-converter-app-challenge3-adding-react-frontend-s3-route53-cloudfront-acm-66936b26ad7f?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/66936b26ad7f</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 00:28:14 GMT</pubDate>
            <atom:updated>2024-05-27T01:47:30.915Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>TTS Converter App — Challenge3 — Adding React Frontend (S3, Route53, Cloudfront, ACM)</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VBCkCMdwlDhqBNRG" /><figcaption>Before challenge 3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aDWPeuCWypg-elie" /><figcaption>After challenge 3</figcaption></figure><p>To make our TTS converter app even better, we’re taking on Challenge 3: Integrating a React frontend with the backend we built in <a href="https://medium.com/@meriemiag/text-to-speech-converter-challenge2-github-actions-workflows-16c59556e6c1">Challenge 2</a>. This means creating a user-friendly interface using React, which will complement the existing backend infrastructure. The frontend will be accessible via a custom HTTPS domain name, distributed through a robust DNS system, and deployed seamlessly in AWS using GitHub Actions workflows and Terraform code.</p><p>In this article, I’ll start by talking about the frontend. After that, I’ll explain the AWS services that are part of this solution. Then, I’ll give steps to help you solve the challenge. Finally, I’ll wrap up by sharing a link to my solution to the challenge.</p><h3><strong>The Frontend</strong></h3><p>The frontend is developed using <a href="https://react.dev/">React</a>, a JavaScript library designed for creating dynamic user interfaces, particularly for single-page applications (SPAs). SPAs offer faster interactions by updating content without reloading the entire page from the server. Instead, they replace only specific parts of the page with new data, maintaining the same URL and avoiding full page reloads. Once built, a React application comprises a collection of JavaScript, CSS, and HTML files</p><h3><strong>AWS Services in the Solution</strong></h3><ul><li><strong>Route53</strong></li></ul><p>Amazon Route 53 is the AWS DNS service. It can be used for domain registration, DNS routing, and health checking.</p><ul><li><strong>AWS Certificate Manager (ACM)</strong></li></ul><p>ACM is an AWS service that makes it easy to obtain and utilize SSL/TLS certificates for your websites. Think of an SSL certificate as an online ID card that verifies your website’s identity. It secures your website and encrypts data transmitted over the internet, ensuring its privacy and security. ACM simplifies the process of obtaining, managing, and renewing these certificates, saving you time and effort. It seamlessly integrates with AWS services such as route53, Elastic Load Balancers, CloudFront, and API Gateway</p><ul><li><strong>S3</strong></li></ul><p>Amazon S3 provides a feature called <strong><em>Static website hosting</em></strong>, which is designed to serve static web assets such as HTML, CSS, and JavaScript files directly from your S3 bucket. This means you can use S3 not just for storage, but also for hosting websites.</p><p>When you build applications using frameworks like React or Angular, they generate static files as output. These files contain all the necessary code, styles, and content needed to run your web application in the browser.</p><p>To deploy your React (or Angular) application to S3, you simply need to upload the build output directory to your S3 bucket and enable the <strong><em>Static website hosting</em></strong> feature on your S3 bucket. This tells S3 to treat the uploaded files as a website and make them accessible via a public URL.</p><p>By leveraging S3 for static website hosting, you can take advantage of its scalability, reliability, and low cost. It provides a simple and efficient way to deploy and serve static web content without the need for complex server setups or maintenance. This makes it an attractive option for hosting websites, single-page applications, and other static assets on the web.</p><ul><li><strong>Cloudfront</strong></li></ul><p>AWS CloudFront is a service that speeds up content delivery to users. It uses caching to optimize performance and enhance content delivery. When a user requests content from a CloudFront distribution, CloudFront checks if the content is already cached at an edge location, which is a worldwide network of data centers. If the content is found in the cache, CloudFront delivers it directly to the user, reducing latency and improving response times.</p><p>Cache settings in CloudFront distributions allow developers to control how content is cached and for how long. By specifying Time-To-Live (TTL) values for objects in the cache, developers can determine how long CloudFront should keep content before refreshing it from the origin server. This helps balance between delivering fresh content and minimizing the number of requests to the origin, optimizing performance and reducing costs.</p><p>CloudFront has the capability to manage content originating from diverse sources such as S3 buckets and API Gateways. This means that developers can leverage CloudFront to efficiently distribute and serve a wide range of content types, including static assets stored in S3 buckets and dynamic data generated by API Gateways. By integrating with CloudFront, these different sources can seamlessly deliver content to end users with low latency and high performance, enhancing the overall user experience.</p><p>By integrating with AWS Certificate Manager (ACM), CloudFront can secure connections with viewers, ensuring safe access via specified domain names and automatically redirecting HTTP traffic to HTTPS for added security.</p><h3><strong>Challenge 3</strong></h3><p>Enhance the TTS Converter app by seamlessly integrating a React frontend with the backend of challenge2, using AWS services, Terraform for infrastructure management, and GitHub Actions for automated deployment</p><h3><strong>Key Actions for Completing the Challenge</strong></h3><ol><li>Clone the repository from <a href="https://github.com/mariemssi/TTS-Converter-Challenge-2">Challenge 2</a>.</li><li>Deploy the backend as per the instructions provided in Challenge 2.</li><li>Create a React frontend for the TTS converter app. You can use the provided code in my <a href="https://github.com/mariemssi/TTS-Converter-Challenge-3">GitHub repository</a> or develop your own.</li><li>Test the connection to your backend API from the React frontend to ensure proper functionality.</li><li>Obtain a custom domain name from Route 53, or use an existing one if available.</li><li>Use Terraform to create the necessary resources:</li></ol><ul><li>An ACM certificate for your custom domain name.</li><li>An S3 bucket to upload the built React app.</li><li>A CloudFront distribution with two origins: your S3 bucket and your API Gateway.</li><li>An OCA (Origin Access Control) for your CloudFront distribution.</li><li>An S3 bucket policy to restrict access to the S3 bucket to the OCA and enhance security</li></ul><p>7. Set up GitHub Actions pipelines to automate the deployment of the Terraform code and the React code. You may want to consider separate pipelines for code and infrastructure deployment.</p><ul><li>For the infra, you need to plan and apply Terraform configurations.</li><li>For the code, you need to install Node.js, install npm dependencies, build your app, deploy it to S3 and invalidate the cache of the cloudfront distribution to ensure that the served content is always up-to-date.</li></ul><p>8. Run your pipelines to deploy the frontend code and infra</p><p>9. Open your web browser and navigate to your domain using HTTPS <a href="https://www.yourdomain.com/">https://www.yourdomain.com</a>.</p><p>10. Proceed to test the application to ensure it runs without any issues.</p><h3><strong>Solution of challenge 3</strong></h3><p>You can find the solution to this challenge in <a href="https://github.com/mariemssi/TTS-Converter-Challenge-3">my GitHub repository</a> and you can try the app via this link: <a href="https://www.buildwithaws.com/">https://www.buildwithaws.com</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zWCnqnQULyVuybVl5TUeDg.png" /></figure><p>If you’ve made it this far, <strong>thank you for reading</strong>! Stay tuned for more exciting challenges and solutions on AWS😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66936b26ad7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to fix : « … operation error S3: DeleteBucket, https response error StatusCode: 409, RequestID…]]></title>
            <link>https://medium.com/@meriemiag/how-to-fix-operation-error-s3-deletebucket-https-response-error-statuscode-409-requestid-4d56e4f96be0?source=rss-2ee5b7b9130e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d56e4f96be0</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Mariem SOUSSI]]></dc:creator>
            <pubDate>Mon, 15 Apr 2024 00:38:02 GMT</pubDate>
            <atom:updated>2024-04-15T00:38:48.509Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to fix : « … operation error S3: DeleteBucket, https response error StatusCode: 409, RequestID: 9JF6N…., HostID: …=, api error BucketNotEmpty: The bucket you tried to delete is not empty »</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNvqIeMnXzVpHcjHa_SI1w.jpeg" /></figure><p>You might come across this error if you make a bucket with Terraform, add files, and then try to delete it using “terraform destroy”.</p><pre>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br>  bucket = &quot;my-tf-test-bucket&quot;<br>}</pre><h3>Why does this happen?</h3><p>When Terraform creates a bucket, it sets the <strong><em>force-destroy</em></strong> option to false by default. This means you need to delete all objects in the bucket before using “terraform destroy.” If you don’t, you’ll encounter this error.</p><h3>How to solve this issue?</h3><p>To fix it automatically, follow these steps:</p><ol><li>Update your Terraform code by adding “force_destroy = true” to your bucket configuration:</li></ol><pre>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br>  bucket = &quot;my-tf-test-bucket&quot;<br>  # To allow destruction of a non-empty bucket<br>  force_destroy = true<br>}</pre><p>2. Run “terraform apply” to apply the changes and make the force destroy option effective. You can target this change only to your resource by using:</p><pre>terraform apply -target=aws_s3_bucket.example</pre><p>3. Now, run “terraform destroy” to delete the bucket:</p><pre>terraform destroy</pre><p><strong><em>Destroy complete! Resources: 1 destroyed.</em> </strong>👏</p><p>Alternatively, you can manually delete all objects in the bucket via the console and then run “terraform destroy.”</p><p>Hope this helps! 😊</p><p><strong>For More details</strong></p><p><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket"><strong>https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d56e4f96be0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>