<?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"><channel><title><![CDATA[AWSBuilder]]></title><description><![CDATA[I’m currently working as FullStack ML developer.

AWS Community Builder.

Former fullstack developer at Surv* ( https://www.survbetter.com/ ). 

ML Specialist c]]></description><link>https://awsbuilder.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1629617271987/B7jD1T8y4.png</url><title>AWSBuilder</title><link>https://awsbuilder.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Mon, 02 Nov 2026 16:02:12 GMT</lastBuildDate><atom:link href="https://awsbuilder.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Hugging Face's Transformers and Amazon SageMaker: A Serverless Inference]]></title><description><![CDATA[To develop a Serverless Inference endpoint, the Hugging Face Inference DLCs and Amazon SageMaker Python SDK will be used. A new feature in SageMaker called…]]></description><link>https://awsbuilder.hashnode.dev/hugging-faces-transformers-and-amazon-sagemaker-a-serverless-inference</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/hugging-faces-transformers-and-amazon-sagemaker-a-serverless-inference</guid><category><![CDATA[AWS]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[huggingface]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Thu, 23 Feb 2023 18:18:45 GMT</pubDate><content:encoded><![CDATA[<p>To develop a Serverless Inference endpoint, the Hugging Face Inference DLCs and Amazon SageMaker Python SDK will be used. A new feature in SageMaker called Amazon SageMaker Serverless Inference lets you scale and deploy machine learning models in a serverless environment. Similar to Amazon Lambda, serverless endpoints dynamically deploy compute resources and scale them up and down based on traffic. For workloads that can handle cold starts and have periods of inactivity in between traffic spikes, serverless inference is perfect. If your traffic is irregular or unpredictable, Serverless Inference with a pay-per-use model is a financially sensible choice.</p>
<p>That's how it works:</p>
<p><img src="https://raw.githubusercontent.com/huggingface/notebooks/01668a894da73efcffbd6b03a3fd80bbfd79d68e/sagemaker/19_serverless_inference/imgs/e2e.png" alt class="image--center mx-auto" /></p>
<p>SageMaker controls the provisioning and management of the compute resources when you construct a serverless endpoint.</p>
<p>After that, you may ask the endpoint for inferences and get model predictions in return.</p>
<p>You only pay for what you use because SageMaker adjusts the computing resources up or down as necessary to handle the volume of your requests.  </p>
<p>Let's begin writing some demo code:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> sagemaker
<span class="hljs-keyword">import</span> boto3
sess = sagemaker.Session()
<span class="hljs-comment"># sagemaker session bucket -&gt; used for uploading data, models and logs</span>
<span class="hljs-comment"># sagemaker will automatically create this bucket if it not exists</span>
sagemaker_session_bucket=<span class="hljs-literal">None</span>
<span class="hljs-keyword">if</span> sagemaker_session_bucket <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">and</span> sess <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
    <span class="hljs-comment"># set to default bucket if a bucket name is not given</span>
    sagemaker_session_bucket = sess.default_bucket()

<span class="hljs-keyword">try</span>:
    role = sagemaker.get_execution_role()
<span class="hljs-keyword">except</span> ValueError:
    iam = boto3.client(<span class="hljs-string">'iam'</span>)
    role = iam.get_role(RoleName=<span class="hljs-string">'sagemaker_execution_role'</span>)[<span class="hljs-string">'Role'</span>][<span class="hljs-string">'Arn'</span>]

sess = sagemaker.Session(default_bucket=sagemaker_session_bucket)

print(<span class="hljs-string">f"sagemaker role arn: <span class="hljs-subst">{role}</span>"</span>)
print(<span class="hljs-string">f"sagemaker bucket: <span class="hljs-subst">{sess.default_bucket()}</span>"</span>)
print(<span class="hljs-string">f"sagemaker session region: <span class="hljs-subst">{sess.boto_region_name}</span>"</span>)
</code></pre>
<h3 id="heading-create-inference-huggingfacemodel-for-the-serverless-inference-endpoint">Create Inference <code>HuggingFaceModel</code> for the Serverless Inference Endpoint</h3>
<p>Our serverless endpoint runs on the distilbert-base-uncased-finetuned-sst-2-english model. This model is a DistilBERT-base-uncased fine-tune checkpoint tuned on SST-2 which is used for topic classification.  </p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> sagemaker.huggingface.model <span class="hljs-keyword">import</span> HuggingFaceModel
<span class="hljs-keyword">from</span> sagemaker.serverless <span class="hljs-keyword">import</span> ServerlessInferenceConfig

<span class="hljs-comment"># Hub Model configuration. &lt;https://huggingface.co/models&gt;</span>
hub = {
    <span class="hljs-string">'HF_MODEL_ID'</span>:<span class="hljs-string">'distilbert-base-uncased-finetuned-sst-2-english'</span>,
    <span class="hljs-string">'HF_TASK'</span>:<span class="hljs-string">'text-classification'</span>
}

<span class="hljs-comment"># create Hugging Face Model Class</span>
huggingface_model = HuggingFaceModel(
   env=hub,                      <span class="hljs-comment"># configuration for loading model from Hub</span>
   role=role,                    <span class="hljs-comment"># iam role with permissions to create an Endpoint</span>
   transformers_version=<span class="hljs-string">"4.17"</span>,  <span class="hljs-comment"># transformers version used</span>
   pytorch_version=<span class="hljs-string">"1.10"</span>,        <span class="hljs-comment"># pytorch version used</span>
   py_version=<span class="hljs-string">'py38'</span>,            <span class="hljs-comment"># python version used</span>
)

<span class="hljs-comment"># Specify MemorySizeInMB and MaxConcurrency in the serverless config object</span>
serverless_config = ServerlessInferenceConfig(
    memory_size_in_mb=<span class="hljs-number">4096</span>, max_concurrency=<span class="hljs-number">10</span>,
)

<span class="hljs-comment"># deploy the endpoint endpoint</span>
predictor = huggingface_model.deploy(
    serverless_inference_config=serverless_config
)
</code></pre>
<p>An HuggingFacePredictor object that can be used to request inference is returned by the.deploy() method. It's simple to submit queries to your endpoint and receive responses thanks to this HuggingFacePredictor.  </p>
<pre><code class="lang-python">data = {
  <span class="hljs-string">"inputs"</span>: <span class="hljs-string">"the mesmerizing performances of the leads keep the film grounded and keep the audience riveted ."</span>,
}

res = predictor.predict(data=data)
print(res)
</code></pre>
<h3 id="heading-clean-up">Clean up</h3>
<pre><code class="lang-python">predictor.delete_model()
predictor.delete_endpoint()
</code></pre>
]]></content:encoded></item><item><title><![CDATA[CI/CD for ML on AWS]]></title><description><![CDATA[The scope of an ML practitioner's duties stops after they have created an ideal ML model, regardless of whether they used the CRISP-DM technique or an…]]></description><link>https://awsbuilder.hashnode.dev/cicd-for-ml-on-aws</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/cicd-for-ml-on-aws</guid><category><![CDATA[AWS]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[ci-cd]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Tue, 27 Sep 2022 04:11:46 GMT</pubDate><content:encoded><![CDATA[<p>The scope of an ML practitioner's duties stops after they have created an ideal ML model, regardless of whether they used the CRISP-DM technique or an AutoML methodology. The ML practitioner simply hands the model off to the various teams in charge of managing and deploying the model in production after their role is finished.</p>
<p>When trying to automate the entire process, this handover causes a disconnect that makes things more difficult. More importantly, this separation frequently affects the overall delivery schedule and delays the project's effective conclusion.</p>
<p>Using a Continuous Integration and Continuous Delivery (CI/CD) approach, the main objective of this article is to illustrate one of the ways to close this apparent gap in model deployment and further automate the process. By demonstrating how an ML practitioner can better communicate with the application development and operations teams, I'll also introduce you to the idea of an agile, cross-functional team. By the end of the chapter, you will see how this methodology can consistently produce production-grade ML models and deploy them. We will concentrate on the following subjects in order to achieve this:
CI/CD methodology introduction; automating machine learning with CI/CD; building a CI/CD pipeline on AWS</p>
<h2 id="heading-introducing-the-cicd-methodology">Introducing the CI/CD methodology</h2>
<p>A highly well-liked mechanism for automating the creation and release of software into production is the CI/CD pattern. The basic idea behind this method is to deploy changes to production automatically and seamlessly after making incremental, dependable, and frequent modifications to the software code.
Although this discipline has been around for a while and is used by many DevOps engineers, MLOps, or Machine Learning Operations, is beginning to gain traction within the ML practitioner community. Before delving into how this methodology might be used for ML, let's become familiar with the individual parts of the procedure, beginning with CI.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/192133212-55593a11-624e-4bfd-9853-9a38c0301e6e.png" alt="image" /></p>
<h3 id="heading-creating-or-updating-source-artifacts">Creating or updating source artifacts</h3>
<p>Other than initiating the full CI process, the source artefacts stage doesn't really do any particular tasks. In essence, this step acts as a repository for the source code or software components that make up the finished application. The pipeline begins when new software artefacts (such as new features) or updated software artefacts (such as bug patches) are added to this repository.</p>
<p>For instance, application developers contribute updates to the shared version control system (such as GitHub, Bitbucket, or AWS CodeCommit) when they modify the code, add new features, or correct application defects. These stored changes are called commits, with\seach commit having an associated description or message that describes why a particular\schange was done. To help other contributors understand what has been changed in the code and why, these commits summarise the history of all the modifications. A Pull Request can be opened by the developer after a commit has been made (PR).</p>
<h3 id="heading-construction-of-pipeline-assets">Construction of pipeline assets</h3>
<p>The various software artefacts (and their dependencies) are produced or compiled in the next stage of the pipeline. These assets, or assets that are specific to the current release or, to put it another way, assets that are specific to the current execution of the pipeline, are essentially the end product of building the source code artefacts into an asset that is specific to the current release. For instance, the build step can be used to create a Docker container image or to convert C++ code into a release binary.</p>
<h3 id="heading-testing-the-pipeline-assets">Testing the pipeline assets</h3>
<p>After the pipeline assets are constructed, the following stage of the pipeline involves testing them for functionality as well as integration into the larger design or application. At this level, developers use automated testing, testing scripts, or even a testing architecture (also known as a test environment or QA environment) to carry out system testing.
This step's main objective is to ensure that built assets will work properly after being put into production. Application developers can ensure that the overall integrity of the solution, in its entirety, is preserved once it is released into production by testing the complete system.</p>
<h3 id="heading-approving-the-release">Approving the release</h3>
<p>The final step of the CI phase is to authorise the system or application for production once the integrity of the entire system or application has been tested. This step of the procedure can either include a human (or team) approving the test results, or it can be automated in cases when there are lots of code changes.</p>
<h2 id="heading-creating-a-cicd-pipeline-on-aws">Creating a CI/CD pipeline on AWS</h2>
<p>AWS offers a comprehensive collection of developer tools to meet the varied needs for hosting code as well as creating and delivering pipeline assets. We will leverage three key services from the AWS developer toolchain to build a CI/CD pipeline on AWS. We will use two additional services from the AWS development package to make the construction and automation of the pipeline even easier.</p>
<p>The following are the three essential elements of a CI/CD pipeline:
  • An element for keeping track of the numerous pipeline artefacts.</p>
<p>  • A step in the construction of the various pipeline assets.</p>
<p>  • A pipeline execution automation component.</p>
<p>AWS offers specialised services to meet the necessary capabilities of each of these three key components, particularly the following:</p>
<p>• <a href="https://aws.amazon.com/codecommit/"> AWS CodeCommit </a> </p>
<p>• <a href="https://aws.amazon.com/codebuild/"> AWS CodeBuild </a></p>
<p>• <a href="https://aws.amazon.com/codepipeline/"> AWS CodePipeline </a></p>
<ul>
<li><p>AWS CodeCommit is a cloud-based source code and version control service. In essence, it is the AWS-managed alternative to GitHub. CodeCommit used to store all the various pipeline and ML model artifacts.</p>
</li>
<li><p>CodeBuild is the heart of the continuous integration phase of the CI/CD pipeline. This service is responsible for compiling or building the various artifacts into usable pipeline assets. In the case of ML release automation, CodeBuild builds the required model training and serves runtimes, as well as executing the data processing, model training, and model evaluation processes.</p>
</li>
<li><p>AWS CodePipeline handles the continuous deployment phase of the CI/CD pipeline. This service contains the structure of the pipeline and is responsible for automating the task of releasing the trained model into production as a SageMaker hosted endpoint.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Automating Machine Learning Model Development Using SageMaker Autopilot]]></title><description><![CDATA[AWS provides a variety of methods for automating the creation of ML models. I'll describe one such approach in this article: SageMaker Autopilot. A…]]></description><link>https://awsbuilder.hashnode.dev/automating-machine-learning-model-development-using-sagemaker-autopilot</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/automating-machine-learning-model-development-using-sagemaker-autopilot</guid><category><![CDATA[AWS]]></category><category><![CDATA[sagemaker ]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[deployment]]></category><category><![CDATA[autopilot]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Fri, 23 Sep 2022 15:33:32 GMT</pubDate><content:encoded><![CDATA[<p>AWS provides a variety of methods for automating the creation of ML models. I'll describe one such approach in this article: SageMaker Autopilot. A framework called Autopilot runs the essential phases of a typical ML workflow automatically. This basically automates the end-to-end ML process by allowing both inexperienced and seasoned ML practitioners to assign the manual chores of data discovery, algorithm selection, model training, and model optimization to a dedicated AWS service.</p>
<p>This post will introduce you to some of the AWS features that concentrate on machine learning (ML) solutions and ML automation.</p>
<p>The following topics will be covered: 
  • Introduction to the AWS AI and ML landscape.</p>
<p>  • Overview of SageMaker Autopilot.</p>
<p>  • Using SageMaker Autopilot to overcome automation problems.</p>
<p>  • Using the SageMaker SDK to automate the ML experiment.</p>
<h2 id="heading-introducing-the-aws-ai-and-ml-landscape">Introducing the AWS AI and ML landscape</h2>
<p>AWS offers a wide range of machine learning (ML) and artificial intelligence (AI) capabilities to its clients. AWS has collected and arranged these capabilities into what is often known as the AI/ML Stack in order to further aid its clients in understanding them. The main objective of the AI/ML stack is to offer the tools that a developer or an expert in machine learning could need, depending on their level of experience. In essence, it equips all developers, whether they are regarded as novices or experts, with AI and ML skills. </p>
<p><img src="https://user-images.githubusercontent.com/23625821/191805882-11ffbc89-818c-403e-b67a-8bf82a88c5d4.png" alt="image" /></p>
<p><img src="https://user-images.githubusercontent.com/23625821/191806161-3355ff90-f041-4b60-b1c6-072532d7589e.png" alt="image" /></p>
<h2 id="heading-overview-of-sagemaker-autopilot">Overview of SageMaker Autopilot</h2>
<p>The AWS service that offers AutoML capability to its users is called SageMaker Autopilot. The following SageMaker modules are pieced together by Autopilot into an automated framework to address the various AutoML requirements:</p>
<p>• SageMaker Processing: Using a streamlined and controlled experience, processing jobs handle the labor-intensive tasks and scalability requirements of organising, validating, and feature engineering the data.</p>
<p>• SageMaker Built-in Algorithms: SageMaker offers a number of pre-built algorithms that are suited to a variety of use case types, making it easier for ML practitioners to get started with model-building activities.</p>
<p>• SageMaker Training: Training jobs handle the labor-intensive scaling and provisioning operations related to setting up the necessary compute resources to train the model.</p>
<p>• Automatic Model Tuning: By enabling the ML practitioner to run numerous training jobs concurrently, each with a subset of the necessary parameters, model tuning or hyperparameter tuning scales the model tuning task. As a result, there is no longer a need to adjust, assess, and retrain the model in a sequential manner. In order to choose future hyperparameters that will better optimise the model, SageMaker model tuning by default creates a probabilistic model of the performance of previously used hyperparameters using Bayesian Search (although Random Search can also be used).</p>
<p>• SageMaker Managed Deployment: After an optimal model has been trained, SageMaker Hosting can be used to deploy a single model or a collection of models as a fully functional API for use by production applications in an elastic and scalable way.</p>
<p>These tools are connected by Autopilot to form an automated workflow. The raw data is the only component that the ML practitioner is required to provide. By just providing the data, Autopilot enables even a beginner in machine learning to automatically develop a model that is suitable for production.</p>
<h2 id="heading-overcoming-automation-challenges-with-sagemaker-autopilot">Overcoming automation challenges with SageMaker Autopilot</h2>
<p>• The difficulties associated with creating the optimal ML model, such as gathering and comprehending the data before creating the model that is most appropriate for the use case.
• The difficulties brought on by the ML process itself, which is difficult, laborious, iterative, and continual.</p>
<p>For experimenting Sagemaker Autopilot, you can refer to this <a href="https://aws.amazon.com/getting-started/hands-on/create-machine-learning-model-automatically-sagemaker-autopilot/#"> tutorial </a></p>
<h2 id="heading-sagemaker-sdk-using-for-automating-the-ml-experiment">SageMaker SDK Using for automating the ML experiment</h2>
<p>The SageMaker SDK is essentially a higher-level SDK with an emphasis on ML exploration that utilises the base boto3 SDK. For instance, a machine learning practitioner would need to execute three different boto3 calls to deploy a model as a SageMaker hosted endpoint:</p>
<ol>
<li>The machine learning practitioner must use the SageMaker training job's output artefact to instantiate a trained model. This is done by using the boto3.client("sagemaker") low-level SageMaker client's create model() method.</li>
<li>After that, the ML expert must construct a SageMaker hosted endpoint configuration that details the endpoint's extra configuration options as well as the underlying computer resources. The SageMaker client's create endpoint config() method is used for this.</li>
<li>The trained model is deployed with the endpoint settings using the create endpoint() method.</li>
</ol>
<p>As an alternative, the ML practitioner might achieve the same result by executing the deploy() method on a model that has already been trained using the SageMaker SDK. The underlying model, endpoint setup, and endpoint deployment are all created by the SageMaker SDK.
The SageMaker SDK greatly simplifies ML experimentation for the more seasoned ML practitioner. You will begin getting acquainted with the SageMaker SDK in the following part by working through an example to codify the AutoML experiment.</p>
<p>You can refere this <a href="https://sagemaker-examples.readthedocs.io/en/latest/autopilot/index.html"> link </a> to implement your models using Sagemaker Autopilot and codify your Autopilot experiments. </p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with ML]]></title><description><![CDATA[Unfortunately, there is no standardised manual on how to execute ML. This is due to the fact that each ML use case is distinct and particular to the…]]></description><link>https://awsbuilder.hashnode.dev/getting-started-with-ml</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/getting-started-with-ml</guid><category><![CDATA[AWS]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[sagemaker ]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Wed, 21 Sep 2022 18:18:02 GMT</pubDate><content:encoded><![CDATA[<p>Unfortunately, there is no standardised manual on how to execute ML. This is due to the fact that each ML use case is distinct and particular to the application that uses the resulting ML model. Instead, the majority of data scientists, ML engineers, and ML practitioners adhere to a broad workflow pattern. The Cross-Industry Standard Process for Data Mining (CRISP-DM) is a process model that was developed, and while not everyone adheres to the exact stages verbatim, most production ML models have probably been produced using the constraints that the CRISP-DM methodology offers.
Therefore, when we talk about the ML process, we always mean the complete process of creating ML models that are ready for production while following the guidelines from CRSIP-DM.</p>
<p>An illustration of the CRISP-DM recommendations for designing a typical procedure that an ML practitioner might adhere to can be found in the graphic below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1663783086890/1QQt7eWJn.png" alt="crisp.png" /></p>
<p>After the data has been reviewed, the ML practitioner decides which modelling techniques are most appropriate for addressing the use case and extracting the most pertinent information from the data. These methods consist of the following:</p>
<ol>
<li>Choosing the appropriate ML algorithm</li>
<li>Adding additional elements to the data (engineering new features) that can raise the general efficacy of the selected model.</li>
<li>Data separation into training and testing sets for model development and assessment</li>
</ol>
<p>A model's suitability for use in production depends entirely on the quality of the data it was trained on. To extract the most pertinent features for model development and training, the data must be thoroughly evaluated and comprehended. Exploratory Data Analysis (EDA), which evaluates the statistical components of the data and may result in the creation of charts to better understand feature importance, can be used to achieve this. In order to help the trained model learn from these ideal properties, we may decide to collect additional vital data, delete uninteresting data, and maybe engineer new facets of the data.</p>
<p>In dealing with any problem, you have first do the following: </p>
<ul>
<li>Sourcing, ingesting, and understanding the data (EDA).</li>
<li>Building the right model: 
  In this stage, you have to select the most appropriate ML model / methodology to get the most accurate results / predictions.</li>
