<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dipander Goyal | AWS Community Builder on Medium]]></title>
        <description><![CDATA[Stories by Dipander Goyal | AWS Community Builder on Medium]]></description>
        <link>https://medium.com/@dipandergoyal?source=rss-103836b75624------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RvkePGBcQeGL9dXpkHyq5Q.jpeg</url>
            <title>Stories by Dipander Goyal | AWS Community Builder on Medium</title>
            <link>https://medium.com/@dipandergoyal?source=rss-103836b75624------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 27 May 2026 20:39:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dipandergoyal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[AWS Savings Plan Vs Reserved Instances — Comparison]]></title>
            <link>https://medium.com/@dipandergoyal/aws-savings-plan-vs-reserved-instances-comparison-1ab10532f3b0?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ab10532f3b0</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[cloud-cost-optimization]]></category>
            <category><![CDATA[aws-cost-optimization]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[finops]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Fri, 22 Mar 2024 16:38:50 GMT</pubDate>
            <atom:updated>2024-03-22T16:44:51.805Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS Savings Plan Vs Reserved Instances — Comparison</h3><p>Below is my analysis, that covers the difference between AWS Savings Plan and Reserved Instances based on atttibutes like “<strong>pricing</strong>”, “<strong>Instance</strong>”, “<strong>account</strong>” and <strong>other attributes</strong>.</p><p><strong>Note: </strong><em>As AWS keeps on enhancing the Savings plans/Reserved instances features, this analysis is performed in </em><strong><em>Feb 2024</em></strong><em>. Always, refer to the latest information in official documentation shared by AWS. (Read </em><a href="https://aws.amazon.com/savingsplans/"><em>here</em></a><em> about savings plans and </em><a href="https://aws.amazon.com/ec2/pricing/reserved-instances/"><em>here </em></a><em>about Reserved instances.)</em></p><h3><strong>Pricing Attributes:</strong></h3><p>I tried to name the parameters so that they are self-explanatory. However, I will still explain some of them to make it more understandable.</p><p>Below is the comparison table for Pricing attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHzWcMV2n74n9FmpvY_O1Q.png" /></figure><p><strong>Commitment Type: </strong>When you buy the savings plan, you commit to AWS that you will make <strong>x dollar ($) </strong>of usage per hour for 1 OR 3 years. However, when you purchase Reserved instances, you commit AWS that you will buy <strong>x number of Ec2 instances</strong> for 1 OR 3 years. So the difference is, in the earlier, commitment is on dollars per hour, and for later it is number of Ec2 instances.</p><h3>Instance Attributes:</h3><p>As you see below, the Savings plan provides more flexibility than Reserved instances when it comes to instance-specific attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hi_yPTTSQ6I0I1HZcOuOXg.png" /></figure><p><strong>Fixed: </strong>denotes that you cannot change once a purchase is made.</p><p><strong>Flexible: </strong>denotes that you can even make modifications after the purchase.</p><h3>Account Attributes:</h3><p>If you have a large number of AWS accounts as part of AWS Organizations, then a savings plan is the only option if you want to make commitment at the Organization level rather than the AWS account level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAwKCwDm_KGH_uY9SSUZ3Q.png" /></figure><h3>Other Attributes:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MEP7JT6XrNkuNdASg2XNrg.png" /></figure><p>The explanation for some parameters falling under “<strong>Other attributes</strong>” is as follows:</p><p><strong>Capacity Reservation:</strong> this means, if AWS will reserve the capacity for your commitment. AWS only reserves the capacity for ZONAL Reserved Instances.</p><p><strong>Selling/Buying On MarketPlace:</strong> You can sell the Reserved instances if you over-committed in the past, and now your Reserved instances have become unusable because of a change in business needs. The same is the case with buying at the marketplace.</p><p><strong>Automatically Apply to Lambda/Fargate: </strong>Only applicable for a savings plan. If you commit for <strong>x dollars</strong> hourly commitment, you do not need to explicitly mention if your usage will be applicable for ec2 or lambda or fargate. It will automatically provide you the <strong>% savings</strong> on all the services it supports.</p><p><strong>Updating Plans after purchase:</strong> If you have any flexibility to modify your commitment. It’s only possible conditionally with convertible reserved instances.</p><p><strong>Queuing a purchase: </strong>If your existing commitment is nearing the expiration date, you can already make a purchase for future commitment starting from the date in future. Refer the table above to check for possibilities.</p><p><strong>Supported AWS Services:</strong> Not all the services are eligible for savings plan OR reserved instances. Check the table above for eligible AWS services falling in each category.</p><h3>Conclusion:</h3><ol><li>AWS Savings plan is more flexible than reserved instances, but your decision depends on whether you want more savings or more flexibility.</li><li>AWS recommends using Savings plans over reserved instances because of flexibility. Assess your use case and make the commitment carefully and optimize your cloud spending accordingly.</li></ol><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ab10532f3b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EKS Pod Identities-Wings To Your Pods Simplified]]></title>
            <link>https://medium.com/@dipandergoyal/eks-pod-identities-wings-to-your-pods-simplified-4e1b40e56ae4?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e1b40e56ae4</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[iam-roles]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[aws-eks]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Sun, 03 Mar 2024 21:44:34 GMT</pubDate>
            <atom:updated>2024-03-03T21:44:34.474Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever your k8s pods needed to have access to AWS services <em>(S3, DynamoDB, etc.)</em>, there are many ways of achieving that, for example, <strong>kube2iam, kiam, IRSA</strong> (IAM roles for Service Accounts), etc.</p><h4>However, during ReInvent-2023, AWS released another feature known as EKS Pod Identity which simplifies this requirement. Let’s see how.</h4><p>Before this, <strong>IRSA</strong><em>(IAM roles for Service Accounts)</em> was a commonly used approach. <a href="https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html"><em>You can read more about IRSA here.</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_bfM2smz_9XnMn5esUj24g.png" /></figure><h4>Limitations With IRSA:</h4><ol><li>You need to manage the OIDC provider. In some cases, OIDC is managed by other teams, and hence the control is compromised for the infra team.</li><li>You need to mention the OIDC provider in the IAM trust policy, which adds complexity.</li><li>You need to mention IAM role ARN using annotations in ServiceAccount.</li><li>One IAM role is restricted to an EKS cluster. Cannot be used across clusters. So need to create/manage multiple IAM roles for the same purpose.</li><li>If you need to change the IAM role associated with a service account, you may need to recreate the pods using that service account to pick up the change.</li></ol><h4>Benefits of EKS Pod Identity:</h4><ol><li>IAM roles can be used across multiple EKS clusters. Need to create and manage a lesser number of IAM roles.</li><li>IAM role trust policy can have a generic simplified assume role principal pods.eks.amazonaws.com.</li><li>Using <em>CreatePodIdentityAssociation</em> API, an association is made between this<strong> IAM role and a Kubernetes service account</strong>. So a generic IAM role and generic service accounts are created and associated with each other, without any need to use the IAM role arn in the service accounts.</li><li>It works based on the agent running as a Daemon in each node. Just another pod supporting to help grant permissions to pods.</li><li><em>Supports Role Session Tags:</em> This allows for creating more sophisticated permission policies that are reusable and can match specific attributes like cluster names, service accounts, or namespaces.</li><li><em>No Additional Cost:</em> Amazon EKS Pod Identity is available at no extra charge, which can be particularly beneficial for cost management in large-scale deployments.</li><li>You can even use tags(At agent permission level, <a href="https://docs.aws.amazon.com/eks/latest/userguide/pod-id-agent-setup.html">refer here</a>) to control which roles can be assumed by pods using identity agent.</li></ol><h4>Points to note about EKS Pod Identity:</h4><ol><li>It requires Amazon EKS cluster version 1.24 or higher, so older clusters may need to be updated before they can leverage this feature. <a href="https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html#pod-id-cluster-versions">More details here.</a></li><li>Applications need to use the latest AWS SDK versions to be compatible with EKS Pod Identity, potentially requiring updates to existing applications.</li></ol><h3>Conclusion:</h3><p>Without the need to create/manage OIDC, you can simply provide the permissions to your pods with the EKS identity feature in this simplified way. If you think, this feature is useful for your team(s), it’s the right time to think about it and use it accordingly.</p><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e1b40e56ae4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When to not use AWS S3 Intelligent Tiering]]></title>
            <link>https://medium.com/@dipandergoyal/when-to-not-use-aws-s3-intelligent-tiering-b4eefe1ee5f1?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4eefe1ee5f1</guid>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[aws-cost-optimization]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[aws-optimization]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Wed, 28 Feb 2024 15:13:13 GMT</pubDate>
            <atom:updated>2024-02-28T15:25:01.619Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>AWS S3 Intelligent-Tiering</strong> monitors access patterns and automatically moves objects that have not been accessed to lower-cost access tiers, without <strong>performance impact</strong> or <strong>operational overhead(</strong><em>Once enabled, no further changes are needed, it’s all automatic</em><strong>)</strong>.</p><p>One point to note is, AWS charges additionally for providing this capability(object monitoring and automation)</p><p>S3 Intelligent-Tiering is the ideal storage <strong><em>class for data with unknown, changing, or unpredictable access patterns, independent of object size or retention period</em>.</strong> You can use S3 Intelligent-Tiering as the default storage class for virtually any workload, especially data lakes, data analytics, new applications, and user-generated content.</p><p>To check how it works, <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/intelligent-tiering-overview.html">refer to this link</a> and to know more about costs associated with it, <a href="https://aws.amazon.com/s3/pricing/">refer to this link.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Knr1qIkajyhYFuWS.png" /></figure><h3>When to NOT use AWS S3 Intelligent Tiering</h3><p><strong>Smaller Object Sizes:</strong> <em>If you have small object sizes(</em><strong><em>More percentage of objects smaller than 128KB</em></strong><em>), then S3 auto-tiering will not be acting upon your objects, as it has a minimum eligible object size of 128 KB. These smaller objects will not be monitored and </em><strong><em>will always be charged at the Frequent Access tier rates</em></strong><em>, with no monitoring and automation charges. In this case, you can choose S3 lifecycle management to transfer the objects to lower-cost storage class.</em></p><p><strong>Consistent Access Patterns: </strong><em>If your access patterns are consistent over time and don’t vary significantly, the automatic tiering provided by S3 Intelligent-Tiering might not provide substantial benefits. In such cases, a storage class with a fixed cost structure, like S3 Standard or S3 One Zone-IA, OR configuring a LifeCycle rule will be a better choice.</em></p><p><strong>Data with a Short Lifecycle:</strong><em> If your data has a short lifecycle or if you expect to delete it soon after creation, using S3 intelligent tiering is not the right choice.</em></p><p><strong>Specific Access Requirements: </strong><em>If you have specific access requirements, such as very low-latency access or retrieval within a specific timeframe, you may prefer to keep your data in another high-performance storage class rather than the S3 Intelligent tier.</em></p><p><strong>Simplicity in Cost Management: </strong><em>If you prefer a simpler cost calculation and want to avoid the complexity associated with the automatic tiering process, you can use a single storage class like. Automatic tiering adds complexity to calculations as each automatic storage tier has different pricing plans.</em></p><h3>Conclusion</h3><p>S3 intelligent tiering is a great feature, but at the same time, careful decisions about using it or not, based on the usecase can save more money.</p><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4eefe1ee5f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Secrets Manager — BatchGetSecretValue — Single API call to retrieve a group of secrets]]></title>
            <link>https://medium.com/@dipandergoyal/aws-secrets-manager-batchgetsecretvalue-single-api-call-to-retrieve-a-group-of-secrets-cdf835cc0693?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdf835cc0693</guid>
            <category><![CDATA[aws-cli]]></category>
            <category><![CDATA[operations]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[aws-secrets-manager]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Sat, 24 Feb 2024 15:59:19 GMT</pubDate>
            <atom:updated>2024-02-28T15:18:34.598Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS Secrets Manager — BatchGetSecretValue — Single API call to retrieve a group of secrets</h3><blockquote>During ReInvent-2023, AWS released <strong>a new API for AWS Secrets Manager</strong> to retrieve the value for <strong>a group of secrets in a single API call.</strong></blockquote><h3><strong>Benefits</strong></h3><ol><li>Offers simplicity for the use cases, where you need to bring multiple secrets into your application.</li><li>No need to make iterative calls to retrieve one secret at a time.</li><li>With the <strong>BatchGetSecretValue</strong>, you can input a list of <strong>secret names or ARNs, or filter criteria, such as tags</strong> and it will return a response for all matching secrets in the same format as the existing <strong>GetSecretValue</strong> API.</li><li>You can reduce the overall amount of API calls and optimize your application.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8qTmWlxXCZy8hPM7.png" /><figcaption>AWS Secrets Manager</figcaption></figure><h3>Demo</h3><p><strong><em>Prerequisites:</em></strong></p><ol><li>You should have AWS CLI installed in your machine.</li><li>Should have below mentioned IAM permissions to perform this demo.</li><li>Should have more than secrets created to retrieve their values.</li></ol><p><strong><em>IAM Permissions:</em></strong></p><pre>secretsmanager:BatchGetSecretValue<br>secretsmanager:GetSecretValue <br>secretsmanager:ListSecrets <br>kms:Decrypt</pre><p><strong><em>Retrieve Multiple Secrets By SecretName:</em></strong></p><pre>aws secretsmanager batch-get-secret-value \<br>    --region RegionName \<br>    --secret-id-list SecretName1 SecretName2</pre><p><strong><em>Output:</em></strong></p><pre>{<br>    &quot;SecretValues&quot;: [<br>        {<br>            &quot;ARN&quot;: &quot;arn:aws:secretsmanager:region:1234567890:secret:SecretName1-abc&quot;,<br>            &quot;Name&quot;: &quot;SecretName1&quot;,<br>            &quot;VersionId&quot;: &quot;df12ddd-3232-78bv-fdfg&quot;,<br>            &quot;SecretString&quot;: &quot;{\&quot;username\&quot;:\&quot;admin\&quot;,\&quot;password\&quot;:\&quot;pass123\&quot;}&quot;,<br>            &quot;VersionStages&quot;: [<br>                &quot;AWSCURRENT&quot;<br>            ],<br>            &quot;CreatedDate&quot;: &quot;134245351.729&quot;<br>        },<br>        {<br>            &quot;ARN&quot;: &quot;arn:aws:secretsmanager:region:1234567890:secret:SecretName2-def&quot;,<br>            &quot;Name&quot;: &quot;SecretName2&quot;,<br>            &quot;VersionId&quot;: &quot;hj124lkj-3256-56hg-ethf&quot;,<br>            &quot;SecretString&quot;: &quot;{\&quot;username\&quot;:\&quot;dbuser\&quot;,\&quot;password\&quot;:\&quot;dbpass123\&quot;}&quot;,<br>            &quot;VersionStages&quot;: [<br>                &quot;AWSCURRENT&quot;<br>            ],<br>            &quot;CreatedDate&quot;: &quot;143454511.142&quot;<br>        }<br>    ],<br>    &quot;Errors&quot;: []<br>}</pre><p><strong><em>Retrieve Multiple Secrets With Filters:</em></strong></p><pre>aws secretsmanager batch-get-secret-value \<br>    --region RegionName \<br>    --filters Key=&quot;name&quot;,Values=&quot;dbSecret&quot;</pre><p>It will return all the secrets which has “dbsecret” in the Secret names.</p><h3>Summary:</h3><p>A useful and easy-to-integrate feature with minimum changes into your existing code that can save a lot of API calls and can save money if you are making thousands of API calls daily to get different secrets.</p><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdf835cc0693" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS KMS Symmetric Key — Encrypt & Decrypt Data More Than 4KB]]></title>
            <link>https://medium.com/@dipandergoyal/aws-kms-symmetric-key-encrypt-decrypt-data-more-than-4kb-9d04199d198d?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d04199d198d</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-kms]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 13:55:33 GMT</pubDate>
            <atom:updated>2024-04-23T15:38:31.059Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@dipandergoyal/aws-kms-symmetric-key-encrypt-decrypt-data-upto-4kb-efd182c1ff0f?source=your_stories_page-------------------------------------">AWS KMS Symmetric Key — Encrypt &amp; Decrypt Data More Than 4KB</a></h3><h3>UseCase:</h3><p>In this article, we are going to <strong>implement the steps</strong> to encrypt and decrypt large data(<strong>More than 4096</strong> Bytes (4KB)) using AWS KMS Key, which intern uses envelop encryption(<a href="https://medium.com/@dipandergoyal/aws-kms-envelop-encryption-explained-9db3bd56542b"><strong><em>Read My Article here</em></strong></a>).</p><p>For encrypting data less than 4KB (Passwords, small files) <a href="https://medium.com/@dipandergoyal/aws-kms-symmetric-key-encrypt-decrypt-data-upto-4kb-efd182c1ff0f"><strong><em>follow this article.</em></strong></a></p><h3>Prerequisites:</h3><ol><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">AWS Cli should be installed</a> in your personal OR virtual machine.</li><li>base64 utility should be installed.</li><li>IAM role OR user credentials should be <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">configured using AWS CLI</a>.</li><li>AWS KMS Symmetric key should be <a href="https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html#create-symmetric-cmk">created using console</a> OR cli OR your own preferred way.</li><li>Either of <strong>‘KMS Key Policy’</strong> OR<strong> ‘IAM role/user policy’</strong> should allow kms GenerateDataKey, encrypt &amp; decrypt permissions <strong>(Shown further in the article)</strong></li><li>Data file with size greater than 4KB.</li></ol><h3>My Machine Setup:</h3><p>I have already installed <strong>AWS CLI</strong> and <strong>base64 </strong>utility in my <strong>EC2 linux machine</strong> and my ec2 is already attached with IAM role <strong><em>(Permissions shown below), </em></strong><em>so I </em><strong><em>do not need to explicitly follow the step 3</em></strong><em> mentioned in prerequisites</em>. Check below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*2qOxZNuW4XFz9qVyLsSaHg.png" /></figure><p>I have also created the KMS Symmetric key using AWS Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bnMCuzWSl13iv6ef1_zNWg.png" /></figure><p><strong>As I mentioned above</strong>, either my IAM role (attached to EC2) can have below permissions. It is known as identity based policy as it is attached to my identity (IAM Role in this case).</p><pre>&quot;kms:GenerateDataKey&quot;,<br>&quot;kms:Encrypt&quot;,<br>&quot;kms:Decrypt&quot;</pre><p><strong>OR, instead of attaching above policy to IAM role/user,</strong> you can just attach below policy to the KMS key itself (Known as resource based policy):</p><pre>{<br>            &quot;Sid&quot;: &quot;Allow use of the key&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::1234567890:role/IAMroleName&quot;<br>            },<br>            &quot;Action&quot;: [<br>                &quot;kms:Encrypt&quot;,<br>                &quot;kms:Decrypt&quot;,<br>                &quot;kms:ReEncrypt*&quot;,<br>                &quot;kms:GenerateDataKey*&quot;,<br>                &quot;kms:DescribeKey&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        }</pre><blockquote><em>Doing all this is enough for you to proceed with actual implementation steps.</em></blockquote><h3>Implementation (Encryption):</h3><p>Once all the prerequisites are met, follow below steps for encryption of large data:</p><h4><strong>#1. Generate Data Key Using KMS</strong></h4><p>Let’s generate Data key using CMK we generated earlier. It returns Data Key (<strong><em>Plaintext</em></strong>) and Encrypted Data key (<strong><em>CiphertextBlob</em></strong>).</p><p><a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#data-keys">Read more about what is data key here…</a></p><pre>aws kms generate-data-key --key-id &lt;kms_key_id&gt; --key-spec AES_256 --region &lt;region&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAdncflQTiZKNJoOcxomzg.png" /></figure><h4><strong>#2. Decode Base64 encoded Data Key</strong></h4><p>The Data Key (<strong><em>Plaintext</em></strong>) and Encrypted Data key(<strong><em>CiphertextBlob</em></strong>) generated above are Base64 encoded. Let’s decode just the <strong><em>Plaintext</em></strong>:</p><pre>echo &#39;&lt;Plaintext_Output_Above&gt;&#39; | base64 --decode &gt; ./plain_data_key.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S13cYIfxLwee4NDjgyvvHg.png" /></figure><h4><strong>#3. Encrypt Data/file using Plaintext Data Key</strong></h4><p>Let’s encrypt actual data <em>using Decoded plaintext data key</em>. I have a file with size 8.6KB available in my EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*KvlgdBWMIRzNHfEg8lCkvg.png" /></figure><pre>openssl enc -e -aes256 -in <strong>data.txt</strong> -k <strong>plain_data_key.txt</strong> &gt; <strong>encrypted_data.txt</strong></pre><p><strong><em>I get the encrypted_data.txt file as output with encrypted binary data.</em></strong></p><h4><strong>#4. Wrapping up steps for encryption</strong></h4><ol><li>Now, the encryption is complete.<strong><em> You can remove your “Plaintext” data key so that it is not misused by anyone.</em></strong></li><li>Store your Encrypted data key (<strong><em>CiphertextBlob</em></strong>) <strong><em>(generated as part of step #1)</em></strong> at some safe place (Secret manager etc) <strong>so that it can be used in future for decryption.</strong></li></ol><h3>Implementation (Decryption):</h3><p>Let’s follow below steps for decryption of encrypted data:</p><h4>#1. <strong>Decode “CiphertextBlob”</strong></h4><pre>echo &#39;<strong>&lt;CiphertextBlob&gt;</strong>&#39; | base64 --decode &gt; ./encrypted_data_key.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*dZ_SNG3VJ1tDifOxKHdkeA.png" /></figure><h4><strong>#2. Decrypt Encrypted Data Key</strong></h4><p>Now, we have to decrypt the data key using the Parent KMS key, using which the data key was generated (<strong><em>KMS Symmetric Key in my case</em></strong>).</p><pre>aws kms decrypt --key-id &lt;kms_key_id&gt; --ciphertext-blob fileb:///root/kms/encrypted_data_key.txt --region &lt;region&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJHeGC5mCE2O4P2K48qzFw.png" /></figure><h4><strong>#3. Decode Base64 encoded Plaintext Data Key</strong></h4><p>Same way as we did for encryption, we have to decode the “Plaintext” key:</p><pre>echo &#39;&lt;Plaintext_Output_Above&gt;&#39; | base64 --decode &gt; ./decrypted_plain_data_key.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hy0JAXulxJAsVVTqAlRvhg.png" /></figure><h4><strong>#4. Decrypt actual data</strong></h4><p>Now is the time to decrypt actual data using “<strong><em>decrypted_plain_data_key.txt</em></strong>”</p><pre>openssl enc -d -aes256 -in encrypted_data.txt -k decrypted_plain_data_key.txt</pre><p>And I get the data back:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*tmRrmSgUiCQXgMt18Jjx8Q.png" /></figure><blockquote><em>That is it! Now you can again remove the “plaintext” data key.</em></blockquote><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d04199d198d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS ECS Sidecar — Share data between containers]]></title>
            <link>https://medium.com/@dipandergoyal/aws-ecs-sidecar-share-data-between-containers-16a992480cb?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/16a992480cb</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[aws-ecs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws-ecs-fargate]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 10:37:30 GMT</pubDate>
            <atom:updated>2023-07-19T10:44:16.221Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS ECS Sidecar — Share data between containers</h3><h4>UseCase:</h4><ol><li>You are running your application in <strong>ECS with EC2 OR Fargate</strong>.</li><li>You want to run more than one container as part of single task definition and share some particular data (Folders etc) between all the containers.</li></ol><h4>Example:</h4><ol><li>Let’s say, I have a primary container running my WordPress application and it is generating the<strong> log files </strong>in the primary container at <strong><em>/myapp/logs location.</em></strong></li><li>My second container (<strong><em>Sidecar</em></strong>), has the logs processor running <strong><em>(Example: AWS Cloudwatch, Filebeat etc)</em></strong></li><li>My second container wants to access log files generated by my primary container at <strong><em>/myapp/logs location</em></strong> and send them to <strong><em>Cloudwatch/Splunk etc.</em></strong></li></ol><h4>Pre-Requisites:</h4><ol><li><em>You have container-1 and container-2(Sidecar) images ready.</em></li><li><em>You have understanding about ECS task definition to some extent.</em></li></ol><h3>Implementation:</h3><h3>Method1 — When you have just one volume to share b/w containers</h3><p><strong>#1. Modify the volumes section of your task definition</strong></p><p>In task definition volumes section, define a data volume with name and DockerVolumeConfiguration values.</p><pre>&quot;volumes&quot;: [{         <br>&quot;name&quot;: &quot;logs&quot;,         <br>&quot;dockerVolumeConfiguration&quot; : <br>  {             <br>  &quot;scope&quot;: &quot;task&quot;,      #scope can be task or shared      <br>  &quot;driver&quot;: &quot;local&quot;        <br>  }     <br>}]</pre><blockquote>The scope property value can be <strong>task or shared</strong>. With <strong>task scope, </strong>the volume is deleted after the task stops. With <strong>shared scope, </strong>volume persists even if the task stops and persists till the life cycle of the container instance (Example: EC2)</blockquote><p><strong>#2. Next step is to make changes in the container definition of container-1 and container-2 (sidecar):</strong></p><p>In the <strong>containerDefinitions </strong>section of <strong>container-1 &amp; 2</strong>, definemountPoints property that reference the name of the defined volume in the last step and the <strong>containerPath </strong>to specify the <strong>path you want to share.</strong></p><pre>&quot;containerDefinitions&quot;: [{<br> &quot;name&quot;: &quot;container-1&quot;,<br> &quot;mountPoints&quot;: [{<br>  &quot;sourceVolume&quot;: &quot;logs&quot;,<br>  &quot;containerPath&quot;: &quot;/myapp/logs&quot;<br> }]<br>}, {<br> &quot;name&quot;: &quot;container-2&quot;,<br> &quot;mountPoints&quot;: [{<br>  &quot;sourceVolume&quot;: &quot;logs&quot;,<br>  &quot;containerPath&quot;: &quot;/myapp/logs&quot;<br> }]<br>}]</pre><p>Doing this will mount the same volume to both the containers. If you are running your tasks within <strong>ECS with ec2</strong>, you can then check the docker volumes created by running <strong>docker volume ls</strong> command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*OliJBBQgYSMPSZ8lQ1Relg.png" /></figure><p>That’s it, you can now share the data across containers.</p><h3>Method2 — When you have more volumes to share b/w containers</h3><p>Assume, you have more volumes, some of them are <strong><em>local docker volumes, some of them are EBS and EFS volumes</em></strong> used by your primary container. Now if you want to s<strong><em>hare all of them with your sidecar container</em></strong> aswell, then you can use this method.</p><p><strong>#1.</strong> It is exactly the same as method one. Only difference is you can define more than one volumes. Example below:</p><pre>&quot;volumes&quot;: [{         <br>&quot;name&quot;: &quot;logs&quot;,         <br>&quot;dockerVolumeConfiguration&quot; : <br>  {             <br>  &quot;scope&quot;: &quot;task&quot;,      #scope can be task or shared      <br>  &quot;driver&quot;: &quot;local&quot;        <br>  }     <br>},<br>{         <br>&quot;name&quot;: &quot;database&quot;,         <br>&quot;dockerVolumeConfiguration&quot; : <br>  {             <br>  &quot;scope&quot;: &quot;shared&quot;,      #scope can be task or shared      <br>  &quot;driver&quot;: &quot;local&quot;        <br>  }     <br>}<br>]</pre><p><strong>#2. Make changes in the container definition of container-1 and container-2 (sidecar):</strong></p><p>In the <strong>containerDefinitions </strong>section of <strong>container-1</strong>, definemountPoints property that reference the name of the defined volume in the last step and the <strong>containerPath </strong>to specify the <strong>path you want to share.</strong></p><p>In the <strong>containerDefinitions </strong>section of <strong>container-2,</strong> define <strong>volumesFrom </strong>property that reference the name of the <strong>sourceContainer </strong>to share volumes from.</p><pre>&quot;containerDefinitions&quot;: [{<br> &quot;name&quot;: &quot;container-1&quot;,<br> &quot;mountPoints&quot;: [{<br>  &quot;sourceVolume&quot;: &quot;logs&quot;,<br>  &quot;containerPath&quot;: &quot;/myapp/logs&quot;<br> },<br> {<br>  &quot;sourceVolume&quot;: &quot;database&quot;,<br>  &quot;containerPath&quot;: &quot;/var/data&quot;<br> }<br>]<br>}, <br>{<br> &quot;name&quot;: &quot;container-2&quot;,<br> &quot;volumesFrom&quot;: [{<br>   &quot;sourceContainer&quot;: &quot;container-1&quot;,<br>   &quot;readOnly&quot;: false<br>  }]<br>}]</pre><p>Doing this will expose all the volumes used by container-1 with container-2.</p><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a992480cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS KMS Envelop Encryption — Explained]]></title>
            <link>https://medium.com/@dipandergoyal/aws-kms-envelop-encryption-explained-9db3bd56542b?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/9db3bd56542b</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[aws-kms]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 15:43:45 GMT</pubDate>
            <atom:updated>2023-07-10T16:00:19.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS KMS Envelop Encryption — Explained</h3><h3>Background:</h3><p>In the past, application teams used to store security keys<strong><em>(used for data encryption/decryption)</em></strong> in application configuration files which is a security risk if your key is exposed to intruders, they can decrypt the data.</p><h3>Introduction:</h3><p><strong>Envelope encryption</strong> is the practice of encrypting plaintext data with a <strong>data key (</strong>Explained Below<strong>)</strong>, and then encrypting the <strong>data key</strong> by using another key. In short, the actual data key (Used to encrypt the date) itself is encrypted by some other key so that it can be secured.</p><p>In below Diagram:</p><ol><li>We have a <strong>data key </strong>(Explained Below), which we use to encrypt data <strong><em>(Data in EBS, S3 or local disk etc)</em></strong></li><li>Then we definitely have to secure the data key using which we encrypted the plain format data. That’s why we encrypt the key with another key (In Diagram, AWS KMS key encrypts the data key), <strong>and doing this knows as envelop encryption.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*bho5ustHK112YrQS8-IyQg.png" /><figcaption>Snippet 1.1 -Envelop Encryption</figcaption></figure><h3>Data keys:</h3><ol><li>First of all, data key is just like any other normal key out there (Example: .pem key). Only difference is the algorithm it is generated and the purpose it serves is different.</li><li><strong><em>Data keys</em></strong> are symmetric keys you can use to encrypt data, including large amounts of data <em>(Even more than 4KB)</em> and <strong>other data encryption keys</strong>. For example: <strong>EBS, S3, RDS(encryption at rest) is achieved with the help of data keys(<em>Under the hood</em>).</strong></li><li>Unlike KMS Customer Managed Keys<em>(Not allowed to leave AWS KMS Service),</em> <strong>data keys are returned to the user for use outside of AWS KMS</strong>.</li><li>When AWS KMS generates data keys, it returns a <strong>plaintext data key </strong>for immediate use (To Encrypt the data) and an <strong>encrypted copy of the data key </strong>that you can <strong>safely store with the data</strong>. <em>Refer to the image below</em><strong><em>(Snippet 1.2).</em></strong></li><li>When you are ready to decrypt the data, you first ask AWS KMS to decrypt the <strong>encrypted copy of the data key</strong> (Mentioned in above step) and then actually decrypt the data.</li><li>AWS KMS has responsibility to <strong>only generates, encrypts, and decrypts data keys</strong>. Once data key is generated, AWS KMS does not store, manage, or track the data keys. That’s why user have to use and manage data keys outside of AWS KMS.</li><li>With the help of same AWS KMS key, you can generate as many number of data keys as you want.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ZX40omqXGBr1nVoiPntWw.png" /><figcaption>Snippet 1.2 Data Key Requested from AWS KMS Using CMK</figcaption></figure><blockquote>In the above snippet (1.2), we have requested to AWS KMS to generate the data key for us (Using KMS Symmetric Key). As a response, it returns:</blockquote><blockquote><strong>#1 — Plaintext </strong>data key</blockquote><blockquote><strong>#2 </strong>— Encrypted data key (<strong>CiphertextBlob</strong>)</blockquote><h3>How Envelope Encryption works ?</h3><h4><strong>Encryption Process:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*43ZIGCULgIwv4-ioyZk2yQ.png" /><figcaption>Snippet 1.3 — Encryption process in Envelop Encryption</figcaption></figure><ol><li>API request is sent to KMS to generate Data key using CMK. <strong>(You can do that using AWS CLI OR SDK).</strong></li><li>KMS returns response with <strong>Plain Data key</strong> and <strong>Encrypted format Data key</strong>.</li><li>The actual data (EBS, Local disk data) then can be encrypted using <strong>Plain Data key</strong>.</li><li>As the data has been encrypted, you can remove the <strong>Plain Data key</strong> from the memory.</li><li>Store Encrypted Data Key somewhere safely. It will be used in future to decrypt the data.</li></ol><h4><strong>Decryption Process:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NLb0_KEJbDNGJHQL0qlbkw.png" /><figcaption>Snippet 1.4 — Decryption process in Envelop Encryption</figcaption></figure><ol><li>Get the encrypted key from your safe.</li><li>Send an API request to AWS KMS, to decrypt the key.</li><li>KMS will return response with Plain Data Key.</li><li>Decrypt the <strong>Encrypted Data </strong>using Plain Data key.</li><li>As the data has been decrypted, you can remove the <strong>Plain Data key</strong> from the memory.</li></ol><h3>Summary:</h3><p>Basically, we have encrypted the key(which we used to encrypt the plain format data) using another key(AWS KMS key in above example). That’s how we achieve envelop encryption. You can do envelop encryption at any number of levels. <strong><em>(Example: First key is encrypted by 2nd and 2nd key is encrypted by 3rd and so on….)</em></strong></p><blockquote>I <strong>will perform the demo as part of different article and update the link here.</strong></blockquote><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9db3bd56542b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS KMS Symmetric Key — Encrypt & Decrypt Data Upto 4KB]]></title>
            <link>https://medium.com/@dipandergoyal/aws-kms-symmetric-key-encrypt-decrypt-data-upto-4kb-efd182c1ff0f?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/efd182c1ff0f</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[decryption]]></category>
            <category><![CDATA[aws-kms]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 15:15:56 GMT</pubDate>
            <atom:updated>2023-07-25T08:44:23.003Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS KMS Symmetric Key — Encrypt &amp; Decrypt Data Upto 4KB</h3><h3>What is KMS Service:</h3><p><strong>AWS Key Management Service (AWS KMS)</strong> is a managed service that makes it easy for you to create and control the cryptographic keys that are used to protect your data. AWS KMS uses hardware security modules (HSM) to protect and validate your AWS KMS keys under the FIPS 140–2 Cryptographic Module Validation Program . <a href="https://docs.aws.amazon.com/kms/latest/developerguide/overview.html"><strong>Read More…</strong></a></p><h3><strong>UseCase:</strong></h3><p>In this article, we are going to use AWS KMS key to encrypt and decrypt the data which is equal to OR less than 4096 Bytes (4KB). This data size is the limit imposed by AWS (<a href="https://aws.amazon.com/kms/faqs/#:~:text=Q%3A%20What%20is%20the%20size,of%20the%20data%20and%20returned."><strong>check here….</strong></a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*mxRaVs0dZw_nWMhQUKACXA.png" /></figure><h3>Prerequisites:</h3><ol><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">AWS Cli should be installed</a> in your personal OR virtual machine.</li><li>base64 utility should be installed.</li><li>IAM role OR user credentials should be <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">configured using AWS CLI</a>.</li><li>AWS KMS Symmetric key should be <a href="https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html#create-symmetric-cmk">created using console</a> OR cli OR your own preferred way.</li><li>Either of <strong>‘KMS Key Policy’</strong> OR<strong> ‘IAM role/user policy’</strong> should allow kms encrypt &amp; decrypt permissions <strong>(Shown further in the article)</strong></li></ol><h3>My Machine Setup:</h3><p>I have already installed <strong>AWS CLI</strong> and <strong>base64 </strong>utility in my <strong>EC2 linux machine</strong> and my ec2 is already attached with IAM role <strong><em>(Permissions shown below), </em></strong><em>so I </em><strong><em>do not need to explicitly follow the step 3</em></strong><em> mentioned in prerequisites</em>. Check below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*yKRo6xuwTUDslt45G0SkuA.png" /></figure><p>I have also created the KMS Symmetric key using AWS Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aCfSmeyuyMT8qCWT58USgA.png" /></figure><p><strong>As I mentioned above</strong>, either my IAM role (attached to EC2) can have below permissions. It is known as identity based policy as it is attached to my identity (IAM Role in this case).</p><pre>&quot;kms:Encrypt&quot;,<br>&quot;kms:Decrypt&quot;</pre><p><strong>OR, instead of attaching above policy to IAM role/user,</strong> you can just attach below policy to the KMS key itself (Known as resource based policy):</p><pre>{<br>            &quot;Sid&quot;: &quot;Allow use of the key&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::<strong>1234567890</strong>:role/<strong>roleName</strong>&quot;<br>            },<br>            &quot;Action&quot;: [<br>                &quot;kms:Encrypt&quot;,<br>                &quot;kms:Decrypt&quot;,<br>                &quot;kms:ReEncrypt*&quot;,<br>                &quot;kms:GenerateDataKey*&quot;,<br>                &quot;kms:DescribeKey&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        }</pre><blockquote>Doing all this is enough for you to proceed with actual implementation steps.</blockquote><h3><strong>Implementation:</strong></h3><p>Once all the prerequisites are met, follow below steps for encryption and decryption:</p><h3>#1 Create a file with some data:</h3><p>On your machine (In my case Linux machine), create a text file or a file of your choice. I have named this file as <strong>“data.txt”</strong> with below data. <em>Make sure that the file size is less than 4KB:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*cu6wkmE3s63xGg5wxUPQTA.png" /></figure><p>In my case the file size is even less than 1KB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*lE148imZeCqYDLuXpRoOqw.png" /></figure><h3>#2 Encrypt the File:</h3><p>Run below command to encrypt the file:</p><pre><strong>#Run Below From Linux Machine:</strong><br>aws kms encrypt \<br>    --key-id <strong>myKMSKeyId </strong>\<br>    --plaintext fileb://<strong>data.txt</strong>\<br>    --region <strong>region </strong>\<br>    --output text \<br>    --query CiphertextBlob | base64 \<br>    --decode &gt; <strong>encrypted-data.txt</strong><br><br><strong>##############################################<br>#Run Below From Windows:<br></strong><br>aws kms encrypt \<br>    --key-id <strong>myKMSKeyId </strong>\<br>    --plaintext fileb://<strong>data.txt</strong>\<br>    --output text \<br>    --query CiphertextBlob &gt; C:\Temp\<strong>encrypted-data.base64</strong><br><br>certutil -decode C:\Temp\<strong>encrypted-data.base64</strong> C:\Temp\<strong>encrypted-data</strong></pre><p>Below is the output after I executed above command(In Linux Machne). As you see I get the <strong>encrypted-data.txt </strong>file generated and having encrypted data within it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUZBFd3um-lPDY-IvgndLw.png" /></figure><p><strong>--plaintext: </strong>Uses the --plaintext parameter to indicate the data to encrypt. This parameter value must be base64-encoded. or you must use the fileb:// in file name, so that data is automatically converted into binary data.</p><p><strong>--output and </strong><strong>--query:</strong> Ideally, running the <strong>kms encrypt</strong> command returns many things(a json object). These two parameters(output and query) are used to just extract the encrypted data and nothing else.</p><p><strong>base64:</strong> Uses the base64 utility to decode the extracted output into binary data.</p><p><strong>&gt; encrypted-data.txt</strong><strong>: </strong>The final part of the command ( &gt; <strong>encrypted-data.txt</strong>) saves the binary ciphertext to a file to make decryption easier.</p><h3>#3 Decrypt the File:</h3><pre><strong>#Run Below From Linux Machine:</strong><br><br>aws kms decrypt \<br>    --ciphertext-blob fileb:/<strong>/encrypted-data.txt</strong> \<br>    --key-id <strong>myKMSKeyId </strong>\<br>    --region <strong>region </strong>\<br>    --output text \<br>    --query Plaintext | base64 \<br>    --decode &gt; <strong>myplaintext.txt<br></strong><br><strong>##############################################<br><br>#Run Below From Windows Command Prompt:</strong><br><br>aws kms decrypt ^<br>    --ciphertext-blob fileb://<strong>encrypted-data.txt</strong>^<br>    --key-id <strong>myKMSKeyId </strong>^<br>    --region <strong>region </strong>^<br>    --output text ^<br>    --query Plaintext &gt; <strong>myplaintext</strong>.base64<br><br>certutil -decode <strong>myplaintext</strong>.base64 <strong>myplaintext</strong></pre><p>Below is the output after I executed above command (In Linux Machine). As you see I get the <strong>myplaintext.txt </strong>file generated and having decrypted data within it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ID2tcMVtIsieT0uhjLDWZg.png" /></figure><p><strong>-ciphertext-blob</strong> parameter, use the fileb:// prefix, which tells the CLI to read the data from a binary file.</p><p><em>Rest all the properties are same as encryption part.</em></p><h3>Can I perform all the above with KMS — <strong>Asymmetric key aswell?</strong></h3><p>Yes, you can do the same with <strong>AWS KMS — Asymmetric key</strong> also. You just need to provide one extra command line parameter that is <strong>“ — encryption-algorithm”</strong> while running the command.</p><h3>What if my file size is more than 4KB?</h3><p>Lets see….</p><p>I will create a file of size 10kb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*OJe4t4CpAtOKK3RzA-UuFw.png" /></figure><p>If I now run the encrypt command then?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QRdNUeyLwuu8GV4I1qtiw.png" /></figure><p><strong>I get the validation exception, thrown by AWS.</strong></p><blockquote><strong><em>So does this mean that KMS cannot handle data more than 4KB? </em></strong>No, its not the case, there is way known by name <strong>“Envelope Encryption”</strong><a href="https://medium.com/@dipandergoyal/aws-kms-symmetric-key-encrypt-decrypt-data-more-than-4kb-9d04199d198d"><strong>(Read My Article Here)</strong></a><strong>.</strong></blockquote><blockquote>If you want to read about <a href="https://medium.com/@dipandergoyal/aws-kms-envelop-encryption-explained-9db3bd56542b"><strong>what is Envelope Encryption</strong> you can read that here</a>.</blockquote><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efd182c1ff0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuration Management-Confd vs Consul-Template vs Ansible]]></title>
            <link>https://medium.com/@dipandergoyal/configuration-management-confd-vs-consul-template-vs-ansible-9b7d1b08ce82?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b7d1b08ce82</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[confd]]></category>
            <category><![CDATA[consul]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Thu, 06 Jul 2023 12:26:46 GMT</pubDate>
            <atom:updated>2023-07-06T14:28:24.508Z</atom:updated>
            <content:encoded><![CDATA[<h3>Problem Statement:</h3><ol><li>Assume you are developing an application in Java (OR .Net, PHP etc) OR you have a vendor developed application.</li><li>As you know, for our <strong>application/middlewares</strong> to work, we need some configuration files <em>(For example: Nginx/apache/jboss config file OR some other application specific configuration files)</em> containing application configuration parameters, DB connection details etc.</li><li>You must be storing your application code in some <em>git repository</em> of your choice. <strong>H</strong>owever, you would not like to keep your configuration details hardcoded in the git repo (Because it is either some <em>secret values </em>OR those values are <em>changing with each environment</em> like dev/test/prod)</li><li>Your application is not written in a way to dynamically fetch those values from key-value store (Example: AWS Secrets manager, DynamoDB etc)</li><li>To have the configuration files dynamically populated with right set of values, this article can suggest you few solutions.</li></ol><h3>Solution Explanation:</h3><p>In below diagram, you can see we have three stages, <strong>inputs, Template Rendering and Output.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*LBT5BFpny3YjcDwUDf8o-A.png" /></figure><blockquote><strong>#1 Inputs stage:</strong> In this stage we need <strong>input configuration file(s)</strong> having placeholders (See below example config file with <strong>yellow highlighted</strong> placeholders) and <strong>the actual values</strong>. These actual values can be provided from any source (Example: OS level Env variables, AWS secrets Manager, DynamoDB, consul server etc)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*h-ho9rUU3UxcqO1fsQznYA.png" /><figcaption>Application Config File — WIth Placeholders highlighted in Yellow</figcaption></figure><blockquote><strong>#2 TemplateRendering Stage:</strong> In this stage, the input (Config file with placeholders and the actual values) are processed by the use of tools like confd, consul-template or Ansible or any other tool available in the market.</blockquote><blockquote>#3 <strong>Output Stage: </strong>Here we get the final rendered configuration files placed at required location within virtual machine OR docker container. Which can be used the application to work properly.</blockquote><h3>Real UseCase Example:</h3><p>Earlier in one of our application(s), we were building the Docker images and running them in AWS ECS orchestrator. we used <strong>confd </strong>to render the application config files. <em>We wanted to </em><strong><em>avoid having the configuration files with real values in the GIT as well as in the Docker Image</em></strong><em>.</em></p><p>So we kept the Dockerfile and other application configuration files<strong>(Just templates with placeholders</strong>) in the Git repository and built the docker image using the same and provided the real values to the container at runtime(<strong>as OS environment variables</strong>) using AWS Secrets Manager (through <strong>AWS ECS &amp; Secrets Manager default Integration provide by AWS) and confd(At runtime) rendered the templates </strong>and kept them at required location within container and <strong>we started the application using Docker entrypoint. </strong>(Refer Below Diagram)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wmXylUdmYuaG2W--u4OPQ.png" /></figure><p>If I put it in terms of three stages then below is how it looks:</p><ol><li><strong>Input Stage: </strong>Configuration files stored in Git Repo and actual values stored in the AWS Secrets manager.</li><li><strong>Render Stage:</strong> Confd used for rendering within Docker container.</li><li><strong>Output Stage:</strong> Config files with real values generated and placed within container at runtime.</li></ol><blockquote><strong>Note:</strong> If we use <strong>consul-template</strong> for above use case instead of <strong>confd</strong>, it will work exactly the same way, without any issues.</blockquote><h3>Comparison Confd/Consul-Template/Ansible:</h3><h3>Confd:</h3><p>confd is a lightweight configuration management tool focused on:</p><ul><li>keeping local configuration files up-to-date using data stored in <a href="https://github.com/coreos/etcd">etcd</a>, <a href="http://consul.io/">consul</a>, <a href="http://aws.amazon.com/dynamodb/">dynamodb</a>, <a href="http://redis.io/">redis</a>, <a href="https://vaultproject.io/">vault</a>, <a href="https://zookeeper.apache.org/">zookeeper</a>, <a href="https://aws.amazon.com/ec2/systems-manager/">aws ssm parameter store</a> or env vars and processing <a href="https://github.com/kelseyhightower/confd/blob/master/docs/template-resources.md">template resources</a>.</li><li>reloading applications to pick up new config file changes</li></ul><blockquote><a href="https://github.com/kelseyhightower/confd">More Information…………</a></blockquote><h4>Confd Pros:</h4><ol><li>It is very <strong>lightweight and Open Source </strong>tool, just a <strong>simple binary</strong> is need to do the job.</li><li>We can make our application <strong>environment independent</strong> (dev/test/prod etc)</li><li>It supports <strong>jinja like conditioning</strong> (if/else, loops) as part of writing templates.</li><li>We do not need to <strong>expose secrets and other important configuration</strong> values in Git repo or the docker image or the virtual machine.</li><li>confd supports many <strong>data sources (etcd, redis, AWS SSM, Vault etc)</strong>.</li><li>It can look for dynamic changes in the application configuration.</li></ol><h4>Confd Cons:</h4><ol><li>The confd new versions are not released from last 5 years. So it is not actively maintained.</li></ol><h3>Consul-Templates:</h3><p>consul-template provides convenient way to populate values from <a href="https://www.consul.io/">Consul</a> into the file system using the consul-template daemon.</p><p>The daemon consul-template queries a <a href="https://www.consul.io/"><strong>Consul</strong></a><strong>, </strong><a href="https://www.vaultproject.io/"><strong>Vault</strong></a><strong>, </strong><a href="https://www.nomadproject.io/"><strong>Nomad</strong></a><strong> cluster, or OS environment variables</strong> and updates any number of specified templates on the file system. As an added bonus, it can optionally run arbitrary commands when the update process completes.</p><blockquote><a href="https://github.com/hashicorp/consul-template">More Information…………</a></blockquote><h4>Consul-Template Pros:</h4><ol><li>It is very <strong>lightweight and Open Source </strong>tool developed and maintained by HashiCorp. New versions are being released every couple of months.</li><li>We can make our application <strong>environment independent</strong> (dev/test/prod etc)</li><li>We do not need to <strong>expose secrets and other important configuration</strong> values in Git repo or the docker image or the virtual machine.</li><li>It is feature rich tool mainly if you are using HashiCorp’s other tooling.</li><li>It can look for dynamic changes in the application configuration.</li></ol><h4>Consul-Template Cons:</h4><ol><li>It supports fewer data sources (<a href="https://www.consul.io/">Consul</a>, <a href="https://www.vaultproject.io/">Vault</a>, or <a href="https://www.nomadproject.io/">Nomad</a>). It is mainly built to have integration with Consul and other HashiCorp solution.</li></ol><h3>Ansible:</h3><p>Ansible is a radically simple IT automation system. It handles configuration management, application deployment, cloud provisioning, ad-hoc task execution, network automation, and multi-node orchestration. Ansible makes complex changes like zero-downtime rolling updates with load balancers easy.</p><blockquote><a href="https://www.ansible.com/">More Information…………</a></blockquote><h4>Ansible-Template Pros:</h4><ol><li>It is <strong>Open Source, Simple, easy to learn and well maintained, python based </strong>configuration management tool.</li><li>It is feature rich tool and has integration with plenty of tools and can be used to serve plenty of use cases.</li><li>We can make our application <strong>environment independent</strong> (dev/test/prod etc)</li><li>We do not need to <strong>expose secrets and other important configuration</strong> values in Git repo or the docker image or the virtual machine.</li></ol><h4>Ansible Cons:</h4><ol><li>If we talk about just configuration rendering <em>(Like this article is intended for)</em> then Ansible is not the right choice. You will have to do more to achieve the job. Ansible is a perfect solution for other complex use cases like if you want to configure multiple machines with some set of softwares, if you want to configure and deploy your application OR orchestrate the Cloud infra to name a few. It is advances configuration management tool not meant for just rendering templates.</li></ol><p>From HashiCorp perspective, consul-template is different from confd and ansible in following way:</p><p><a href="https://github.com/hashicorp/consul-template#faq"><em>Source: this</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*i4z6y5x5rJ-6gXDo7982WA.png" /></figure><h3>Conclusion:</h3><ol><li>All the three tools are efficient to do the job (Configuration rendering), your selection totally depends on your use case.</li><li>As such, Ansible is meant to do a lot and its pretty advanced tool to serve different use cases. But if you are just looking for your configuration rendering and a light weight solution then <strong>confd </strong>and <strong>consul-template</strong> are the right choice.</li></ol><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b7d1b08ce82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Session Manager — Connect Private subnet instances]]></title>
            <link>https://medium.com/@dipandergoyal/aws-session-manager-connect-private-subnet-instances-784c6baaacca?source=rss-103836b75624------2</link>
            <guid isPermaLink="false">https://medium.com/p/784c6baaacca</guid>
            <category><![CDATA[aws-session-manager]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws-ssm]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Dipander Goyal | AWS Community Builder]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 07:51:28 GMT</pubDate>
            <atom:updated>2023-07-04T07:51:28.589Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS Session Manager — Connect Private subnet Linux/Windows instances</h3><blockquote><strong><em>Please Note:</em></strong><em> This article assumes that you have good understanding about EC2 services and the traditional ways to open session with EC2 Linux and Windows instances.</em></blockquote><h3>UseCase Explanation:</h3><ol><li>Ideally, instance in private subnets are not directly accessible if you are not using VPN/DirectConnect connectivity.</li><li>In past, we used to have bastion host setup in public subnet and ssh tunneling to connect to private subnet instances.</li><li>In this article, we will see the more secure way to connect your instances in AWS private subnets using AWS session manager.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sIKztHg_zsg-WsULl9APoA.png" /></figure><h3>Prerequisites:</h3><p>For this article, I have used Windows laptop and Powershell as the scripting language to initiate the remote sessions. You can also use Windows bash or GitBash cli tools.</p><p>You must have the following tools and services installed on your personal computer:</p><ul><li>The <a href="https://aws.amazon.com/cli/">AWS Command Line Interface</a> (AWS CLI).</li><li>The <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html">Session Manager plugin</a> installed locally</li><li>IAM user with programmatic access. (<a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/getting-started-restrict-access-quickstart.html">Mainly session manager permissions</a>).</li></ul><p>You also need the following AWS components and services:</p><ul><li>Linux &amp; Windows EC2 instance in the private subnet.</li><li>SSM agent installed in the EC2 instance. (It also comes pre-installed by default in few AWS provided AMI’s like AWS Linux2. <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/ami-preinstalled-agent.html">Refer this</a>). Follow these instructions to <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-manual-agent-install.html">install the SSM agent</a>.</li><li>Required IAM permissions added to the new/existing IAM role. <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/getting-started-add-permissions-to-existing-profile.html">Follow this for permissions.</a></li><li>You EC2 SG should have outbound connectivity on port 443 to <em>Systems Manager endpoints</em>. So that SSM agent can communicate with the sessions manager API. OR you can also keep the outbound default rule which allows all traffic.</li></ul><h3>Implementation:</h3><p><strong>#1 </strong>Once you have EC2(Linux &amp; Windows) in private subnet with all the prerequisites (SSM agent, IAM role and SG setup), you should see the EC2 instance shown the AWS Systems Manager ===&gt; Session manager service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9d2il0JFzFHZvxPbMI_Ew.png" /></figure><p><strong>#2 </strong>(Optional) You can connect to your private EC2 instance from above screen, and it will open browser based CLI session for you.</p><h4><strong>#3</strong> To connect to private EC2 instance (<strong><em>Linux</em></strong>) from your local computer, run the following command</h4><pre>aws ssm start-session --target &lt;instance-id&gt; --region &lt;region&gt;</pre><p>It will open the session and thats it for Linux instance!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*yb0xT7nDSB-nfcXLSWAtVQ.png" /></figure><h4><strong>#4</strong> To connect to private EC2 instance (<strong><em>Windows</em></strong>) from your local computer, run the following command:</h4><pre>aws ssm start-session --target &lt;instance-id&gt; --document-name AWS-StartPortForwardingSession --parameters &quot;localPortNumber=54321,portNumber=3389&quot; --region &lt;region&gt;</pre><p>It will open the session and show below screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*vnj1AFdnCMo1YpLtZF-CbA.png" /></figure><p><em>Leave this window as it is!</em></p><p>Open RDP session window (You can grab the administrator user password from the AWS console with your EC2 private keypair)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*ljvDX11VoEnHwhWgq9h5Uw.png" /></figure><p>Enter the Administrator password and doing this will open the GUI based session for your Windows server and that is it.</p><h4>#5 What If you lost the Windows private key pair?</h4><p>If you loose your Windows private key, then you can open CLI based session with windows instance, exactly the same way you do with Linux:</p><pre>aws ssm start-session --target &lt;windows-instance-id&gt; --region &lt;region&gt;</pre><p>It will open the CLI session for you and you can add Windows user and add the user to the Administrator group(<a href="https://www.wikihow.com/Add-Users-from-CMD">Refer This</a>) and then follow the same process of <strong>AWS session manager StartPortForwardingSession </strong>and again open GUI based RDP session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWjxPWb8jKmjuqlOPYNkiw.png" /></figure><p><em>If you liked this article, please show your appreciation by </em><strong><em>clapping </em></strong><em>👏 below! Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=784c6baaacca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>