</ul>
<p>Algorithms such as: 
  • Linear regression
  • Support vector machines
  • Decision trees
  • Naïve Bayes
  • Neural networks</p>
<ul>
<li>Training the model: </li>
<li>Evaluating the trained model
We can proceed to the model evaluation stage of the ML process after the model has been trained. The trained model is now assessed against the goals and success criteria laid out in the business use case with the intention of determining whether or not the trained model is prepared for production. some metrics can be used for evaluation like RMSE.</li>
</ul>
<p>Important different steps for ML engineer / practitioner to consider: </p>
<ul>
<li><p>Use another model: 
 It's important to take into account entails creating a brand-new model utilising a totally     different method that nonetheless adheres to the use case. The ML expert might, for instance, do research using a different supervised learning, regression-based technique.
 Depending on the method, the data may also need to be reorganised to better match the needed input format. </p>
</li>
<li><p>Tuning the existing model
 Hence, this stage of the process is alsoreferred to as hyperparameter optimization (HPO).</p>
</li>
<li><p>Deploying the optimized model into production
 Insofar as some ML practitioners choose not to include this step in their ML process, model deployment is something of a murky area. For instance, some ML experts might believe that their only responsibility is to present a production-ready ML model that addresses the business use case. Once this model has been trained, it is simply given to the teams or owners who are responsible for developing the application so that they may test and incorporate the model into the application.
To ensure that the trained model interacts properly with the application, some ML practitioners will collaborate with the application teams to deploy the model into a test or Quality Assurance (QA) environment.</p>
</li>
</ul>
<p>Although the model deployment step in the accompanying diagram is when the CRISP-DM approach comes to an end, the process is actually ongoing. Once the model has been put into use in a production application, it needs to be closely watched to make sure it doesn't stray from its intended use and to guarantee that it regularly makes correct predictions on previously unknown or brand-new data. The ML practitioner will be required to restart the ML process in order to reoptimize the model and make it generalise to this new input should this circumstance emerge.</p>
]]></content:encoded></item><item><title><![CDATA[Smallest Number in Infinite Set]]></title><description><![CDATA[You have a set which contains all positive integers [1, 2, 3, 4, 5, ...]. Implement the SmallestInfiniteSet class: SmallestInfiniteSet() Initializes the…]]></description><link>https://awsbuilder.hashnode.dev/smallest-number-in-infinite-set</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/smallest-number-in-infinite-set</guid><category><![CDATA[Python]]></category><category><![CDATA[leetcode]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Fri, 09 Sep 2022 15:20:03 GMT</pubDate><content:encoded><![CDATA[<p>You have a set which contains all positive integers [1, 2, 3, 4, 5, ...].</p>
<p>Implement the SmallestInfiniteSet class:</p>
<p>SmallestInfiniteSet() Initializes the SmallestInfiniteSet object to contain all positive integers.
int popSmallest() Removes and returns the smallest integer contained in the infinite set.
void addBack(int num) Adds a positive integer num back into the infinite set, if it is not already in the infinite set.</p>
<pre><code class="lang-py">
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SmallestInfiniteSet</span>:</span>
    <span class="hljs-keyword">import</span> heapq
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self</span>):</span>
        self.summary = list(range(<span class="hljs-number">1</span>, <span class="hljs-number">1001</span>))
        heapq.heapify(self.summary)
        self.deleted = set()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">popSmallest</span>(<span class="hljs-params">self</span>) -&gt; int:</span>
        A = heapq.heappop(self.summary)
        self.deleted.add(A)
        <span class="hljs-keyword">return</span> A

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">addBack</span>(<span class="hljs-params">self, num: int</span>) -&gt; <span class="hljs-keyword">None</span>:</span>
        <span class="hljs-keyword">if</span> num <span class="hljs-keyword">in</span> self.deleted:
            self.deleted.remove(num)
            heapq.heappush(self.summary, num)
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Count Good Nodes in Binary Tree]]></title><description><![CDATA[Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the…]]></description><link>https://awsbuilder.hashnode.dev/count-good-nodes-in-binary-tree</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/count-good-nodes-in-binary-tree</guid><category><![CDATA[leetcode-solution]]></category><category><![CDATA[Python]]></category><category><![CDATA[problem solving skills]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Thu, 01 Sep 2022 05:05:31 GMT</pubDate><content:encoded><![CDATA[<p>Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.</p>
<p>Return the number of good nodes in the binary tree.</p>
<pre><code class="lang-py"><span class="hljs-comment"># Definition for a binary tree node.</span>
<span class="hljs-comment"># class TreeNode:</span>
<span class="hljs-comment">#     def __init__(self, val=0, left=None, right=None):</span>
<span class="hljs-comment">#         self.val = val</span>
<span class="hljs-comment">#         self.left = left</span>
<span class="hljs-comment">#         self.right = right</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">goodNodes</span>(<span class="hljs-params">self, root: TreeNode</span>) -&gt; int:</span>

      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">checkNode</span>(<span class="hljs-params">node,val</span>):</span>
        <span class="hljs-keyword">if</span>(node == <span class="hljs-literal">None</span>):
            <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>

        op = <span class="hljs-number">0</span>
        <span class="hljs-keyword">if</span>(node.val &gt;= val):
            op = <span class="hljs-number">1</span>

        val = max(val,node.val)
        <span class="hljs-keyword">return</span> op + checkNode(node.left,val) + checkNode(node.right,val)

      <span class="hljs-keyword">return</span> checkNode(root,root.val)
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Combination Sum II]]></title><description><![CDATA[Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers…]]></description><link>https://awsbuilder.hashnode.dev/combination-sum-ii</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/combination-sum-ii</guid><category><![CDATA[leetcode-solution]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Tue, 30 Aug 2022 06:27:23 GMT</pubDate><content:encoded><![CDATA[<p>Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.</p>
<p>Each number in candidates may only be used once in the combination.</p>
<p>Note: The solution set must not contain duplicate combinations.</p>
<pre><code class="lang-py"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">combinationSum2</span>(<span class="hljs-params">self, candidates: List[int], target: int</span>) -&gt; List[List[int]]:</span>
        candidates.sort()
        res = []
        n = len(candidates)

        <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">backtrack</span>(<span class="hljs-params">cur, pos, target</span>):</span>
            <span class="hljs-keyword">if</span> target == <span class="hljs-number">0</span>:
                res.append(cur.copy())
                <span class="hljs-comment"># return</span>

            <span class="hljs-keyword">if</span> target &lt; <span class="hljs-number">0</span>:
                <span class="hljs-keyword">return</span>
            prev = <span class="hljs-number">-1</span>

            <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(pos, n):
                <span class="hljs-keyword">if</span> prev == candidates[i]:
                    <span class="hljs-keyword">continue</span>

                cur.append(candidates[i])
                backtrack(cur, i+<span class="hljs-number">1</span>, target-candidates[i])
                cur.pop()

                prev = candidates[i]


        backtrack([], <span class="hljs-number">0</span>, target)        
        <span class="hljs-keyword">return</span> res
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Restore IP Addresses]]></title><description><![CDATA[A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros.]]></description><link>https://awsbuilder.hashnode.dev/restore-ip-addresses</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/restore-ip-addresses</guid><category><![CDATA[leetcode-solution]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Mon, 29 Aug 2022 09:06:40 GMT</pubDate><content:encoded><![CDATA[<p>A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros.</p>
<p>For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses, but "0.011.255.245", "192.168.1.312" and "192.168@1.1" are invalid IP addresses.
Given a string s containing only digits, return all possible valid IP addresses that can be formed by inserting dots into s. You are not allowed to reorder or remove any digits in s. You may return the valid IP addresses in any order.</p>
<pre><code class="lang-py">
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span>(<span class="hljs-params">object</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">restoreIpAddresses</span>(<span class="hljs-params">self, s</span>):</span>
        res = []
        <span class="hljs-keyword">if</span> len(s) &gt; <span class="hljs-number">12</span>:
            <span class="hljs-keyword">return</span> res

        <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">backtrack</span>(<span class="hljs-params">i, dots, curIP</span>):</span>
            <span class="hljs-keyword">if</span> dots == <span class="hljs-number">4</span> <span class="hljs-keyword">and</span> i == len(s):
                res.append(curIP[:<span class="hljs-number">-1</span>])
                <span class="hljs-keyword">return</span>

            <span class="hljs-keyword">if</span> dots &gt; <span class="hljs-number">4</span>:
                <span class="hljs-keyword">return</span>

            <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range(i, min(i+<span class="hljs-number">3</span>, len(s))):
                <span class="hljs-keyword">if</span> (int(s[i: j + <span class="hljs-number">1</span>]) &lt; <span class="hljs-number">256</span>) <span class="hljs-keyword">and</span> (i == j <span class="hljs-keyword">or</span> s[i] != <span class="hljs-string">"0"</span>):
                    backtrack(j + <span class="hljs-number">1</span>, dots + <span class="hljs-number">1</span>, curIP + s[i: j+<span class="hljs-number">1</span>] + <span class="hljs-string">"."</span>)


        backtrack(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-string">""</span>)
        <span class="hljs-keyword">return</span> res
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Set Mismatch]]></title><description><![CDATA[You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got…]]></description><link>https://awsbuilder.hashnode.dev/set-mismatch</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/set-mismatch</guid><category><![CDATA[leetcode-solution]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sun, 28 Aug 2022 07:59:43 GMT</pubDate><content:encoded><![CDATA[<p>You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.</p>
<p>You are given an integer array nums representing the data status of this set after the error.</p>
<p>Find the number that occurs twice and the number that is missing and return them in the form of an array.</p>
<pre><code class="lang-py">
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> Counter

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span>(<span class="hljs-params">object</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">findErrorNums</span>(<span class="hljs-params">self, nums</span>):</span>
        <span class="hljs-string">"""
        :type nums: List[int]
        :rtype: List[int]
        """</span>

        <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">findMissing</span>(<span class="hljs-params">ns</span>):</span>
            <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>, len(ns) + <span class="hljs-number">1</span>):
                <span class="hljs-keyword">if</span> i <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> ns:
                    <span class="hljs-keyword">return</span> i


        c = Counter(nums).items()
        res = <span class="hljs-number">0</span> 

        <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> c:
            <span class="hljs-keyword">if</span> v == <span class="hljs-number">2</span>:
                res = k
                <span class="hljs-keyword">break</span> 

        <span class="hljs-keyword">return</span> [res, findMissing(nums)]
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Implement Trie]]></title><description><![CDATA[A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various…]]></description><link>https://awsbuilder.hashnode.dev/implement-trie</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/implement-trie</guid><category><![CDATA[Python]]></category><category><![CDATA[leetcode-solution]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sun, 28 Aug 2022 07:50:09 GMT</pubDate><content:encoded><![CDATA[<p>A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.</p>
<p>Implement the Trie class:</p>
<p>Trie() Initializes the trie object.
void insert(String word) Inserts the string word into the trie.
boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.</p>
<pre><code class="lang-py">
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TrieNode</span>():</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self</span>):</span>
        self.children = {}
        self.endOfWord = <span class="hljs-literal">False</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Trie</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self</span>):</span>
        self.root = TrieNode()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">insert</span>(<span class="hljs-params">word</span>):</span>
        cur = self.root
        <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> word:
            <span class="hljs-keyword">if</span> c <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> cur.children:
                cur.children[c] = TrieNode()
            cur = cur.children[c]
        cur.endOfWord = <span class="hljs-literal">True</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">search</span>(<span class="hljs-params">word</span>):</span>
        cur = self.root
        <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> word:
            <span class="hljs-keyword">if</span> c <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> cur.children:
                <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span>
            cur = cur.children[c]
        <span class="hljs-keyword">return</span> cur.endOfWord

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">startsWith</span>(<span class="hljs-params">prefix</span>):</span>
        cur = self.root
        <span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> prefix:
            <span class="hljs-keyword">if</span> c <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> cur.children:
                <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span>
            cur = cur.children[c]
        <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Merge Triplets to Form Target Triplet]]></title><description><![CDATA[A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are…]]></description><link>https://awsbuilder.hashnode.dev/merge-triplets-to-form-target-triplet</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/merge-triplets-to-form-target-triplet</guid><category><![CDATA[leetcode-solution]]></category><category><![CDATA[problem solving skills]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sat, 27 Aug 2022 09:50:53 GMT</pubDate><content:encoded><![CDATA[<p>A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.</p>
<p>To obtain target, you may apply the following operation on triplets any number of times (possibly zero):</p>
<p>Choose two indices (0-indexed) i and j (i != j) and update triplets[j] to become [max(ai, aj), max(bi, bj), max(ci, cj)].
For example, if triplets[i] = [2, 5, 3] and triplets[j] = [1, 7, 5], triplets[j] will be updated to [max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5].
Return true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.</p>
<pre><code class="lang-py"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mergeTriplets</span>(<span class="hljs-params">self, triplets: List[List[int]], target: List[int]</span>) -&gt; bool:</span>
        good = set()

        <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> triplets:
            <span class="hljs-keyword">if</span> t[<span class="hljs-number">0</span>] &gt; target[<span class="hljs-number">0</span>] <span class="hljs-keyword">or</span> t[<span class="hljs-number">1</span>] &gt; target[<span class="hljs-number">1</span>] <span class="hljs-keyword">or</span> t[<span class="hljs-number">2</span>] &gt; target[<span class="hljs-number">2</span>]:
                <span class="hljs-keyword">continue</span>
            <span class="hljs-keyword">for</span> i, v <span class="hljs-keyword">in</span> enumerate(t):
                <span class="hljs-keyword">if</span> v == target[i]:
                    good.add(i)


        <span class="hljs-keyword">return</span> len(good) == <span class="hljs-number">3</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Enforcing Data at Rest Encryption within AWS Services 
| AWS White Paper Summary]]></title><description><![CDATA[AWS Key Management Service (AWS KMS) is a managed service that allows you to concentrate on the cryptographic needs of your applications while Amazon Web…]]></description><link>https://awsbuilder.hashnode.dev/enforcing-data-at-rest-encryption-within-aws-services-or-aws-white-paper-summary</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/enforcing-data-at-rest-encryption-within-aws-services-or-aws-white-paper-summary</guid><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sun, 05 Jun 2022 08:23:46 GMT</pubDate><content:encoded><![CDATA[<p>AWS Key Management Service (AWS KMS) is a managed service that allows you to concentrate on the cryptographic needs of your applications while Amazon Web Services (AWS) manages availability, physical security, logical access control, and maintenance of the underlying infrastructure. </p>
<p>Further, AWS KMS allows you to audit usage of your keys by providing logs of all API calls made on them to help you meet compliance and regulatory requirements.</p>
<p>Customers want to know how to effectively implement AWS KMS in their environment. </p>
<p>This whitepaper discusses how to use AWS KMS for each capability described in the AWS Cloud Adoption Framework Security Perspective whitepaper, including the differences between the different types of customer master keys, using AWS KMS key policies to ensure least privilege, auditing the use of the keys, and listing some use cases that work to protect sensitive information within AWS.</p>
<h3 id="heading-identity-and-access-management">Identity and Access Management</h3>
<p>The Identity and Access Management capability provides guidance on determining the controls for access management within AWS KMS to secure your infrastructure according to established best practices and internal policies.</p>
<h4 id="heading-aws-kms-and-iam-policies">AWS KMS and IAM Policies</h4>
<p>You can use AWS Identity and Access Management (IAM) policies in combination with key policies to control access to your customer master keys (CMKs) in AWS KMS. </p>
<p>This section discusses using IAM in the context of AWS KMS.  It doesn’t provide detailed information about the IAM service. </p>
<p>Policies attached to IAM identities (that is, users, groups, and roles) are called identity-based policies (or IAM policies). </p>
<p>Policies attached to resources outside of IAM are called resource-based policies. </p>
<p>In AWS KMS, you must attach resource-based policies to your customer master keys (CMKs). </p>
<p>These are called key policies. All KMS CMKs have a key policy, and you must use it to control access to a CMK. </p>
<p>IAM policies by themselves are not sufficient to allow access to a CMK, although you can use them in combination with a CMK key policy. </p>
<p>To do so, ensure that the CMK key policy includes the policy statement that enables IAM policies.</p>
<h4 id="heading-key-policies">Key Policies</h4>
<p>Key policies are the primary way to control access to CMKs in AWS KMS. Each CMK has a key policy attached to it that defines permissions on the use and management of the key. </p>
<p>The default policy enables any principals you define, as well as enables the root user in the account to add IAM policies that reference the key. </p>
<p>We recommend that you edit the default CMK policy to align with your organization’s best practices for least privilege. </p>
<p>To access an encrypted resource, the principal needs to have permissions to use the resource, as well as to use the encryption key that protects the resource. </p>
<p>If the principal does not have the necessary permissions for either of those actions, the request to use the encrypted resource will be denied.</p>
<h4 id="heading-least-privilege-separation-of-duties">Least Privilege / Separation of Duties</h4>
<p>Key policies specify a resource, action, effect, principal, and conditions to grant access to CMKs. </p>
<p>Key policies allow you to push more granular permissions to CMKs to enforce least privilege. </p>
<p>For example, an application might make a KMS API call to encrypt data but there is no use case for that same application to decrypt data. </p>
<p>In that use case, a key policy could grant access to the kms:Encrypt action but not kms:Decrypt and reduce the possibility for exposure. </p>
<p>Additionally, AWS allows you to separate the usage permissions from administration permissions associated with the key. </p>
<p>This means that an individual may have the ability to manipulate the key policy, but might not have the necessary permissions to use the key for cryptographic functions.</p>
<h3 id="heading-cross-account-sharing-of-keys">Cross Account Sharing of Keys</h3>
<p>Delegation of permissions to a CMK within AWS KMS can occur when you include the root principal of a trusted account within the CMK key policy. </p>
<p>The trusted account then has the ability to further delegate these permissions to IAM users and roles within their own account using IAM policies. </p>
<p>While this approach may simplify the management of the key policy, it also relies on the trusted accounts to ensure that the delegated permissions are managed. </p>
<p>The other approach would be to explicitly manage permissions to all authorized users using only the KMS key policy, which could make the key policy complex and less manageable. </p>
<p>Regardless of the approach you take, the specific trust should be broken out on a per key basis to ensure that you adhere to the least privilege model.</p>
<h3 id="heading-cmk-grants">CMK Grants</h3>
<p>Key policy changes follow the same permissions model used for policy editing elsewhere in AWS. </p>
<p>That is, users either have permission to change the key policy or they do not. </p>
<p>Users with the PutKeyPolicy permission for a CMK can completely replace the key policy for a CMK with a different key policy of their choice. </p>
<p>You can use key policies to allow other principals to access a CMK, but key policies work best for relatively static assignments of permissions. </p>
<p>To enable more granular permissions management, you can use grants. </p>
<p>Grants are useful when you want to define scoped-down, temporary permissions to use your CMK on your behalf in the absence of a direct API call from you.</p>
<h3 id="heading-encryption-context">Encryption Context</h3>
<p>In addition to limiting permission to the AWS KMS APIs, AWS KMS also gives you the ability to add an additional layer of authentication for your KMS API calls utilizing encryption context. </p>
<p>The encryption context is a key-value pair of additional data that you want associated with AWS KMS-protected information. </p>
<p>This is then incorporated into the additional authenticated data (AAD) of the authenticated encryption in AWS KMS-encrypted ciphertexts. </p>
<p>If you submit the encryption context value in the encryption operation, you are required to pass it in the corresponding decryption operation. </p>
<p>You can use the encryption context inside your policies to enforce tighter controls for your encrypted resources.</p>
<p>Because the encryption context is logged in CloudTrail, you can get more insight into the usage of your keys from an audit perspective. </p>
<p>Be aware that the encryption context is not encrypted and will be visible within CloudTrail logs. </p>
<p>The encryption context should not be considered sensitive information and should not require secrecy.</p>
<h3 id="heading-multi-factor-authentication">Multi-Factor Authentication</h3>
<p>To provide an additional layer of security over specific actions, you can implement an additional layer of protection using multi-factor authentication (MFA) on critical KMS API calls. </p>
<p>Some of those calls are PutKeyPolicy, ScheduleKeyDeletion, DeleteAlias, and DeleteImportedKeyMaterial. </p>
<p>This can be accomplished through a conditional statement within the key policy that checks for when or if an MFA device was used as part of authentication.</p>
<p>If someone attempts to perform one of the critical AWS KMS actions, the following CMK policy will validate that their MFA was authenticated within the last 300 seconds, or 5 minutes, before performing the action.</p>
<pre><code class="lang-json">{
 <span class="hljs-attr">"Sid"</span>: <span class="hljs-string">"MFACriticalKMSEvents"</span>,
 <span class="hljs-attr">"Effect"</span>: <span class="hljs-string">"Allow"</span>,
 <span class="hljs-attr">"Principal"</span>: {
    <span class="hljs-attr">"AWS"</span>: <span class="hljs-string">"arn:aws:iam::111122223333:user/ExampleUser"</span>
 },
 <span class="hljs-attr">"Action"</span>: [
   <span class="hljs-string">"kms:DeleteAlias"</span>,
   <span class="hljs-string">"kms:DeleteImportedKeyMaterial"</span>,
   <span class="hljs-string">"kms:PutKeyPolicy"</span>,
   <span class="hljs-string">"kms:ScheduleKeyDeletion"</span>
 ],
 <span class="hljs-attr">"Resource"</span>: <span class="hljs-string">"*"</span>,
 <span class="hljs-attr">"Condition"</span>:{
    <span class="hljs-attr">" NumericLessThan "</span>:{<span class="hljs-attr">"aws: MultiFactorAuthAge"</span>:<span class="hljs-string">"300"</span>}
  }
}
</code></pre>
<h3 id="heading-detective-controls">Detective Controls</h3>
<p>The Detective Controls capability ensures that you properly configure AWS KMS to log the necessary information you need to gain greater visibility into your environment.</p>
<h4 id="heading-cmk-auditing">CMK Auditing</h4>
<p>AWS KMS is integrated with CloudTrail. To audit the usage of your keys in AWS KMS, you should enable CloudTrail logging in your AWS account. </p>
<p>This ensures that all KMS API calls made on keys in your AWS account are automatically logged in files that are then delivered to an Amazon Simple Storage Service (S3) bucket that you specify. Using the information collected by CloudTrail, you can determine what request was made, the source IP address from which the request was made, who made the request, when it was made, and so on. </p>
<p>AWS KMS integrates natively with many other AWS services to make monitoring easy. </p>
<p>You can use these AWS services, or your existing security tool suite, to monitor your CloudTrail logs for specific actions such as ScheduleKeyDeletion, PutKeyPolicy, DeleteAlias, DisableKey, DeleteImportedKeyMaterial on your KMS key. Furthermore, AWS KMS emits Amazon CloudWatch Events when your CMK is rotated, deleted, and imported key material in your CMK expires.</p>
<h4 id="heading-cmk-use-validation">CMK Use Validation</h4>
<p>In addition to capturing audit data associated with key management and use, you should ensure that the data you are reviewing aligns with your established best practices and policies. One method is to continuously monitor and verify the CloudTrail logs as they come in. </p>
<p>Another method is to use AWS Config rules. By using AWS Config rules you can ensure that the configuration of many of the AWS services are set up appropriately. </p>
<p>For example, with EBS volumes you can use the AWS Config rule ENCRYPTED_VOLUMES to validate that attached EBS volumes are encrypted.</p>
<p>A CMK can have a tag applied to it for a variety of purposes. </p>
<p>The most common use is to correlate a specific CMK back to a business category (such as a cost center, application name, or owner). </p>
<p>The tags can then be used to verify that the correct CMK is being used for a given action. </p>
<p>For example, in CloudTrail logs, for a given KMS action you can verify that the CMK being used belongs to the same business category as the resource that it’s being used on. Previously, this might have required a look up within a resource catalog, but now this external lookup is not required because of tagging within AWS KMS as well as many of the other AWS services.</p>
<h3 id="heading-infrastructure-security">Infrastructure Security</h3>
<p>The Infrastructure Security capability provides you with best practices on how to configure AWS KMS to ensure that you have an agile implementation that can scale with your business while protecting your sensitive information.</p>
<h4 id="heading-customer-master-keys">Customer Master Keys</h4>
<p>Within AWS KMS, your key hierarchy starts with a CMK. A CMK can be used to directly encrypt data blocks up to 4 KB or it can be used to secure data keys, which protect underlying data of any size.</p>
<p>CMKs can be broken down into two general types: AWS-managed and customer-managed. </p>
<p>An AWSmanaged CMK is created when you choose to enable server-side encryption of an AWS resource under the AWS-managed CMK for that service for the first time (e.g., SSE-KMS). </p>
<p>The AWS-managed CMK is unique to your AWS account and the Region in which it’s used. </p>
<p>An AWS-managed CMK can only be used to protect resources within the specific AWS service for which it’s created. It does not provide the level of granular control that a customer-managed CMK provides. </p>
<p>For more control, a best practice is to use a customer-managed CMK in all supported AWS services and in your applications. A customer-managed CMK is created at your request and should be configured based upon your explicit use case.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/141607731-83fbeec0-91e6-4d36-b18a-e75090acc6a1.png" alt="1" /></p>
<h4 id="heading-key-creation-and-management">Key Creation and Management</h4>
<p>Since AWS makes creating and managing keys easy through the use of AWS KMS, we recommend that you have a plan for how to use the service to best control the blast radius around individual keys.</p>
<p>Previously, you may have used the same key across different geographic regions, environments, or even applications. With AWS KMS, you should define data classification levels and have at least one CMK per level. </p>
<p>For example, you could define a CMK for data classified as “Confidential,” and so on. This ensures that authorized users only have permissions for the key material that they require to complete their job.</p>
<p>You should also decide how you want to manage usage of AWS KMS. </p>
<p>Creating KMS keys within each account that requires the ability to encrypt and decrypt sensitive data works best for most customers, but another option is to share the CMKs from a few centralized accounts. </p>
<p>Maintaining the CMKs in the same account as the majority of the infrastructure using them helps users provision and run AWS services that use those keys. AWS services don’t allow for cross-account searching unless the principal doing the searching has explicit List* permissions on resources owned by the external account. </p>
<p>This can also only be accomplished via the CLI or SDK, and not through service console-based searches. Additionally, by storing the credentials in the local accounts, it might be easier to delegate permissions to individuals who know the IAM principals that require access to the specific CMKs. </p>
<p>If you were sharing the keys via a centralized model, the AWS KMS administrators would need to know the full Amazon Resource Name (ARN) for all users of the CMKs to ensure least privilege. </p>
<p>Otherwise, the administrators might provide overly permissive permissions on the keys.</p>
<h4 id="heading-key-aliases">Key Aliases</h4>
<p>A key alias allows you to abstract key users away from the underlying Region-specific key ID and key ARN. </p>
<p>Authorized individuals can create a key alias that allows their applications to use a specific CMK independent of the Region or rotation schedule. </p>
<p>Thus, multi-Region applications can use the same key alias to refer to KMS keys in multiple Regions without worrying about the key ID or the key ARN. </p>
<p>You can also trigger manual rotation of a CMK by pointing a given key alias to a different CMK. Similar to how Domain Name Services (DNS) allows the abstraction of IP addresses, a key alias does the same for the key ID. </p>
<p>When you are creating a key alias, we recommend that you determine a naming scheme that can be applied across your accounts such as alias/Environment-Function-Service Team.</p>
<p>It should be noted that CMK aliases can’t be used within policies. This is because the mapping of aliases to keys can be manipulated outside the policy, which would allow for an escalation of privilege. Therefore, key IDs must be used in KMS key policies, IAM policies, and KMS grants.</p>
<h3 id="heading-using-aws-kms-at-scale">Using AWS KMS at Scale</h3>
<p>AWS recommends using envelope encryption to scale your KMS implementation. Envelope encryption is the practice of encrypting plaintext data with a unique data key, and then encrypting the data key with a key encryption key (KEK). Within AWS KMS, the CMK is the KEK. </p>
<p>You can encrypt your message with the data key and then encrypt the data key with the CMK. Then the encrypted data key can be stored along with the encrypted message. </p>
<p>You can cache the plaintext version of the data key for repeated use, reducing the number of requests to AWS KMS. Additionally, envelope encryption can help to design your application for disaster recovery. You can move your encrypted data as-is between Regions and only have to re-encrypt the data keys with the Region-specific CMKs.</p>
<h3 id="heading-data-protection">Data Protection</h3>
<p>The Data Protection capability addresses some of the common AWS use cases for using AWS KMS within your organization to protect your sensitive information.</p>
<h4 id="heading-common-aws-kms-use-cases">Common AWS KMS Use Cases</h4>
<h5 id="heading-encrypting-pci-data-using-aws-kms">Encrypting PCI Data Using AWS KMS</h5>
<p>Since security and quality controls in AWS KMS have been validated and certified to meet the requirements of PCI DSS Level 1 certification, you can directly encrypt Primary Account Number (PAN) data with an AWS KMS CMK. </p>
<p>The use of a CMK to directly encrypt data removes some of the burden of managing encryption libraries. </p>
<p>Additionally, a CMK can’t be exported from AWS KMS, which alleviates the concern about the encryption key being stored in an insecure manner. As all KMS requests are logged in CloudTrail, use of the CMK can be audited by reviewing the CloudTrail logs. </p>
<p>It’s important to be aware of the requests per second limit when designing applications that use the CMK directly to protect Payment Card Industry (PCI) data.</p>
<h5 id="heading-secret-management-using-aws-kms-and-amazon-s3">Secret Management Using AWS KMS and Amazon S3</h5>
<p>Although AWS KMS primarily provides key management functions, you can leverage AWS KMS and Amazon S3 to build your own secret management solution.</p>
<p>Create a new Amazon s3 bucket to hold your secrets. Deploy a bucket policy onto the bucket to limit access to only authorized individuals and services. The secrets stored in the bucket utilize a predefined prefix per file to allow for granular control of access to the secrets. </p>
<p>Each secret, when placed in the S3 bucket, is encrypted using a specific customer-managed KMS key. Furthermore, due to the highly sensitive nature of the information being stored within this bucket, S3 access logging or CloudTrail Data Events are enabled for audit purposes. Then, when a user or service requires access to the secret, they assume an identity within AWS that has permissions to use both the object in the S3 bucket as well as the KMS key. An application that runs in an EC2 instance uses an instance role that has the necessary permissions.</p>
<h5 id="heading-encrypting-lambda-environment-variables">Encrypting Lambda Environment Variables</h5>
<p>By default, when you create or update Lambda functions that use environment variables, those variables are encrypted using AWS KMS. When your Lambda function is invoked, those values are decrypted and made available to the Lambda code. You have the option to use the default KMS key for Lambda or specify a specific CMK of your choice.</p>
<p>To further protect your environment variables, you should select the “Enable encryption helpers” checkbox. By selecting this option, your environment variables will also be individually encrypted using a CMK of your choice, and then your Lambda function will have to specifically decrypt each encrypted environment variable that is needed.</p>
<h5 id="heading-encrypting-data-within-systems-manager-parameter-store">Encrypting Data within Systems Manager Parameter Store</h5>
<p>Amazon EC2 Systems Manager is a collection of capabilities that can help you automate management tasks at scale. </p>
<p>To efficiently store and reference sensitive configuration data such as passwords, license keys, and certificates, the Parameter Store lets you protect sensitive information within secure string parameters.</p>
<p>A secure string is any sensitive data that needs to be stored and referenced in a secure manner. </p>
<p>If you have data that you don't want users to alter or reference in clear text, such as domain join passwords or license keys, then specify those values using the Secure String data type. You should use secure strings in the following circumstances:</p>
<ul>
<li>You want to use data/parameters across AWS services without exposing the values as clear text in commands, functions, agent logs, or CloudTrail logs.</li>
<li>You want to control who has access to sensitive data.</li>
<li>You want to be able to audit when sensitive data is accessed using CloudTrail.</li>
<li>You want AWS-level encryption for your sensitive data and you want to bring your own encryption keys to manage access.</li>
</ul>
<p>By selecting this option when you create your parameter, the Systems Manager encrypts that value when it’s passed into a command and decrypts it when processing it on the managed instance. The encryption is handled by AWS KMS and can be either a default KMS key for the Systems Manager or you can specify a specific CMK per parameter.</p>
<h3 id="heading-enforcing-data-at-rest-encryption-within-aws-services">Enforcing Data at Rest Encryption within AWS Services</h3>
<p>Your organization might require the encryption of all data that meets a specific classification. Depending on the specific service, you can enforce data encryption policies through preventative or detective controls. For some services like Amazon S3, a policy can prevent storing unencrypted data. For other services, the most efficient mechanism is to monitor the creation of storage resources and check whether encryption is enabled appropriately. In the event that unencrypted storage is created, you have a number of possible responses ranging from deleting the storage resource to notifying an administrator.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>AWS KMS provides your organization with a fully managed service to centrally control your encryption keys. Its native integration with other AWS services makes it easier for AWS KMS to encrypt the data that you store and process.</p>
<p>By taking the time to properly architect and implement AWS KMS, you can ensure that your encryption keys are secure and available for applications and their authorized users. Additionally, you can show your auditors detailed logs associated with your key usage.</p>
<h4 id="heading-reference">Reference</h4>
<p><a href="https://docs.aws.amazon.com/whitepapers/latest/kms-best-practices/kms-best-practices.pdf#welcome"> Original paper </a> </p>
]]></content:encoded></item><item><title><![CDATA[How to easily install Odoo on Ubuntu]]></title><description><![CDATA[If you find errors in a previous command, force install the dependencies with the following command: Configure PostgreSQL: Configure git : Create an…]]></description><link>https://awsbuilder.hashnode.dev/how-to-easily-install-odoo-on-ubuntu</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/how-to-easily-install-odoo-on-ubuntu</guid><category><![CDATA[Open Source]]></category><category><![CDATA[crm]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[setup]]></category><category><![CDATA[Ubuntu]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sun, 21 Nov 2021 06:36:01 GMT</pubDate><content:encoded><![CDATA[<ul>
<li>Run the following commands to install the main dependencies:</li>
</ul>
<pre><code class="lang-sh">$ sudo apt-get update

$ sudo apt install git python3-pip build-essential wget
python3-dev python3-venv python3-wheel libxslt-dev
libzip-dev libldap2-dev libsasl2-dev python3-setuptools
libpng12-0 libjpeg-dev gdebi -y
</code></pre>
<ul>
<li>Download and install wkhtmltopdf :</li>
</ul>
<pre><code class="lang-sh">$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/
releases/download/0.12.5/wkhtmltox_0.12.5-1.trusty_amd64.
deb

$ sudo dpkg -i wkhtmltox_0.12.5-1.trusty_amd64.deb
</code></pre>
<p>If you find errors in a previous command, force install the dependencies with the
following command:</p>
<pre><code class="lang-sh">$ sudo apt-get install -f
</code></pre>
<ul>
<li>Now, install the PostgreSQL database:</li>
</ul>
<pre><code class="lang-sh">
$ sudo apt install postgresql -y
</code></pre>
<p>Configure PostgreSQL:</p>
<pre><code class="lang-sh">
$ sudo -u postgres createuser --superuser $(whoami)
</code></pre>
<p>Configure git :</p>
<pre><code class="lang-sh">
$ git config --global user.name <span class="hljs-string">"Your Name"</span>
$ git config --global user.email youremail@example.com
</code></pre>
<p>Create an odoo-14.0 virtual environment and activate it:</p>
<pre><code class="lang-sh">$ python3 -m venv ~/venv-odoo-14.0
$ <span class="hljs-built_in">source</span> ~/venv-odoo-14.0/bin/activate
</code></pre>
<ul>
<li>Install the Python dependencies of Odoo in venv :</li>
</ul>
<pre><code class="lang-sh">$ <span class="hljs-built_in">cd</span> ~/odoo-dev/odoo/
$ pip3 install -r requirements.txt
</code></pre>
<ul>
<li>Create and start your first Odoo instances:</li>
</ul>
<pre><code class="lang-sh">
$ createdb odoo-test
$ python3 odoo-bin -d odoo-test –i base --addons-path=addons --db-filter=odoo-test$
</code></pre>
<ul>
<li>Clone the Odoo code base:</li>
</ul>
<pre><code class="lang-sh">$ mkdir ~/odoo-dev
$ <span class="hljs-built_in">cd</span> ~/odoo-dev
$ git <span class="hljs-built_in">clone</span> -b 14.0 --single-branch --depth 1 https://github.com/odoo/odoo.git
</code></pre>
<ul>
<li>Point your browser to http://localhost:8069 and authenticate it by using
the admin account and using admin as the password</li>
</ul>
<h3 id="heading-note">Note</h3>
<p>If you need RTL support, please install node and rtlcss via the following command:</p>
<pre><code class="lang-sh">sudo apt-get install nodejs npm -y
sudo npm install -g rtlcss
</code></pre>
]]></content:encoded></item><item><title><![CDATA[IPv6 on AWS | AWS White Paper Summary]]></title><description><![CDATA[Every node connected to an Internet Protocol (IP) network must have an IP address for communication purposes. As the internet continues to grow, so does…]]></description><link>https://awsbuilder.hashnode.dev/ipv6-on-aws-or-aws-white-paper-summary</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/ipv6-on-aws-or-aws-white-paper-summary</guid><category><![CDATA[AWS]]></category><category><![CDATA[networking]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sun, 21 Nov 2021 05:51:27 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-best-practices-for-adopting-and-designing-ipv6-based-networks-on-aws">Best practices for adopting and designing IPv6-based networks on AWS</h2>
<ul>
<li><p>Every node connected to an Internet Protocol (IP) network must have an IP address for communication purposes. </p>
</li>
<li><p>As the internet continues to grow, so does the need for IP addresses. </p>
</li>
<li><p>IPv6 is a version of the Internet Protocol that uses a larger address space than its predecessor, IPv4. </p>
</li>
<li><p>This whitepaper focuses on best practices for adopting and designing IPv6-based networks on AWS Cloud. </p>
</li>
<li><p>It covers IPv6 dual-stack networks for both internet-facing and private IPv6 networks use cases.</p>
</li>
</ul>
<h2 id="heading-intro">Intro</h2>
<ul>
<li>An increasing number of organizations operate dual-stack IPv4/IPv6 networks. </li>
<li>Carrier networks and ISPs were the first groups to start deploying IPv6 on their networks, with mobile networks leading the charge. </li>
<li><p>Adoption of IPv6 has been delayed, partly due to NAT with IPv4, which takes private IP addresses and turns them into public IP addresses.</p>
</li>
<li><p>An increasing number of organizations are adopting IPv6 in their environments, driven by the public IPv4 space exhaustion, private IPv4 scarcity, especially within large-scale networks, and the need to provide connectivity to IPv6-only clients. </p>
</li>
<li><p>There is no onesize-fits-all approach with IPv6; however, there are best practices AWS customers can follow to plan and implement IPv6 into their existing cloud networks. </p>
</li>
<li><p>This whitepaper explains key drivers for adoption and highlights best practices to guide you while leaving enough space for you to decide, based on your specific use case and implementation, how to approach IPv6 in your network.</p>
</li>
</ul>
<h3 id="heading-tenets-for-ipv6-adoption">Tenets for IPv6 adoption</h3>
<ul>
<li>Adhering to the following tenets for IPv6 adoption can help make the process and decision more manageable: <ul>
<li>Re-evaluate network controls — IPv6 offers opportunities to rethink your approach to perimeter security and make design decisions that further improve your security posture.</li>
<li>Design for scale — More usable IPv6 addresses doesn’t mean you can shortcut IP allocation and planning.</li>
<li>Phase your IPv6 adoption — Focus on your business needs to implement IPv6 where needed, and remember that IPv4 and IPv6 can be made to coexist as long as needed.</li>
</ul>
</li>
</ul>
<h3 id="heading-internet-protocol-version-6">Internet Protocol version 6</h3>
<ul>
<li><p>IPv6 is the next generation IP address standard intended to supplement and eventually replace IPv4, the original and ubiquitous IP address scheme. </p>
</li>
<li><p>Every computer, mobile phone, home automation component, IoT sensor, and any other device connected to an IP-based network needs a numerical IP address to communicate with other devices.</p>
</li>
<li><p>Public reachable IPv4 addresses are in short supply due to their widespread usage and constantly increasing demand stemming from the proliferation of connected devices globally. </p>
</li>
<li><p>The last available block of new IP version 4 (IPv4) addresses was allocated back in 2011, and from that time on, everyone has been reusing a finite set of available addresses. </p>
</li>
<li><p>IP version 6 (IPv6) is the replacement for IPv4, and it is designed to address the depletion of IP addresses, and change the way traffic is managed.</p>
</li>
</ul>
<h3 id="heading-ipv6-addressing">IPv6 addressing</h3>
<p>The IPv6 address space is organized by using format prefixes, that logically divide it in the form of a tree so that a route from one network to another can easily be found.</p>
<p>The main categories of IPv6 addresses are:</p>
<pre><code>  - Aggregatable <span class="hljs-keyword">global</span> unicast addresses (GUA) — <span class="hljs-number">2000</span>::/<span class="hljs-number">3</span> 

  - <span class="hljs-keyword">Unique</span>-<span class="hljs-keyword">local</span> unicast addresses (ULA) — FC00::/<span class="hljs-number">7</span> 

  - Link-<span class="hljs-keyword">local</span> unicast addresses — FE80::/<span class="hljs-number">10</span> 

  - Multicast addresses — FF00::/<span class="hljs-number">8</span> 
</code></pre><h3 id="heading-ipv6-adoption-strategies-and-mechanisms">IPv6 adoption strategies and mechanisms</h3>
<p>Working with customers, AWS observed the following two main drivers for IPv6 adoption.</p>
<ul>
<li>Network Address Translation is no longer sufficient to work around exhaustion and poses significant challenges with overlapping IP addresses.</li>
<li>There are numerous organizational or regulatory mandates to adopt IPv6. </li>
</ul>
<p>Following is a summary of IPv6 adoption drivers:</p>
<ul>
<li>Mandated IPv6 endpoints — Either mandated by a government policy or an industry regulator, and not necessarily tied to a particular use case.</li>
</ul>
<ul>
<li><p>Interoperability with IPv6 networks — The last years have seen a growing population of IPv6-only clients, and as a result so have the number of organizations wanting to cater to this user base. With the number of mobile IPv6-only users, many companies find they can’t afford to lose that section of their potential user base.</p>
</li>
<li><p>Public IPv4 exhaustion — As public IPv4 addresses become more scarce, allocating contiguous IP address ranges for public routing becomes more difficult and costly.</p>
</li>
<li><p>Private IPv4 exhaustion — As private IPv4 (RFC1918) addresses become exhausted and too fragmented within organizations’ private networks, IPv6-only networks offer opportunities to address additional nodes.</p>
</li>
</ul>
<p>IPv6 adoption strategy depends on the driving force behind it. You may have an immediate goal such as addressing private IPv4 exhaustion, or the ability to provide IPv6 service endpoints as per government mandate, with the long-term goal of fully converting to an IPv6 only network. </p>
<p>Following are the four main driving forces, and the corresponding adoption strategy:</p>
<ul>
<li><p>Private IPv4 exhaustion — The goal is to provision new nodes and allocate routable IP addresses without IP overlap, and without the challenge of sourcing contiguous and usable IP addresses.</p>
</li>
<li><p>Adoption strategy — Configure IPv6-only routing between dual stack network segments, to facilitate communication using the IPv6 stack. Provide IPv6 to IPv4 interoperability layer, such as dual-stack load balancers. </p>
</li>
</ul>
<ul>
<li><p>Public IPv4 exhaustion — The goal is to support IPv6 only nodes connecting to your public endpoints. As an example, you may have an API endpoint for data upload from IoT devices which are connected to an IPv6-only network. The IoT devices have IPv6 addresses, and the network does not provide interoperability layer to IPv4. Other devices may operate in IPv4 networks.</p>
</li>
<li><p>Adoption strategy — Create dual-stack VPCs and subnets. Configure AWS services such as load balancers and edge service in dual-stack mode with corresponding DNS record on the AWS Cloud. Optionally, provide separate endpoints for IPv4 and IPv6 in dedicated IPv4-only or IPv6-only deployments.</p>
</li>
</ul>
<h3 id="heading-interoperability">Interoperability</h3>
<p>Although operating in dual-stack mode solves a lot of the problems with IPv4 and IPv6 interoperability, it creates management overhead. For example, security becomes harder because you have to manage two sets of security rules, one for each network stack. Routing and troubleshooting become harder, and you have to maintain additional records to existing DNS names.</p>
<p>You may be able to avoid making the entire network dual-stack by focusing on implementing dual-stack at your border via load balancers. Existing segments of your network can continue to operate as IPv4 in most cases, and new segments are built with IPv6. Focus on implementing and operating interoperability layer where AWS services such as dual-stack VPC and load balancers, to help you solve interoperability challenges.</p>
<h3 id="heading-planning-ipv6-adoption-in-the-aws-cloud-network">Planning IPv6 adoption in the AWS Cloud network</h3>
<p>Elastic network interfaces in an IP network could operate in three different modes:</p>
<ul>
<li><p>IPv4-only mode — Your resources can communicate over IPv4, and if communicating to IPv6 nodes, require an interoperability layer.</p>
</li>
<li><p>IPv6-only mode — Your resources can communicate over IPv6, and if communicating to IPv4 nodes, require an interoperability layer.</p>
</li>
<li><p>Dual-stack mode — Your resources can communicate over both IPv4 and IPv6.</p>
</li>
</ul>
<p>A separate interoperability layer is not required</p>
<h4 id="heading-ipv6-addressing-plan-on-aws">IPv6 addressing plan on AWS</h4>
<p>Coming up with an IPv6 addressing plan is one of the most important initial tasks for any organization proceeding with IPv6 adoption. For most organizations, IPv6 is deployed in parallel with IPv4 in existing IPv4 AWS and hybrid networks. </p>
<p>IPv4 addressing plans tend to grow over time, and consequently may be highly fragmented, not contiguous, or not big enough. Simply duplicating the IPv4 addressing scheme in
some fashion in IPv6 might initially prove advantageous. </p>
<p>However, any temporary advantage gained by such a shortcut will ultimately be surpassed by the ease and efficiency of operation and design offered by a proper IPv6 addressing plan that incorporates the key benefits of the larger allocations possible with IPv6. </p>
<h4 id="heading-aws-assigned-ipv6-vpc-cidr">AWS-assigned IPv6 VPC CIDR</h4>
<p>By default, Amazon provides one fixed size (/56) IPv6 CIDR block to a VPC. This range is assigned by the service, and consequently, you can’t assign contiguous IPv6 CIDR blocks to VPCs in the same Region or based on other custom-defined criteria.</p>
<p>For customers that have a large VPC footprint in AWS and prefer to use IP route summarization to simplify their overall environment, bring your own IPv6 (BYOIPv6) described, in the next section, may be the preferred solution.</p>
<h4 id="heading-byoipv6-vpc-cidr">BYOIPv6 VPC CIDR</h4>
<p>Alternatively, if you own an IPv6 address space, you can import it into AWS using the Bring Your Own IPv6 service. The smallest IPv6 address range that you can bring is /48 for CIDRs that are publicly advertised by AWS, and /56 for CIDRs that are not publicly advertised by AWS. </p>
<p>You can also choose to bring a /48 and mark it as non-advertisable, keeping control of IP advertisements on your on-premises setup. After importing it, you can assign /56 ranges from the space to individual VPCs in the same account.</p>
<h4 id="heading-vpc-subnet-addressing">VPC subnet addressing</h4>
<p>Although you can assign one /56 IPv6 CIDR block to a VPC, the VPC subnets are /64 fixed in length. This yields to the interface ID being /64 in length, in accordance with the general format of the IPv6 unicast addresses. Given the fixed size of the VPC CIDR and the subnet prefix, you have 8 bits for subnet allocation in the VPC, enabling you to create 256 subnets in the VPC.</p>
<h3 id="heading-designing-an-ipv6-aws-cloud-network">Designing an IPv6 AWS Cloud network</h3>
<h5 id="heading-amazon-vpc-design">Amazon VPC design</h5>
<p>Planning and implementing network connectivity in AWS is usually one of the foundational tasks you perform when deploying workloads in AWS. </p>
<p>Following are some of the aspects typically considered:</p>
<ul>
<li>Amount and nature of Amazon VPCs required</li>
<li><p>Amazon VPC CIDR range and IP address allocation including Bring Your Own IP (BYOIP) for public connectivity</p>
</li>
<li><p>Number and type of subnets</p>
</li>
<li>Number of availability zones to cover</li>
<li>Permitted traffic paths</li>
<li>Internet incoming and outgoing traffic options</li>
<li>Hybrid connectivity</li>
<li>Inter-VPC connectivity</li>
<li>Scalability and expansion</li>
</ul>
<h5 id="heading-vpc-ip-address-assignment">VPC IP address assignment</h5>
<p>Your VPC can operate in dual-stack mode—your resources can communicate over IPv4, IPv6, or both. IPv4 and IPv6 communication are independent of each other. You cannot disable IPv4 support for your VPC and subnets; you are required to allocate at least one IPv4 CIDR range to your VPC. In addition, you may associate up to one IPv6 CIDR block range per VPC.</p>
<h5 id="heading-subnet-address-assignment">Subnet address assignment</h5>
<p>After you have associated an IPv6 prefix to a VPC, you can begin to assign one /64 IPv6 prefix to each subnet. </p>
<p>Note that these assignments are configured on a per-subnet basis, and it’s possible to have a mix of subnets with and without IPv6 within the same VPC. </p>
<p>This is useful in scenarios where you merely require IPv6 capability for a subset of the network as described in the drivers for adoption section.</p>
<p>The address assignment of resource within a subnet occurs at two levels:</p>
<ul>
<li>The Amazon VPC elastic network interface construct configuration</li>
<li>A resource’s networking stack configuration</li>
</ul>
<h5 id="heading-ip-addressing-of-the-elastic-network-interface">IP addressing of the elastic network interface</h5>
<ul>
<li><p>Network-addressable resources deployed within a VPC must have an elastic network interface. Examples of resources include: </p>
<ul>
<li>Amazon Elastic Compute Cloud (Amazon EC2) instances</li>
<li>Interface VPC endpoints</li>
<li>AWS Lambda functions (deployed in VPCs)</li>
<li>Amazon Relational Database Service (Amazon RDS) database instances</li>
</ul>
</li>
</ul>
<p>Elastic network interfaces are logical constructs in the VPC which represent a resource’s network adapter at runtime. </p>
<p>Each elastic network interface may have one or more IPv4 addresses as well as one or more IPv6 addresses. </p>
<p>This means you are not required to provision separate elastic network interfaces for IPv4 and IPv6, and there is no need to configure additional elastic network interfaces on your workloads to enable IPv6.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/142264990-174070e1-4445-454d-abe0-1432f448d921.png" alt="1" /></p>
<h4 id="heading-ip-addressing-at-the-resources-networking-stack">IP addressing at the resource’s networking stack</h4>
<p>In IPv4, the preferred method for assigning IPv4 addresses is to use Dynamic Host Configuration Protocol (DHCP). </p>
<p>DHCP is based on IPv4’s broadcast mechanism that allows hosts to announce themselves to DHCP servers. </p>
<p>These servers can then offer an IP address lease to the client. IPv6 has no concept of broadcast and initially did not feature DHCP capability. </p>
<p>However, the community has become used to DHCP, and so RFC 8415 was developed to introduce DHCPv6. </p>
<p>In the absence of broadcast capability, DHCPv6 makes use of the well-known multicast address for all DHCP servers/relays, ff02::1:2.</p>
<p>Amazon VPC has built in support for address assignment via DHCP for both IPv4 and IPv6. </p>
<p>Address allocation works similar to static address reservation in traditional DHCP servers: </p>
<p>   the IP address assigned to the elastic network interface construct determines the IP address the VPC DHCP infrastructure offers the resource requesting an address.</p>
<p>Amazon VPC also offers the ability to configure DHCP option sets which can be used to provide additional configuration information such as domain name or DNS servers to use. In a dual-stack design all IP addresses used in an option set need to be IPv4.</p>
<h3 id="heading-supporting-amazon-vpc-services">Supporting Amazon VPC services</h3>
<p>AWS exposes a set of supporting services within customer VPCs at wellknown/reserved addresses. </p>
<p>These services are traditionally exposed from the IPv4 linklocal address range (169.254.0.0/16). </p>
<p>For <a href="https://aws.amazon.com/ec2/nitro/"> AWS Nitro System instances </a> , AWS also provides these services using IPv6 ULAs.</p>
<h3 id="heading-instance-metadata-service-imds">Instance Metadata Service (IMDS)</h3>
<p>The instance metadata is information about your instance. </p>
<p>Instances can introspect this at runtime by querying the IMDS available to it at 169.254.169.254. </p>
<p>For Nitro-based instances, AWS also provides this service at the fd00:ec2::254 IPv6 endpoint.</p>
<h3 id="heading-route-53-dns-resolver">Route 53 DNS resolver</h3>
<p>Amazon VPC features a built-in DNS resolver which resides at VPC_CIDR_BASE + 2 and 169.254.169.253. </p>
<p>IPv6 enabled Nitro instances can access the service via fd00:ec2::253. </p>
<p>Amazon Route 53 Resolver and DNS in general is discussed at greater length in the Designing DNS for IPv6 section of this document.</p>
<h3 id="heading-network-time-protocol-server">Network Time Protocol server</h3>
<p>Amazon VPC provides a Stratum-3 NTP server at 169.254.169.123. </p>
<p>Nitro-based IPv6 enabled instances can reach this server via fd00:ec2::123.</p>
<h3 id="heading-amazon-vpc-connectivity-options-for-ipv6">Amazon VPC connectivity options for IPv6</h3>
<p>There are a growing number of ways in which Amazon VPCs can connect to each other. </p>
<p>Many of these options are detailed in the VPC to VPC connectivity section of the Building a Scalable and Secure Multi-VPC AWS Network Infrastructure <a href="https://docs.aws.amazon.com/whitepapers/latest/building-scalable-secure-multi-vpc-network-infrastructure/welcome.html"> whitepaper </a> .</p>
<p>AWS recommends you read the following subsections alongside, and it follows the same structure while providing additional insight regarding IPv6 operation as both papers cover:</p>
<ul>
<li>VPC peering</li>
<li>AWS Transit Gateway</li>
<li>VPC subnet sharing</li>
<li>AWS PrivateLink</li>
</ul>
<h4 id="heading-vpc-peering">VPC peering</h4>
<p>VPC peering is the simplest method for VPC-to-VPC connectivity. </p>
<p>It supports both intraand inter-Region connectivity. </p>
<p>The peering itself is IP protocol agnostic. </p>
<p>After you establish peering, you must configure one or more static routes defining which prefixes are reachable. </p>
<p>Both IPv4 and IPv6 prefixes may be routed across the same peering.</p>
<p>The following diagram depicts a VPC peering between two VPCs supporting IPv4 and IPv6 simultaneously. </p>
<p>The peering is agnostic, and the subnet route tables are the deciding factor for which prefixes are reachable.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/142267059-f212f122-0d46-4070-b678-c84748a84e1a.png" alt="1" /></p>
<h4 id="heading-aws-transit-gateway">AWS Transit Gateway</h4>
<p>It is a scalable highly available way to establish network connectivity between multiple VPCs. </p>
<p>A Transit Gateway is a Regional construct, and attaches VPCs within the same Region. </p>
<p>Transit Gateways located in different AWS Regions can establish a peering relationship, enabling global connectivity for your network.</p>
<h4 id="heading-ipv6-connectivity-into-transit-gateway">IPv6 connectivity into Transit Gateway</h4>
<p>You use a Transit Gateway attachment to connect a VPC to a Transit Gateway. </p>
<p>An attachment deploys an elastic network interface into each subnet you select. </p>
<p>Traffic is routed into Transit Gateways using static routes in VPC subnet routing tables with the attachment as the next-hop. </p>
<p>The attachments themselves are IP protocol agnostic, and you can route IPv4 and IPv6 prefixes via the same attachment. </p>
<p>To support IPv6, the elastic network interface s used by the attachments need to have IPv6 addresses assigned to them.</p>
<h4 id="heading-ipv6-traffic-within-and-between-transit-gateways">IPv6 traffic within and between Transit Gateways</h4>
<p>A Transit Gateway attachment is both a source and a destination of packets. </p>
<p>You can attach the following resources to your Transit Gateway:</p>
<ul>
<li>VPCs</li>
<li>One or more VPN connections</li>
<li>One or more AWS Direct Connect gateways</li>
<li>One or more Transit Gateway Connect attachments</li>
<li>One or more Transit Gateway peering connections</li>
</ul>
<p>A Transit Gateway has one or more routing tables. </p>
<p>A routing table can receive its entries through a combination of static route configuration and dynamic propagations from other attachments (VPC, Direct Connect, Site-to-Site VPN, or Connect Peering). In either case, IPv6 routes are supported.</p>
<h4 id="heading-aws-transit-gateway-connect-attachments-for-ipv6">AWS Transit Gateway Connect Attachments for IPv6</h4>
<p>You can create a Transit Gateway Connect attachment to establish a connection and dynamic routing between a transit gateway and third-party virtual appliances (such as SD-WAN appliances).</p>
<p>These attachments take the form of IP Generic Routing Encapsulation (GRE) protocol tunnels and enable dynamic exchange of routing information between an EC2 instances in a VPC and a TGW. </p>
<p>Route exchange is facilitated by a Border Gateway Protocol (BGP) peering. TGW connect peers support IPv6 using Multi-Protocol BGP (MP-BGP) and a /125 CIDR block from the well-known fd00::/8 unique local address range.</p>
<p>Multiprotocol BGP (MP-BGP) is an extension to BGP that enables BGP to carry routing information for multiple network layers and address families. MP-BGP can carry the unicast routes used for multicast routing separately from the routes used for unicast IP forwarding.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/142367647-1ee6aff8-99f3-41bc-9f2b-ee108ed2a965.png" alt="1" /></p>
<h4 id="heading-aws-privatelink">AWS PrivateLink</h4>
<p>AWS PrivateLink provides private connectivity between VPCs, AWS services, and customer on-premises networks, without exposing traffic to the public internet. </p>
<p>AWS PrivateLink makes it easy to connect services across different accounts and VPCs to significantly simplify your network architecture.</p>
<p>AWS PrivateLink does not currently support IPv6. However, PrivateLink has the useful property of abstracting the IP addressing used between source and destination. </p>
<p>In the meantime, it’s possible to operate a dual-stack setup for the purpose of communicating via PrivateLink endpoints. </p>
<p>It is possible for a workload to use IPv6 for most communication and use IPv4 purely for accessing the IPv4 address of the PrivateLink endpoint.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/142368216-ed49991d-e692-44b6-8902-efe1f0727fb1.png" alt="1" /></p>
<h4 id="heading-vpc-sharing">VPC sharing</h4>
<p>VPC sharing allows VPC owners to share a subnet across AWS accounts. </p>
<p>You may share dual-stack subnets the same way as IPv4-only ones. </p>
<p>IPv6 resources deployed into a shared subnet function identical to those deployed into non-shared subnets.</p>
<h3 id="heading-amazon-vpc-internet-access">Amazon VPC internet access</h3>
<h4 id="heading-internet-reachable-ipv6-resources">Internet reachable IPv6 resources</h4>
<p>Elastic network interfaces retain their IPv6 addresses throughout their lifetime. </p>
<p>For IPv4, elastic network interfaces can have zero or more Elastic IP addresses associated with them. </p>
<p>An Elastic IP address defines a static 1:1 NAT relationship between an elastic network interface’s IPv4 address and a public internetroutable address.</p>
<p>In IPv6, VPC addressing is already globally unique, and therefore Elastic IP addresses are not required. </p>
<p>Amazon assigned IPv6 addresses are automatically publicly advertised whereas for BYOIP ranges this is optional. </p>
<p>In either case, resources deployed only have IPv6 internet reachability if their subnet’s routing table contains IPv6 destinations (such as ::/0) via either an internet gateway or outbound traffic-only internet gateway.</p>
<h3 id="heading-hybrid-connectivity-design">Hybrid connectivity design</h3>
<p>Hybrid connectivity scenarios are a reality for many customers. </p>
<p>Two methods for addressing these: AWS Direct Connect and AWS managed Site-to-Site VPN.</p>
<p>AWS previously published the Hybrid Connectivity whitepaper, which focused on designs and considerations around these solutions, and most of that content remains relevant. </p>
<p>However, that paper does not consider IPv6. This section assumes you are acquainted with the aforementioned document, and it focuses only on the best practices and differences compared to IPv4 implementations.</p>
<h4 id="heading-aws-direct-connect">AWS Direct Connect</h4>
<p>AWS Direct Connect is a cloud service solution that makes it easy to establish a dedicated network connection from customer premises to AWS.</p>
<p>Different aspects of the Direct Connect service deal with different layers of the OSI model. </p>
<p>The choice of IPv6 only affects configuration related to Layer 3, so many aspects of Direct Connect configuration such as physical connections, link aggregation, VLANs, and jumbo frame are no different from IPv4 use cases.</p>
<p>Where IPv6 does differ is when it comes to addressing and configuration of BGP peerings on top of a virtual network interface (VIF). There are three types of VIFs: </p>
<ul>
<li>Private</li>
<li>Transit</li>
<li>Public</li>
</ul>
<p>Transit and Private VIF IPv6 peerings — Whereas in IPv4 you are free to choose your own addressing for the logical point-to-point, in IPv6, AWS automatically allocates a
125 CIDR for each VIF, and it’s not possible to specify custom IPv6 addresses.</p>
<p>Advertising IPv6 prefixes from AWS</p>
<p>When associating a Direct Connect Gateway directly with a VGW you can specify “Allowed Prefixes . </p>
<p>Think of this like a traditional “prefix-list” filter, controlling the prefixes advertised to your customer gateway. With IPv4, specifying no filter equates to 0.0.0.0/0 — no filtering. </p>
<p>With IPv6, not specifying a value here results in all advertisements being implicitly blocked.</p>
<h3 id="heading-amazon-managed-vpn">Amazon-managed VPN</h3>
<p>AWS Site-to-Site VPN connectivity configuration comprises multiple parts:</p>
<ol>
<li>The customer gateway, which is the logical representation of the onpremises VPN end point.</li>
<li>The VPN connection.</li>
<li>The local device configuration on the VPN appliance, represented by the customer gateway. </li>
</ol>
<p>Any AWS S2S VPN connection consists of two tunnels. It is this connection that defines the IP addressing, ISAKMP, IPsec, and BGP peering parameters.</p>
<h3 id="heading-designing-dns-for-ipv6">Designing DNS for IPv6</h3>
<p>The core concept of DNS is unchanged from IPv4. From a Layer 3 perspective, DNS is just another application, and therefore, by virtue of the OSI/ISO model provided abstraction, agnostic to the chosen network layer protocol.</p>
<p>Regardless of the IP version, there is a deep link between DNS and the IP layer. </p>
<p>The DNS specification has adapted and introduced an additional type to accommodate IPv6 addresses. </p>
<p>In IPv6 the equivalent of the IPv4 “A” records are AAAA records. </p>
<p>This means that it is possible to use IPv4 as the network protocol to connect to a DNS server and resolve an IPv6 (AAAA) record.</p>
<h4 id="heading-ptr-records">PTR records</h4>
<p>A pointer (PTR) record translates an IP address to its domain name. </p>
<p>IPv6 addresses are reverse mapped under the domain IP6.ARPA. </p>
<p>IPv6 reverse maps use a sequence of nibbles separated by dots with the suffix “.IP6.ARPA” as defined in RFC 3596. </p>
<p>For example, the reverse lookup domain name corresponding to the address 2001:db8:1234:1a00:1:2:3:4 would be 4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.a.1.4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa</p>
<h4 id="heading-alias-records">Alias records</h4>
<p>Amazon Route 53 supports alias records. </p>
<p>Route 53 alias records are mapped internally to the DNS name of alias targets such as AWS resources. </p>
<p>Route 53 monitors the IP address associated with an alias target's DNS name for scaling actions and software updates. </p>
<p>The authoritative response from Route 53 name servers contains an A record (for IPv4 addresses) or AAAA record (for IPv6 addresses) with the IP address of the alias target.</p>
<h4 id="heading-dns-resolution-within-a-host">DNS resolution within a host</h4>
<p>External configuration aside it is up to a host’s networking stack at runtime to resolve DNS records. </p>
<p>When configured as dual-stack, most modern operating systems default to preferring IPv6. </p>
<p>In other words, when a query for a FQDN returns both an A and AAAA record the OS prefers to use the AAAA record and establishes IPv6 connectivity to the target.</p>
<h3 id="heading-amazon-route-53-dns-records">Amazon Route 53 DNS records</h3>
<p>In AWS, Amazon Route 53 provides DNS capabilities. Route 53 provides features for two use cases:</p>
<ul>
<li>Public DNS for externally hosted content</li>
<li>DNS capability within a VPC both from a resolver and authoritative name server standpoint</li>
</ul>
<h4 id="heading-public-ipv6-dns-resolution">Public IPv6 DNS resolution</h4>
<p>For externally queryable DNS, you can use Route 53 public hosted zones, with both A and AAAA records. </p>
<p>Route 53 health checks support health checking IPv6 services. </p>
<p>The name servers exist both for IPv4 and IPv6, meaning clients wanting to resolve a FQDN hosted on Route 53 public hosted zone can do so natively.</p>
<h4 id="heading-dns-resolution-within-a-vpc">DNS resolution within a VPC</h4>
<p>Amazon VPC comes with Route 53 Resolver, which provides a built-in capability for resolving DNS names. </p>
<p>This resolver is reachable either on 169.254.169.253 or VPC_CIDR_NETWORK + 2 for IPv4 and fd00:ec2::253 for Nitro-based IPv6 hosts.</p>
<p>Requests sent to this resolver are resolved against the combination of private hosted zones associated with the VPC, and any (shared) resolver rules</p>
<h3 id="heading-ipv6-security-and-monitoring-considerations">IPv6 security and monitoring considerations</h3>
<h4 id="heading-network-level-access-control">Network-level access control</h4>
<p>Amazon VPCs feature two network access control mechanisms, and these exist irrespectively of which version of the IP protocol is used (IPv4 or IPv6):</p>
<ul>
<li>Security groups (SGs) at the elastic network interface level</li>
<li>Network access control lists (network ACLs) at the subnet level</li>
</ul>
<h4 id="heading-vpc-flow-logs">VPC Flow Logs</h4>
<p>VPC Flow Logs is a feature that enables you to capture information about the IPv6 traffic going to and from network interfaces in your VPC. </p>
<p>VPC Flow Logs for IPv6 traffic works the same as IPv4 where you can create flow logs at the VPC level, the subnet level, or the network interface level. </p>
<p>If you create VPC Flow Logs at a VPC or subnet level, every network interface in that VPC or subnet is monitored.</p>
<p>The flow log records can use the default format or the custom format. </p>
<p>With a custom format, you specify which fields are included in the IPv6 flow log records and in which order. </p>
<p>VPC Logs default format: </p>
<p><img src="https://user-images.githubusercontent.com/23625821/142719605-08952018-6fdf-42c5-a379-5250fc750e6c.png" alt="1" /></p>
<h4 id="heading-vpc-traffic-mirroring">VPC Traffic Mirroring</h4>
<p>VPC Traffic Mirroring is a complementary feature to flow logs that copies entire packets, including their payload of network traffic from a specified elastic network interface of an Amazon EC2 instance. </p>
<p>Traffic Mirroring copies inbound and outbound IPv4 and IPv6 traffic from the network interfaces that are attached to your Amazon EC2 instances. </p>
<p>You can send the mirrored traffic to the network interface of another EC2 instance, or a Network Load Balancer that has a UDP listener (listening on UDP port 4789 - VXLAN).</p>
<p>The mirrored traffic is sent to the traffic mirror target by means of the source VPC IPv4 route table. </p>
<p>Note that all mirrored traffic is encapsulated in an IPv4 packet. </p>
<p>Traffic Mirroring mirrors both your IPv4 and IPv6 traffic. </p>
<p>No special configuration is necessary to enable Traffic Mirroring for your IPv6 traffic, whether the traffic mirror source and the target are in the same VPC.  </p>
<p>Or in a different VPC connected via VPC peering or a Transit Gateway (as long as the traffic mirror source can route to the traffic mirror target by IPv4).</p>
<h3 id="heading-aws-web-application-firewall">AWS Web Application Firewall</h3>
<p>AWS Web Application Firewall (AWS WAF) lets you monitor the HTTP(S) requests that are forwarded to an Amazon CloudFront distribution, an Amazon API Gateway REST
API, an Application Load Balancer, or an AWS AppSync GraphQL API. </p>
<p>With AWS WAF, the services that are associated with the protected resources can respond either with the requested content or with HTTP 403 status code based on conditions that are specified, such as the IP addresses (either IPv4 or IPv6) that the request originate from.</p>
<h4 id="heading-web-acl">Web ACL</h4>
<p>You use the rules in a web ACL to block or allow web requests based on criteria which includes IP addresses or address ranges that requests originate from. </p>
<p>The IP set match statement inspects the IP address of a web request against a set of IP addresses and address ranges. </p>
<p>Use this to allow or block web requests based on the IP addresses (either IPv4 or IPv6) that the requests originate from. </p>
<p>AWS WAF IP sets supports all IPv4 and IPv6 CIDR ranges except for 0.0.0.0/0 and ::/0.</p>
<h3 id="heading-aws-shield">AWS Shield</h3>
<p>It provides protection against DDoS attacks. </p>
<p>A DDoS attack can prevent legitimate users from accessing a service and can cause the system to crash due to the overwhelming traffic volume. </p>
<p>All of the AWS Shield detection and mitigations work with IPv4 and IPv6 without any impact to performance, scalability, or availability of the service</p>
<h4 id="heading-aws-network-firewall">AWS Network Firewall</h4>
<p>AWS Network Firewall is a stateful, managed, network firewall and intrusion detection and prevention service for Amazon Virtual Private Cloud (Amazon VPC). </p>
<p>AWS Network Firewall does not currently support IPv6. In the dual-stack mode, you can still use AWS Network Firewall to filter IPv4 traffic going to and coming from an internet gateway, NAT gateway, or over VPN or AWS Direct Connect.</p>
<h4 id="heading-aws-systems-manager">AWS Systems Manager</h4>
<p>Resources managed by AWS Systems Manager must have IPv4 connectivity to Systems Manager’s endpoints. </p>
<p>For example, to connect to an EC2 instance using Systems Manager Session Manager, the instance must be running dual-stack and must have an IPv4 connectivity to the internet or AWS PrivateLink VPC endpoint. </p>
<p>Similarly, on-premises resources must also be in dual-stack network mode</p>
<h3 id="heading-scaling-the-dual-stack-network-design-in-aws">Scaling the dual-stack network design in AWS</h3>
<h4 id="heading-elastic-load-balancing">Elastic Load Balancing</h4>
<p>ELB automatically distributes your incoming traffic across multiple targets, such as EC2 instances, containers, and IP addresses, in one or more Availability Zones. </p>
<p>It supports the following types of load balancers: Application Load Balancers, Network Load Balancers, and Classic Load Balancers.</p>
<p>Both load balancer types support internet-facing and internal load balancer schemes. </p>
<p>You create internet-facing Application Load Balancers and internet-facing Network Load </p>
<p><img src="https://user-images.githubusercontent.com/23625821/142721677-274e3668-5f56-4bc5-a84f-ba34b2d1be47.png" alt="1" /></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>There are multiple driving forces behind IPv6 adoption. This paper describes what they are and explains how you can respond to them. </p>
<p>It also explains differences between IPv4 and IPv6 where applicable, and covers interoperability between both network stacks. </p>
<p>As always, security remains paramount and so this paper covered how to evolve your perimeter design to take advantage of IPv6 protocol features.</p>
<p>Remember that IPv6 only makes a difference at the network layer of the networking stack. </p>
<p>Many connectivity and security elements, especially in cloud native applications, are handled at higher layers and are therefore not affected.</p>
<p>AWS offers comprehensive IPv6 support in Amazon VPC and AWS services running at the edge of AWS Cloud. </p>
<p>You can adopt IPv6 at your own pace and focus on use cases where you will benefit the most from the adoption.</p>
<h4 id="heading-reference">Reference</h4>
<p><a href="https://d1.awsstatic.com/whitepapers/IPv6-on-AWS.pdf"> Original paper </a> </p>
]]></content:encoded></item><item><title><![CDATA[Dapr-JS SDK Overview]]></title><description><![CDATA[Dapr is a portable, serverless, event-driven runtime that makes it easy for developers to build resilient, stateless and stateful microservices that run on…]]></description><link>https://awsbuilder.hashnode.dev/dapr-js-sdk-overview</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/dapr-js-sdk-overview</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[distributed system]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[sdk]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Wed, 17 Nov 2021 20:24:40 GMT</pubDate><content:encoded><![CDATA[<p>Dapr is a portable, serverless, event-driven runtime that makes it easy for developers to build resilient, stateless and stateful microservices that run on the cloud and edge and embraces the diversity of languages and developer frameworks.</p>
<p>Dapr codifies the best practices for building microservice applications into open, independent, building blocks that enable you to build portable applications with the language and framework of your choice. Each building block is independent and you can use one, some, or all of them in your application.</p>
<p>Here is a link for creating a Dapr project with Node.JS and the Dapr-JS SDK:
https://lnkd.in/dJEHmsaH</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/empvn8ojdfhsqzzkknc2.png" alt="Image description" /></p>
<p><a href="https://docs.dapr.io/developing-applications/sdks/js/js-client/"> Dapr-JS SDK Docs </a></p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { DaprClient, DaprServer, HttpMethod, CommunicationProtocolEnum } <span class="hljs-keyword">from</span> <span class="hljs-string">"dapr-client"</span>;

<span class="hljs-keyword">const</span> daprHost = <span class="hljs-string">"127.0.0.1"</span>; <span class="hljs-comment">// Dapr Sidecar Host</span>
<span class="hljs-keyword">const</span> daprPort = <span class="hljs-string">"3500"</span>; <span class="hljs-comment">// Dapr Sidecar Port of this Example Server</span>
<span class="hljs-keyword">const</span> serverHost = <span class="hljs-string">"127.0.0.1"</span>; <span class="hljs-comment">// App Host of this Example Server</span>
<span class="hljs-keyword">const</span> serverPort = <span class="hljs-string">"50051"</span>; <span class="hljs-comment">// App Port of this Example Server </span>

<span class="hljs-comment">// HTTP</span>
<span class="hljs-keyword">const</span> server = <span class="hljs-keyword">new</span> DaprServer(
     serverHost, serverPort, 
     daprHost, daprPort
); 

<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> DaprClient(daprHost, daprPort);

<span class="hljs-comment">// GRPC </span>
<span class="hljs-keyword">const</span> server = <span class="hljs-keyword">new</span> DaprServer(
    serverHost, serverPort, 
    daprHost, daprPort, 
    CommunicationProtocolEnum.GRPC
 );

<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> DaprClient(
     daprHost, daprPort, 
     CommunicationProtocolEnum.GRPC
 );
</code></pre>
]]></content:encoded></item><item><title><![CDATA[AWS Ramp-Up Guide: Data Analytics]]></title><description><![CDATA[Here 's a link for learning plan / path for data analytics specialty on AWS: You can find it here]]></description><link>https://awsbuilder.hashnode.dev/aws-ramp-up-guide-data-analytics</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/aws-ramp-up-guide-data-analytics</guid><category><![CDATA[AWS]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[hadoop]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Wed, 17 Nov 2021 07:20:02 GMT</pubDate><content:encoded><![CDATA[<p>Here 's a link for learning plan / path for data analytics specialty on AWS: </p>
<p>You can find it <a href="https://d1.awsstatic.com/training-and-certification/ramp-up_guides/Ramp-Up_Guide_Data_Analytics.pdf"> here </a></p>
]]></content:encoded></item><item><title><![CDATA[AWS Key Management Service Best Practices | AWS White Paper Summary]]></title><description><![CDATA[AWS Key Management Service (AWS KMS) is a managed service that allows you to concentrate on the cryptographic needs of your applications while Amazon Web…]]></description><link>https://awsbuilder.hashnode.dev/aws-key-management-service-best-practices-or-aws-white-paper-summary</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/aws-key-management-service-best-practices-or-aws-white-paper-summary</guid><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[best practices]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Mon, 15 Nov 2021 06:02:01 GMT</pubDate><content:encoded><![CDATA[<p>AWS Key Management Service (AWS KMS) is a managed service that allows you to concentrate on the cryptographic needs of your applications while Amazon Web Services (AWS) manages availability, physical security, logical access control, and maintenance of the underlying infrastructure. </p>
<p>Further, AWS KMS allows you to audit the usage of your keys by providing logs of all API calls made on them to help you meet compliance and regulatory requirements.</p>
<p>Customers want to know how to effectively implement AWS KMS in their environment. </p>
<p>This whitepaper discusses how to use AWS KMS for each capability described in the AWS Cloud Adoption Framework Security Perspective whitepaper, including the differences between the different types of customer master keys, using AWS KMS key policies to ensure least privilege, auditing the use of the keys, and listing some use cases that work to protect sensitive information within AWS.</p>
<h3 id="identity-and-access-management">Identity and Access Management</h3>
<p>The Identity and Access Management capability provides guidance on determining the controls for access management within AWS KMS to secure your infrastructure according to established best practices and internal policies.</p>
<h4 id="aws-kms-and-iam-policies">AWS KMS and IAM Policies</h4>
<p>You can use AWS Identity and Access Management (IAM) policies in combination with key policies to control access to your customer master keys (CMKs) in AWS KMS. </p>
<p>This section discusses using IAM in the context of AWS KMS.  It doesn’t provide detailed information about the IAM service. </p>
<p>Policies attached to IAM identities (that is, users, groups, and roles) are called identity-based policies (or IAM policies). </p>
<p>Policies attached to resources outside of IAM are called resource-based policies. </p>
<p>In AWS KMS, you must attach resource-based policies to your customer master keys (CMKs). </p>
<p>These are called key policies. All KMS CMKs have a key policy, and you must use it to control access to a CMK. </p>
<p>IAM policies by themselves are not sufficient to allow access to a CMK, although you can use them in combination with a CMK key policy. </p>
<p>To do so, ensure that the CMK key policy includes the policy statement that enables IAM policies.</p>
<h4 id="key-policies">Key Policies</h4>
<p>Key policies are the primary way to control access to CMKs in AWS KMS. Each CMK has a key policy attached to it that defines permissions on the use and management of the key. </p>
<p>The default policy enables any principals you define, as well as enables the root user in the account to add IAM policies that reference the key. </p>
<p>We recommend that you edit the default CMK policy to align with your organization’s best practices for least privilege. </p>
<p>To access an encrypted resource, the principal needs to have permissions to use the resource, as well as to use the encryption key that protects the resource. </p>
<p>If the principal does not have the necessary permissions for either of those actions, the request to use the encrypted resource will be denied.</p>
<h4 id="least-privilege-separation-of-duties">Least Privilege / Separation of Duties</h4>
<p>Key policies specify a resource, action, effect, principal, and conditions to grant access to CMKs. </p>
<p>Key policies allow you to push more granular permissions to CMKs to enforce least privilege. </p>
<p>For example, an application might make a KMS API call to encrypt data but there is no use case for that same application to decrypt data. </p>
<p>In that use case, a key policy could grant access to the kms:Encrypt action but not kms:Decrypt and reduce the possibility for exposure. </p>
<p>Additionally, AWS allows you to separate the usage permissions from administration permissions associated with the key. </p>
<p>This means that an individual may have the ability to manipulate the key policy, but might not have the necessary permissions to use the key for cryptographic functions.</p>
<h3 id="cross-account-sharing-of-keys">Cross Account Sharing of Keys</h3>
<p>Delegation of permissions to a CMK within AWS KMS can occur when you include the root principal of a trusted account within the CMK key policy. </p>
<p>The trusted account then has the ability to further delegate these permissions to IAM users and roles within their own account using IAM policies. </p>
<p>While this approach may simplify the management of the key policy, it also relies on the trusted accounts to ensure that the delegated permissions are managed. </p>
<p>The other approach would be to explicitly manage permissions to all authorized users using only the KMS key policy, which could make the key policy complex and less manageable. </p>
<p>Regardless of the approach you take, the specific trust should be broken out on a per key basis to ensure that you adhere to the least privilege model.</p>
<h3 id="cmk-grants">CMK Grants</h3>
<p>Key policy changes follow the same permissions model used for policy editing elsewhere in AWS. </p>
<p>That is, users either have permission to change the key policy or they do not. </p>
<p>Users with the PutKeyPolicy permission for a CMK can completely replace the key policy for a CMK with a different key policy of their choice. </p>
<p>You can use key policies to allow other principals to access a CMK, but key policies work best for relatively static assignments of permissions. </p>
<p>To enable more granular permissions management, you can use grants. </p>
<p>Grants are useful when you want to define scoped-down, temporary permissions to use your CMK on your behalf in the absence of a direct API call from you.</p>
<h3 id="encryption-context">Encryption Context</h3>
<p>In addition to limiting permission to the AWS KMS APIs, AWS KMS also gives you the ability to add an additional layer of authentication for your KMS API calls utilizing encryption context. </p>
<p>The encryption context is a key-value pair of additional data that you want associated with AWS KMS-protected information. </p>
<p>This is then incorporated into the additional authenticated data (AAD) of the authenticated encryption in AWS KMS-encrypted ciphertexts. </p>
<p>If you submit the encryption context value in the encryption operation, you are required to pass it in the corresponding decryption operation. </p>
<p>You can use the encryption context inside your policies to enforce tighter controls for your encrypted resources.</p>
<p>Because the encryption context is logged in CloudTrail, you can get more insight into the usage of your keys from an audit perspective. </p>
<p>Be aware that the encryption context is not encrypted and will be visible within CloudTrail logs. </p>
<p>The encryption context should not be considered sensitive information and should not require secrecy.</p>
<h3 id="multi-factor-authentication">Multi-Factor Authentication</h3>
<p>To provide an additional layer of security over specific actions, you can implement an additional layer of protection using multi-factor authentication (MFA) on critical KMS API calls. </p>
<p>Some of those calls are PutKeyPolicy, ScheduleKeyDeletion, DeleteAlias, and DeleteImportedKeyMaterial. </p>
<p>This can be accomplished through a conditional statement within the key policy that checks for when or if an MFA device was used as part of authentication.</p>
<p>If someone attempts to perform one of the critical AWS KMS actions, the following CMK policy will validate that their MFA was authenticated within the last 300 seconds, or 5 minutes, before performing the action.</p>
<pre><code class="lang-json">{
 <span class="hljs-attr">"Sid"</span>: <span class="hljs-string">"MFACriticalKMSEvents"</span>,
 <span class="hljs-attr">"Effect"</span>: <span class="hljs-string">"Allow"</span>,
 <span class="hljs-attr">"Principal"</span>: {
    <span class="hljs-attr">"AWS"</span>: <span class="hljs-string">"arn:aws:iam::111122223333:user/ExampleUser"</span>
 },
 <span class="hljs-attr">"Action"</span>: [
   <span class="hljs-string">"kms:DeleteAlias"</span>,
   <span class="hljs-string">"kms:DeleteImportedKeyMaterial"</span>,
   <span class="hljs-string">"kms:PutKeyPolicy"</span>,
   <span class="hljs-string">"kms:ScheduleKeyDeletion"</span>
 ],
 <span class="hljs-attr">"Resource"</span>: <span class="hljs-string">"*"</span>,
 <span class="hljs-attr">"Condition"</span>:{
    <span class="hljs-attr">" NumericLessThan "</span>:{<span class="hljs-attr">"aws: MultiFactorAuthAge"</span>:<span class="hljs-string">"300"</span>}
  }
}
</code></pre>
<h3 id="detective-controls">Detective Controls</h3>
<p>The Detective Controls capability ensures that you properly configure AWS KMS to log the necessary information you need to gain greater visibility into your environment.</p>
<h4 id="cmk-auditing">CMK Auditing</h4>
<p>AWS KMS is integrated with CloudTrail. To audit the usage of your keys in AWS KMS, you should enable CloudTrail logging in your AWS account. </p>
<p>This ensures that all KMS API calls made on keys in your AWS account are automatically logged in files that are then delivered to an Amazon Simple Storage Service (S3) bucket that you specify. Using the information collected by CloudTrail, you can determine what request was made, the source IP address from which the request was made, who made the request, when it was made, and so on. </p>
<p>AWS KMS integrates natively with many other AWS services to make monitoring easy. </p>
<p>You can use these AWS services, or your existing security tool suite, to monitor your CloudTrail logs for specific actions such as ScheduleKeyDeletion, PutKeyPolicy, DeleteAlias, DisableKey, DeleteImportedKeyMaterial on your KMS key. Furthermore, AWS KMS emits Amazon CloudWatch Events when your CMK is rotated, deleted, and imported key material in your CMK expires.</p>
<h4 id="cmk-use-validation">CMK Use Validation</h4>
<p>In addition to capturing audit data associated with key management and use, you should ensure that the data you are reviewing aligns with your established best practices and policies. One method is to continuously monitor and verify the CloudTrail logs as they come in. </p>
<p>Another method is to use AWS Config rules. By using AWS Config rules you can ensure that the configuration of many of the AWS services are set up appropriately. </p>
<p>For example, with EBS volumes you can use the AWS Config rule ENCRYPTED_VOLUMES to validate that attached EBS volumes are encrypted.</p>
<p>A CMK can have a tag applied to it for a variety of purposes. </p>
<p>The most common use is to correlate a specific CMK back to a business category (such as a cost center, application name, or owner). </p>
<p>The tags can then be used to verify that the correct CMK is being used for a given action. </p>
<p>For example, in CloudTrail logs, for a given KMS action you can verify that the CMK being used belongs to the same business category as the resource that it’s being used on. Previously, this might have required a look up within a resource catalog, but now this external lookup is not required because of tagging within AWS KMS as well as many of the other AWS services.</p>
<h3 id="infrastructure-security">Infrastructure Security</h3>
<p>The Infrastructure Security capability provides you with best practices on how to configure AWS KMS to ensure that you have an agile implementation that can scale with your business while protecting your sensitive information.</p>
<h4 id="customer-master-keys">Customer Master Keys</h4>
<p>Within AWS KMS, your key hierarchy starts with a CMK. A CMK can be used to directly encrypt data blocks up to 4 KB or it can be used to secure data keys, which protect underlying data of any size.</p>
<p>CMKs can be broken down into two general types: AWS-managed and customer-managed. </p>
<p>An AWSmanaged CMK is created when you choose to enable server-side encryption of an AWS resource under the AWS-managed CMK for that service for the first time (e.g., SSE-KMS). </p>
<p>The AWS-managed CMK is unique to your AWS account and the Region in which it’s used. </p>
<p>An AWS-managed CMK can only be used to protect resources within the specific AWS service for which it’s created. It does not provide the level of granular control that a customer-managed CMK provides. </p>
<p>For more control, a best practice is to use a customer-managed CMK in all supported AWS services and in your applications. A customer-managed CMK is created at your request and should be configured based upon your explicit use case.</p>
<p><img src="https://user-images.githubusercontent.com/23625821/141607731-83fbeec0-91e6-4d36-b18a-e75090acc6a1.png" alt="1" /></p>
<h4 id="key-creation-and-management">Key Creation and Management</h4>
<p>Since AWS makes creating and managing keys easy through the use of AWS KMS, we recommend that you have a plan for how to use the service to best control the blast radius around individual keys.</p>
<p>Previously, you may have used the same key across different geographic regions, environments, or even applications. With AWS KMS, you should define data classification levels and have at least one CMK per level. </p>
<p>For example, you could define a CMK for data classified as “Confidential,” and so on. This ensures that authorized users only have permissions for the key material that they require to complete their job.</p>
<p>You should also decide how you want to manage usage of AWS KMS. </p>
<p>Creating KMS keys within each account that requires the ability to encrypt and decrypt sensitive data works best for most customers, but another option is to share the CMKs from a few centralized accounts. </p>
<p>Maintaining the CMKs in the same account as the majority of the infrastructure using them helps users provision and run AWS services that use those keys. AWS services don’t allow for cross-account searching unless the principal doing the searching has explicit List* permissions on resources owned by the external account. </p>
<p>This can also only be accomplished via the CLI or SDK, and not through service console-based searches. Additionally, by storing the credentials in the local accounts, it might be easier to delegate permissions to individuals who know the IAM principals that require access to the specific CMKs. </p>
<p>If you were sharing the keys via a centralized model, the AWS KMS administrators would need to know the full Amazon Resource Name (ARN) for all users of the CMKs to ensure least privilege. </p>
<p>Otherwise, the administrators might provide overly permissive permissions on the keys.</p>
<h4 id="key-aliases">Key Aliases</h4>
<p>A key alias allows you to abstract key users away from the underlying Region-specific key ID and key ARN. </p>
<p>Authorized individuals can create a key alias that allows their applications to use a specific CMK independent of the Region or rotation schedule. </p>
<p>Thus, multi-Region applications can use the same key alias to refer to KMS keys in multiple Regions without worrying about the key ID or the key ARN. </p>
<p>You can also trigger manual rotation of a CMK by pointing a given key alias to a different CMK. Similar to how Domain Name Services (DNS) allows the abstraction of IP addresses, a key alias does the same for the key ID. </p>
<p>When you are creating a key alias, we recommend that you determine a naming scheme that can be applied across your accounts such as alias/Environment-Function-Service Team.</p>
<p>It should be noted that CMK aliases can’t be used within policies. This is because the mapping of aliases to keys can be manipulated outside the policy, which would allow for an escalation of privilege. Therefore, key IDs must be used in KMS key policies, IAM policies, and KMS grants.</p>
<h3 id="using-aws-kms-at-scale">Using AWS KMS at Scale</h3>
<p>AWS recommends using envelope encryption to scale your KMS implementation. Envelope encryption is the practice of encrypting plaintext data with a unique data key, and then encrypting the data key with a key encryption key (KEK). Within AWS KMS, the CMK is the KEK. </p>
<p>You can encrypt your message with the data key and then encrypt the data key with the CMK. Then the encrypted data key can be stored along with the encrypted message. </p>
<p>You can cache the plaintext version of the data key for repeated use, reducing the number of requests to AWS KMS. Additionally, envelope encryption can help to design your application for disaster recovery. You can move your encrypted data as-is between Regions and only have to re-encrypt the data keys with the Region-specific CMKs.</p>
<h3 id="data-protection">Data Protection</h3>
<p>The Data Protection capability addresses some of the common AWS use cases for using AWS KMS within your organization to protect your sensitive information.</p>
<h4 id="common-aws-kms-use-cases">Common AWS KMS Use Cases</h4>
<h5 id="encrypting-pci-data-using-aws-kms">Encrypting PCI Data Using AWS KMS</h5>
<p>Since security and quality controls in AWS KMS have been validated and certified to meet the requirements of PCI DSS Level 1 certification, you can directly encrypt Primary Account Number (PAN) data with an AWS KMS CMK. </p>
<p>The use of a CMK to directly encrypt data removes some of the burden of managing encryption libraries. </p>
<p>Additionally, a CMK can’t be exported from AWS KMS, which alleviates the concern about the encryption key being stored in an insecure manner. As all KMS requests are logged in CloudTrail, use of the CMK can be audited by reviewing the CloudTrail logs. </p>
<p>It’s important to be aware of the requests per second limit when designing applications that use the CMK directly to protect Payment Card Industry (PCI) data.</p>
<h5 id="secret-management-using-aws-kms-and-amazon-s3">Secret Management Using AWS KMS and Amazon S3</h5>
<p>Although AWS KMS primarily provides key management functions, you can leverage AWS KMS and Amazon S3 to build your own secret management solution.</p>
<p>Create a new Amazon s3 bucket to hold your secrets. Deploy a bucket policy onto the bucket to limit access to only authorized individuals and services. The secrets stored in the bucket utilize a predefined prefix per file to allow for granular control of access to the secrets. </p>
<p>Each secret, when placed in the S3 bucket, is encrypted using a specific customer-managed KMS key. Furthermore, due to the highly sensitive nature of the information being stored within this bucket, S3 access logging or CloudTrail Data Events are enabled for audit purposes. Then, when a user or service requires access to the secret, they assume an identity within AWS that has permissions to use both the object in the S3 bucket as well as the KMS key. An application that runs in an EC2 instance uses an instance role that has the necessary permissions.</p>
<h5 id="encrypting-lambda-environment-variables">Encrypting Lambda Environment Variables</h5>
<p>By default, when you create or update Lambda functions that use environment variables, those variables are encrypted using AWS KMS. When your Lambda function is invoked, those values are decrypted and made available to the Lambda code. You have the option to use the default KMS key for Lambda or specify a specific CMK of your choice.</p>
<p>To further protect your environment variables, you should select the “Enable encryption helpers” checkbox. By selecting this option, your environment variables will also be individually encrypted using a CMK of your choice, and then your Lambda function will have to specifically decrypt each encrypted environment variable that is needed.</p>
<h5 id="encrypting-data-within-systems-manager-parameter-store">Encrypting Data within Systems Manager Parameter Store</h5>
<p>Amazon EC2 Systems Manager is a collection of capabilities that can help you automate management tasks at scale. </p>
<p>To efficiently store and reference sensitive configuration data such as passwords, license keys, and certificates, the Parameter Store lets you protect sensitive information within secure string parameters.</p>
<p>A secure string is any sensitive data that needs to be stored and referenced in a secure manner. </p>
<p>If you have data that you don't want users to alter or reference in clear text, such as domain join passwords or license keys, then specify those values using the Secure String data type. You should use secure strings in the following circumstances:</p>
<ul>
<li>You want to use data/parameters across AWS services without exposing the values as clear text in commands, functions, agent logs, or CloudTrail logs.</li>
<li>You want to control who has access to sensitive data.</li>
<li>You want to be able to audit when sensitive data is accessed using CloudTrail.</li>
<li>You want AWS-level encryption for your sensitive data and you want to bring your own encryption keys to manage access.</li>
</ul>
<p>By selecting this option when you create your parameter, the Systems Manager encrypts that value when it’s passed into a command and decrypts it when processing it on the managed instance. The encryption is handled by AWS KMS and can be either a default KMS key for the Systems Manager or you can specify a specific CMK per parameter.</p>
<h3 id="enforcing-data-at-rest-encryption-within-aws-services">Enforcing Data at Rest Encryption within AWS Services</h3>
<p>Your organization might require the encryption of all data that meets a specific classification. Depending on the specific service, you can enforce data encryption policies through preventative or detective controls. For some services like Amazon S3, a policy can prevent storing unencrypted data. For other services, the most efficient mechanism is to monitor the creation of storage resources and check whether encryption is enabled appropriately. In the event that unencrypted storage is created, you have a number of possible responses ranging from deleting the storage resource to notifying an administrator.</p>
<h3 id="conclusion">Conclusion</h3>
<p>AWS KMS provides your organization with a fully managed service to centrally control your encryption keys. Its native integration with other AWS services makes it easier for AWS KMS to encrypt the data that you store and process.</p>
<p>By taking the time to properly architect and implement AWS KMS, you can ensure that your encryption keys are secure and available for applications and their authorized users. Additionally, you can show your auditors detailed logs associated with your key usage.</p>
<h4 id="reference">Reference</h4>
<p><a href="https://docs.aws.amazon.com/whitepapers/latest/kms-best-practices/kms-best-practices.pdf#welcome"> Original paper </a> </p>
]]></content:encoded></item><item><title><![CDATA[Top 5 AWS ML Sessions to Attend at AWS re:Invent 2021]]></title><description><![CDATA[For AWS ML newbies, spend your time learning and using Amazon SageMaker, and here are the best 5 AWS Re-invent talks to help you get started quickly this…]]></description><link>https://awsbuilder.hashnode.dev/top-5-aws-ml-sessions-to-attend-at-aws-reinvent-2021</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/top-5-aws-ml-sessions-to-attend-at-aws-reinvent-2021</guid><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[Computer Vision]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Wed, 03 Nov 2021 06:36:44 GMT</pubDate><content:encoded><![CDATA[<p>For AWS ML newbies, spend your time learning and using Amazon SageMaker, and here are the best 5 AWS Re-invent talks to help you get started quickly this year!</p>
<h2 id="1-machine-learning-from-front-end-to-inference">1. Machine learning: From front end to inference</h2>
<p>Explore a real-world scenario for creating an end-to-end solution using machine learning in this lab. Create a web front end that receives user input and evaluates it using a machine learning model. Then, create and run a machine learning backend application using different AWS services.</p>
<h2 id="2-develop-your-ml-project-with-amazon-sagemaker">2. Develop your ML project with Amazon SageMaker</h2>
<p>Learn how to use Amazon SageMaker to create a whole machine learning project from start to finish in this workshop. With SageMaker Data Wrangler, get started with data exploration and analysis, data purification, and feature engineering. After that, save features in SageMaker Feature Store, extract features for training with SageMaker Processing, train a model with SageMaker training, and finally deploy it with SageMaker hosting. Learn to utilise SageMaker Studio as an IDE and SageMaker Pipelines to orchestrate the machine learning workflow.</p>
<h2 id="3-get-started-with-aws-computer-vision-services">3. Get started with AWS computer vision services</h2>
<p>We can use computer vision to improve our ability to comprehend the visual world around us. This session will provide you an overview of AWS computer vision services and show you how these pre-trained and configurable machine learning (ML) capabilities can help you get up and running quickly, even if you don't have any ML experience. Learn how to install these models on your preferred device and execute inferences locally, or how to use cloud APIs for your specific computing requirements. Investigate how AWS clients such as Shutterstock, Mirror, Tyson, and Persona use the AWS machine vision edge and cloud models for media analysis, content control, and quality inspection.</p>
<h2 id="4-applying-aws-machine-learning-to-next-gen-devops">4. Applying AWS machine learning to next-gen DevOps</h2>
<p>While DevOps technology has advanced significantly in recent years, it remains challenging. Concurrency, security, and the handling of sensitive data all necessitate expert judgement and frequently elude established techniques such as peer code reviews and unit testing. Even for companies that can afford to hire experienced code reviewers, the rapid pace at which software is generated generates large volumes of complex code that are impossible to manually examine. Learn how the AWS next-gen DevOps portfolio may assist enhance your developer's experience with machine learning (ML) capabilities to construct automation and more proactive methods that enable teams to innovate faster and with confidence by attending this chalk presentation.</p>
<h2 id="5-prepare-data-for-ml-with-ease-speed-and-accuracy">5. Prepare data for ML with ease, speed, and accuracy</h2>
<p>In this session you will discover how to use Amazon SageMaker to prepare data for machine learning in minutes. SageMaker provides data preparation tools that make it easier to label, prepare, and analyse your data. Walk through a complete data-preparation workflow, including how to use SageMaker Ground Truth to label training datasets, as well as how to extract data from numerous data sources, convert it using SageMaker Data Wrangler's prebuilt visualisation templates, and construct model features. Learn how to use SageMaker Feature Store to establish a repository for storing, retrieving, and sharing features to increase productivity.</p>
]]></content:encoded></item><item><title><![CDATA[Amazon Aurora MySQL Database Administrator’s Handbook]]></title><description><![CDATA[This paper outlines the best practices for managing database connections, setting server connection parameters, and configuring client programs, drivers…]]></description><link>https://awsbuilder.hashnode.dev/amazon-aurora-mysql-database-administrators-handbook</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/amazon-aurora-mysql-database-administrators-handbook</guid><category><![CDATA[AWS]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[Databases]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Sun, 31 Oct 2021 09:20:44 GMT</pubDate><content:encoded><![CDATA[<ul>
<li><p>This paper outlines the best practices for managing database connections, setting server connection parameters, and configuring client programs, drivers, and connectors. </p>
</li>
<li><p>It’s a recommended read for Amazon Aurora MySQL Database Administrators (DBAs) and application developers.</p>
</li>
</ul>
<h2 id="introduction">Introduction</h2>
<ul>
<li><p>Amazon Aurora MySQL (Aurora MySQL) is a managed relational database engine, wire-compatible with MySQL 5.6 and 5.7. Most of the drivers, connectors, and tools that you currently use with MySQL can be used with Aurora MySQL with little or no change.</p>
</li>
<li><p>Aurora MySQL database (DB) clusters provide advanced features such as:</p>
<ul>
<li><p>One primary instance that supports read/write operations and up to 15 Aurora Replicas that support read-only operations. </p>
</li>
<li><p>Each of the Replicas can be automatically promoted to the primary role if the current primary instance fails.</p>
</li>
<li><p>A cluster endpoint that automatically follows the primary instance in case of failover.</p>
</li>
<li><p>A reader endpoint that includes all Aurora Replicas and is automatically updated when Aurora Replicas are added or removed.</p>
</li>
<li><p>Ability to create custom DNS endpoints containing a user-configured group of database instances within a single cluster.</p>
</li>
<li><p>Internal server connection pooling and thread multiplexing for improved scalability. </p>
</li>
</ul>
</li>
</ul>
<h2 id="dns-endpoints">DNS endpoints</h2>
<ul>
<li><p>An Aurora DB cluster consists of one or more instances and a cluster volume that manages the data for those instances. </p>
</li>
<li><p>There are two types of instances:</p>
<ul>
<li><p>Primary instance – Supports read and write statements. Currently, there can be one primary instance per DB cluster.</p>
</li>
<li><p>Aurora Replica – Supports read-only statements. </p>
<ul>
<li>A DB cluster can have up to 15 Aurora Replicas. </li>
<li>The Aurora Replicas can be used for read scaling, and are automatically used as failover targets in case of a primary instance failure.</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>Amazon Aurora supports the following types of Domain Name System (DNS) endpoints:</p>
<ul>
<li><p>Cluster endpoint – Connects you to the primary instance and automatically follows the primary instance in case of failover, that is, when the current primary instance is demoted and one of the Aurora Replicas is promoted in its place.</p>
</li>
<li><p>Reader endpoint – Includes all Aurora Replicas in the DB cluster under a single DNS CNAME. You can use the reader endpoint to implement DNS round robin load balancing for read-only connections.</p>
</li>
<li><p>Instance endpoint – Each instance in the DB cluster has its own individual endpoint. You can use this endpoint to connect directly to a specific instance.</p>
</li>
<li><p>Custom endpoints – User-defined DNS endpoints containing a selected group of instances from a given cluster.</p>
</li>
</ul>
</li>
</ul>
<h2 id="connection-handling-in-aurora-mysql-and-mysql">Connection handling in Aurora MySQL and MySQL</h2>
<ul>
<li>MySQL Community Edition manages connections in a one-thread-per-connection fashion. </li>
<li>This means that each individual user connection receives a dedicated operating system thread in the mysqld process. </li>
<li><p>Issues with this type of connection handling include:</p>
<ul>
<li>Relatively high memory use when there is a large number of user connections, even if the connections are completely idle. </li>
<li>Higher internal server contention and context switching overhead when working with thousands of user connections. </li>
</ul>
</li>
</ul>
<h2 id="common-misconceptions">Common misconceptions</h2>
<p>The following are common misconceptions for database connection management: </p>
<ul>
<li><p>If the server uses connection pooling, you don’t need a pool on the application side. This isn’t true for workloads where connections are opened and torn down very frequently, and clients run relatively few statements per connection.</p>
</li>
<li><p>Idle connections don’t use memory. This isn’t true because the operating system and the database process both allocate an in-memory descriptor for each user connection. What is typically true is that Aurora MySQL uses less memory than MySQL Community Edition to maintain the same number of connections. However, memory usage for idle connections is still not zero, even with Aurora MySQL.</p>
</li>
<li><p>Downtime depends entirely on database stability and database features. This isn’t true because the application design and configuration play an important role in determining how fast user traffic can recover following a database event.</p>
</li>
</ul>
<h2 id="best-practices">Best practices</h2>
<p>The following are best practices for managing database connections and configuring connection drivers and pools.</p>
<h3 id="using-smart-drivers">Using smart drivers</h3>
<p>The cluster and reader endpoints abstract the role changes and topology changes occurring in the DB cluster. However, DNS updates are not instantaneous. </p>
<p>In addition, they can sometimes contribute to a slightly longer delay between the time a database event occurs and the time it’s noticed and handled by the application.</p>
<p>Aurora MySQL exposes near-real-time metadata about DB instances in the INFORMATION_SCHEMA.REPLICA_HOST_STATUS table.</p>
<pre><code class="lang-sql">
mysql&gt; <span class="hljs-keyword">select</span> server_id, <span class="hljs-keyword">if</span>(session_id = <span class="hljs-string">'MASTER_SESSION_ID'</span>,
<span class="hljs-string">'writer'</span>, <span class="hljs-string">'reader'</span>) <span class="hljs-keyword">as</span> <span class="hljs-keyword">role</span>, replica_lag_in_milliseconds <span class="hljs-keyword">from</span>
information_schema.replica_host_status;

+<span class="hljs-comment">-------------------+--------+-----------------------------+</span>
| server_id | role | replica_lag_in_milliseconds |
+<span class="hljs-comment">-------------------+--------+-----------------------------+</span>
| aurora-node-usw2a | writer | 0 |
| aurora-node-usw2b | reader | 19.253999710083008 |
+<span class="hljs-comment">-------------------+--------+-----------------------------+</span>
2 rows in <span class="hljs-keyword">set</span> (<span class="hljs-number">0.00</span> sec)
</code></pre>
<p>For the purpose of this whitepaper, a smart driver is a database driver or connector with the ability to read DB cluster topology from the metadata table. </p>
<p>It can route new connections to individual instance endpoints without relying on high-level cluster endpoints. </p>
<p>A smart driver is also typically capable of load balancing read-only connections across the available Aurora Replicas in a round robin fashion.</p>
<p>The MariaDB Connector/J is an example of a third-party Java Database Connectivity (JDBC) smart driver with native support for Aurora MySQL DB clusters. </p>
<p>Application developers can draw inspiration from the MariaDB driver to build drivers and connectors for languages other than Java.</p>
<p>It’s a good idea to evaluate the use of smart drivers in your setup. </p>
<p>Note that if a thirdparty driver contains Aurora MySQL–specific functionality, it doesn’t mean that it has been officially tested, validated, or certified by AWS. </p>
<p>Also note that due to the advanced built-in features and higher overall complexity, smart drivers are likely to receive updates and bug fixes more frequently than traditional (bare bones) drivers. </p>
<p>You should regularly review the driver’s release notes and use the latest available version whenever possible.</p>
<h3 id="dns-caching">DNS caching</h3>
<p>Unless you use a smart database driver, you depend on DNS record updates and DNS propagation for failovers, instance scaling, and load balancing across Aurora Replicas.</p>
<p>Currently, Aurora DNS zones use a short Time-To-Live (TTL) of five seconds. </p>
<p>Ensure that your network and client configurations don’t further increase the DNS cache TTL. </p>
<p>Remember that DNS caching can occur anywhere from your network layer, through the operating system, to the application container. </p>
<p>For example, Java virtual machines (JVMs) are notorious for caching DNS indefinitely unless configured otherwise. </p>
<p>Here are some examples of issues that can occur if you don’t follow DNS caching best practices:</p>
<ul>
<li><p>After a new primary instance is promoted during a failover, applications continue to send write traffic to the old instance. </p>
</li>
<li><p>Data-modifying statements will fail because that instance is no longer the primary instance.</p>
</li>
<li><p>After a DB instance is scaled up or down, applications are unable to connect to it. </p>
</li>
<li><p>Due to DNS caching, applications continue to use the old IP address of that instance, which is no longer valid.</p>
</li>
<li><p>Aurora Replicas can experience unequal utilization, for example, one DB instance receiving significantly more traffic than the others.</p>
</li>
</ul>
<h3 id="connection-management-and-pooling">Connection management and pooling</h3>
<p>Always close database connections explicitly instead of relying on the development framework or language destructors to do it. </p>
<p>There are situations, especially in container based or code-as-a-service scenarios, when the underlying code container isn’t immediately destroyed after the code completes. </p>
<p>In such cases, you might experience database connection leaks where connections are left open and continue to hold resources (for example, memory and locks).</p>
<h3 id="connection-scaling">Connection scaling</h3>
<p>The most common technique for scaling web service capacity is to add or remove application instances in response to changes in user traffic. </p>
<p>Each application server can use a database connection pool.</p>
<p>This approach causes the total number of database connections to grow proportionally with the number of application instances. </p>
<p>For example, 20 application servers configured with 200 database connections each would require a total of 4,000 database connections. </p>
<p>If the application pool scales up to 200 instances (for example, during peak hours), the total connection count will reach 40,000. Under a typical web application workload, most of these connections are likely idle. </p>
<p>In extreme cases, this can limit database scalability: idle connections do take server resources, and you’re opening significantly more of them than you need.</p>
<p>Also, the total number of connections is not easy to control because it’s not something you configure directly, but rather depends on the number of application servers.</p>
<ul>
<li>Tune the connection pools on application instances. Reduce the number of connections in the pool to the acceptable minimum. </li>
<li><p>This can be a stop-gap  solution, but it might not be a long-term solution as your application server fleet continues to grow.</p>
</li>
<li><p>Introduce a connection proxy between the database and the application. </p>
</li>
<li>On one side, the proxy connects to the database with a fixed number of connections. </li>
<li>On the other side, the proxy accepts application connections and can provide additional features such as query caching, connection buffering, query rewriting/routing, and load balancing.</li>
</ul>
<h3 id="transaction-management-and-autocommit">Transaction management and autocommit</h3>
<p>With autocommit enabled, each SQL statement runs within its own transaction. </p>
<p>When the statement ends, the transaction ends as well. Between statements, the client connection is not in transaction. </p>
<p>If you need a transaction to remain open for more than one statement, you explicitly begin the transaction, run the statements, and then commit or roll back the transaction.</p>
<p>With autocommit disabled, the connection is always in transaction. </p>
<p>You can commit or roll back the current transaction, at which point the server immediately opens a new one.</p>
<p>Running with autocommit disabled is not recommended because it encourages longrunning transactions where they’re not needed. </p>
<h5 id="recommendations">Recommendations:</h5>
<ul>
<li><p>Always run with autocommit mode enabled. Set the autocommit parameter to 1 on the database side (which is the default) and on the application side (which might not be the default).</p>
</li>
<li><p>Always double-check the autocommit settings on the application side. For example, Python drivers such as MySQLdb and PyMySQL disable autocommit by default.</p>
</li>
<li><p>Manage transactions explicitly by using BEGIN/START TRANSACTION and COMMIT/ROLLBACK statements. You should start transactions when you need them and commit as soon as the transactional work is done.</p>
</li>
</ul>
<h3 id="connection-handshakes">Connection handshakes</h3>
<p>A lot of work can happen behind the scenes when an application connector or a GUI tool opens a new database session. </p>
<p>Drivers and client tools commonly run series of statements to set up session configuration (e.g, SET SESSION variable = value). </p>
<p>This increases the cost of creating new connections and delays when your application can start issuing queries.</p>
<p>The cost of connection handshakes becomes even more important if your applications are very sensitive to latency. </p>
<p>OLTP or key-value workloads that expect single-digit millisecond latency can be visibly impacted if each connection is expensive to open. </p>
<p>For example, if the driver runs six statements to set up a connection and each statement takes just one millisecond to run, your application will be delayed by six milliseconds before it issues its first query.</p>
<h3 id="load-balancing-with-the-reader-endpoint">Load balancing with the reader endpoint</h3>
<p>Because the reader endpoint contains all Aurora Replicas, it can provide DNS-based, round robin load balancing for new connections. 
Every time you resolve the reader endpoint, you'll get an instance IP that you can connect to, chosen in round robin fashion.</p>
<p>DNS load balancing works at the connection level (not the individual query level). 
You must keep resolving the endpoint without caching DNS to get a different instance IP on each resolution. </p>
<h3 id="designing-for-fault-tolerance-and-quick-recovery">Designing for fault tolerance and quick recovery</h3>
<p>In large-scale database operations, you’re statistically more likely to experience issues such as connection interruptions or hardware failures. 
You must also take operational actions more frequently, such as scaling, adding, or removing DB instances and performing software upgrades.
The only scalable way of addressing this challenge is to assume that issues and changes will occur and design your applications accordingly.</p>
<h4 id="server-configuration">Server configuration</h4>
<p>There are two major server configuration variables worth mentioning in the context of this whitepaper: max_connections and max_connect_errors.</p>
<h6 id="configuration-variable-maxconnections">Configuration variable max_connections</h6>
<p>The configuration variable max_connections limits the number of database connections per Aurora DB instance. </p>
<p>The best practice is to set it slightly higher than the maximum number of connections you expect to open on each instance.</p>
<p>If you also enabled performance_schema, be extra careful with the setting. </p>
<p>The Performance Schema memory structures are sized automatically based on server configuration variables, including max_connections. </p>
<p>The higher you set the variable, the more memory Performance Schema uses. </p>
<p>In extreme cases, this can lead to out-ofmemory issues on smaller instance types.</p>
<h5 id="configuration-variable-maxconnecterrors">Configuration variable max_connect_errors</h5>
<p>The configuration variable max_connect_errors determines how many successive interrupted connection requests are permitted from a given client host. </p>
<p>If the client host exceeds the number of successive failed connection attempts, the server blocks it.</p>
<h4 id="conclusion">Conclusion</h4>
<p>Understanding and implementing connection management best practices is critical to achieve scalability, reduce downtime, and ensure smooth integration between the
application and database layers. You can apply most of the recommendations provided in this whitepaper with little to no engineering effort. The guidance provided in this whitepaper should help you introduce improvements in your current and future application deployments using Aurora MySQL DB clusters.</p>
<h3 id="reference">Reference</h3>
<p><a href="https://d1.awsstatic.com/whitepapers/RDS/amazon-aurora-connection-management-handbook.pdf?did=wp_card&amp;trk=wp_card"> Original paper </a></p>
]]></content:encoded></item><item><title><![CDATA[BLUE/GREEN AND CANARY DEPLOYMENT FOR EKS: Infrastructure Review]]></title><description><![CDATA[In the previous part of this series, we handled the CDK launch, application upload. In this part, we will handle infrastructure review of all app. Once the…]]></description><link>https://awsbuilder.hashnode.dev/bluegreen-and-canary-deployment-for-eks-infrastructure-review</link><guid isPermaLink="true">https://awsbuilder.hashnode.dev/bluegreen-and-canary-deployment-for-eks-infrastructure-review</guid><category><![CDATA[AWS]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[infrastructure]]></category><dc:creator><![CDATA[Salah Elhossiny]]></dc:creator><pubDate>Tue, 26 Oct 2021 09:40:11 GMT</pubDate><content:encoded><![CDATA[<p>In the <a href="https://awsbuilder.hashnode.dev/blue-green-and-canary-deployment-for-eks-ckv3ubu8w0zzpsss1czyf0kfy"> previous part </a> of this series, we handled the CDK launch, application upload. </p>
<p>In this part, we will handle infrastructure review of all app. </p>
<p>Once the application is pushed to the Repository, the CodePipeline will be triggered and CodeBuild will run the set of commands to dockerize the application and push it to the Amazon ECR repository. </p>
<p>CodeBuild will in turn run the kubectl commands to create the Blue and Green services on the EKS clusters if it does not exist. </p>
<p>For the first time, it will pull the Flask demo Application from the Dockerhub and deploy it on Blue as well as Green service. It should say "Your Flask application is now running on a container in Amazon Web Services" as shown below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635240813463/jn-2MqF1C.png" alt="image.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635240824245/Ug33FK8AZ.png" alt="image.png" /></p>
<p>In rare conditions, it may occur that Blue and Green service shows the same output of "Amazon Web Services", depending upon the timing of the first initial release-changes propagating through the CodePipeline. </p>
<p>However, in subsequent runs, it will deploy the Codebuild created an application on the Green service only and the updated text will show "Amazon EKS" instead of "Amazon Web Services". </p>
<p>This change in text is introduced by the amazon-eks-cicd-codebuild-eks-bg/flask-docker-app/Dockerfile with the line setting the "ENV PLATFORM". </p>
<p>Once done, the CodePipeline will remain blocked by the Approval Stage.</p>
<h2 id="access-eks">ACCESS EKS</h2>
<p>We will access the EKS resources via 2 methods shown below:</p>
<h3 id="a-review-via-aws-console">(a) Review via AWS Console:</h3>
<p>Go to Services -&gt; EKS -&gt; Clusters -&gt; Select the Cluster and confirm its Status is “Active”.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635240940076/OYmRTQ0gh.png" alt="image.png" /></p>
<p>Go to Services -&gt; EC2 -&gt; Instances -&gt; Ensure the EKS worker nodes (EC2) are in “running” state.</p>
<p>Go to the Services -&gt; EC2 -&gt; Load Balancer Ensure that the correct Load-Balancer is selected: Go to the Load Balancer -&gt; “Listeners” tab -&gt; Review the Listener rules.</p>
<p>Now under Load Balancing -&gt; Target groups, select the Monitoring Tab -&gt; Ensure that both the EKS worker nodes are “healthy”. It takes a few minutes after the application is deployed to have the Instances become “healthy”. </p>
<p>From the Description tab, note down the DNS name for accessing the application. This allows for the users to access and test the application deployed on the Green Service. </p>
<p>Thus if dns name is “dns-alb”, this application can be accessed via:</p>
<p>http://dns-alb.us-east-2.elb.amazonaws.com/?group=green</p>
<p>``
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635241030912/2ViIEpWvR.png" alt="image.png" /></p>
<h3 id="b-review-via-terminal-cli">(b) Review via Terminal CLI:</h3>
<p>If not already done in the earlier step, access the EKS cluster from your Cloud9 Terminal and run the command that is provided in the output of the CloudFormation under the field “ClusterConfigCommand”. Copy-paste this command so that your kubectl commands will point to the required EKS Cluster.
Once the config command is run, execute the following commands:</p>
<pre><code class="lang-sh">kubectl get nodes -n flask-alb

kubectl get deploy -n flask-alb

kubectl get pods -n flask-alb

kubectl get svc -n flask-alb

kubectl get ingress -n flask-alb
</code></pre>
<h2 id="check-codepipeline">CHECK CODEPIPELINE</h2>
<p>Go to Services -&gt; CodePipeline -&gt; Pipelines -&gt; CdkStackEksALBBg-[unique-string]
Review the Stages and the CodeBuild Projects to understand the implementation.
Once the Application is deployed on the Green service, access it as mentioned above: http://?group=green.</p>
<p>It is to be noted that container exposes port 5000, whereas service exposes port 80 (for blue-service) OR 8080 (for green-service) which in turn is mapped to local host port on the EC2 worker node instance.</p>
<p>After testing is completed, go to the Approval Stage and Click Approve. This will trigger the CodePipeline to execute the next stage to run the “Swap and Deploy” stage where it swaps the mapping of target-group to the blue / green service.
Thus now access the Application via Blue Service and confirm if the updated application is reflected correctly.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635241179485/oluLWWl8s.png" alt="image.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635241189477/izJeteIjZ.png" alt="image.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635241199578/T2aB1b8V8.png" alt="image.png" /></p>
<p>In the next part, we will handle the code change and canary deployment. Stay tuned! :) </p>
]]></content:encoded></item></channel></rss>