<?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 Justin Zhang on Medium]]></title>
        <description><![CDATA[Stories by Justin Zhang on Medium]]></description>
        <link>https://medium.com/@justinzhang90?source=rss-b6a18042cb92------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iPHFSm7wmkeQWs1tT3IEyA.jpeg</url>
            <title>Stories by Justin Zhang on Medium</title>
            <link>https://medium.com/@justinzhang90?source=rss-b6a18042cb92------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:57:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@justinzhang90/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[Why You Shouldn’t Rely on /etc/hosts in AWS]]></title>
            <link>https://medium.com/@justinzhang90/why-you-shouldnt-rely-on-etc-hosts-in-aws-bb66f4ec0b20?source=rss-b6a18042cb92------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb66f4ec0b20</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Justin Zhang]]></dc:creator>
            <pubDate>Sat, 15 Feb 2025 09:50:32 GMT</pubDate>
            <atom:updated>2025-02-15T09:50:32.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*-pZZzlCvVJKHxks9eGwDqA.jpeg" /></figure><p>Manually updating /etc/hosts for name resolution might seem convenient, but it can quickly become unmanageable as your application grows. Constantly SSH’ing into servers to update IP addresses is tedious and risky. Instead, let’s explore how AWS services—like CloudFormation, Route 53 Private Hosted Zones—can provide a scalable, automated solution.</p><h3>About Amazon Route 53 and Private Hosted Zones</h3><h4><strong>What is Amazon Route 53?</strong></h4><p>Amazon Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service. It’s designed to give developers and businesses an extremely reliable method to route users to applications, whether they run in AWS or elsewhere. It also offers domain registration, DNS health checks, and traffic management features.</p><h4><strong>What are Route 53 Private Hosted Zones?</strong></h4><p>A Private Hosted Zone in Amazon Route 53 is a type of hosted zone that is only accessible within one or more Amazon Virtual Private Clouds (VPCs). This allows you to create custom DNS names for resources that remain private within your AWS environment, enhancing both security and isolation.</p><h4>Price of Private Hosted Zone</h4><p>Pricing for Route 53 Private Hosted Zones includes a monthly charge for each hosted zone, plus usage-based charges for DNS queries. The monthly cost per private hosted zone is typically less than a dollar, but this can change based on current AWS pricing. Always consult the <a href="https://aws.amazon.com/route53/pricing/">official AWS pricing page</a> for the most accurate and up-to-date information.</p><h3>Example CloudFormation Template: DB2 &amp; AP Servers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J00YArocVLdTnzoOCY-TAw.png" /></figure><p>Below is an example that creates two EC2 instances (DB2 and AP) and registers them in a private hosted zone:</p><pre>AWSTemplateFormatVersion: &quot;2010-09-09&quot;<br>Description: Sample CFN to show Private Hosted Zone usage<br><br>Parameters:<br>  Environment:<br>    Type: String<br>    Default: dev<br>    AllowedValues:<br>      - dev<br>      - prod<br>    Description: Deployment environment to choose dev or prod<br><br>  VpcId:<br>    Type: AWS::EC2::VPC::Id<br>    Description: The ID of the VPC<br><br>  SecurityGroupCidr:<br>    Type: String<br>    Default: 10.0.0.0/16<br>    Description: CIDR block for security group ingress<br><br>  SubnetId:<br>    Type: AWS::EC2::Subnet::Id<br>    Description: The ID of the subnet<br><br>  ImageId:<br>    Type: String<br>    Default: ami-12345678  # Replace with an AWS Systems Manager parameter for the latest CentOS or other preferred image<br>    Description: The AMI ID for the instances<br><br>Resources:<br>  # -----------------------------------------------------<br>  # 1) Private Hosted Zone<br>  # -----------------------------------------------------<br>  PrivateHostedZone:<br>    Type: AWS::Route53::HostedZone<br>    Properties:<br>      HostedZoneConfig:<br>        Comment: !Sub &quot;Private hosted zone for ${Environment}&quot;<br>      Name: !Sub &quot;${Environment}.internal.example.com.&quot;  # ensures dev and prod have different domain<br>      VPCs:<br>        - VPCId: !Ref VpcId<br>          VPCRegion: !Ref &quot;AWS::Region&quot;<br><br>  # -----------------------------------------------------<br>  # 2) DB2 Security Group (optional example)<br>  # -----------------------------------------------------<br>  DB2SecurityGroup:<br>    Type: AWS::EC2::SecurityGroup<br>    Properties:<br>      GroupDescription: Allow DB2 traffic<br>      VpcId: !Ref VpcId<br>      SecurityGroupIngress:<br>        - IpProtocol: tcp<br>          FromPort: 50000<br>          ToPort: 50000<br>          CidrIp: !Ref SecurityGroupCidr<br><br>  # -----------------------------------------------------<br>  # 3) DB2 EC2 Instance (for demonstration)<br>  # -----------------------------------------------------<br>  DB2Instance:<br>    Type: AWS::EC2::Instance<br>    Properties:<br>      ImageId: !Ref ImageId<br>      InstanceType: t3.nano<br>      SecurityGroupIds:<br>        - !Ref DB2SecurityGroup<br>      SubnetId: !Ref SubnetId<br>      Tags:<br>        - Key: Name<br>          Value: !Sub &quot;DB2-${Environment}&quot;<br><br>  # -----------------------------------------------------<br>  # 4) Application EC2 Instance<br>  # -----------------------------------------------------<br>  APInstance:<br>    Type: AWS::EC2::Instance<br>    Properties:<br>      ImageId: !Ref ImageId<br>      InstanceType: t3.nano<br>      SecurityGroupIds:<br>        - !Ref DB2SecurityGroup  # or a separate AP security group<br>      SubnetId: !Ref SubnetId<br>      Tags:<br>        - Key: Name<br>          Value: !Sub &quot;AppServer-${Environment}&quot;<br><br>  # -----------------------------------------------------<br>  # 5) DNS Records in Private Hosted Zone<br>  # -----------------------------------------------------<br>  DB2DnsRecord:<br>    Type: AWS::Route53::RecordSet<br>    Properties:<br>      HostedZoneId: !Ref PrivateHostedZone<br>      Name: !Sub &quot;db2.${Environment}.internal.example.com.&quot;<br>      Type: A<br>      TTL: &#39;60&#39;<br>      ResourceRecords:<br>        - !GetAtt DB2Instance.PrivateIp<br><br>  APDnsRecord:<br>    Type: AWS::Route53::RecordSet<br>    Properties:<br>      HostedZoneId: !Ref PrivateHostedZone<br>      Name: !Sub &quot;ap.${Environment}.internal.example.com.&quot;<br>      Type: A<br>      TTL: &#39;60&#39;<br>      ResourceRecords:<br>        - !GetAtt APInstance.PrivateIp</pre><h4>How It Works</h4><ul><li><strong>Parameters</strong>: The Environment parameter toggles between dev and prod.</li><li><strong>Hosted Zone</strong>: Each environment gets its own private hosted zone (e.g., dev.internal.example.com.).</li><li><strong>Instances</strong>: We stand up DB2 and AP instances as examples.</li><li><strong>DNS Records</strong>: Registers each instance’s private IP automatically in Route 53.</li></ul><h3>Conclusion &amp; Call to Action</h3><p>Relying on /etc/hosts is cumbersome and prone to errors, especially at scale. Adopting CloudFormation and Route 53 Private Hosted Zones automates your DNS management, saves you time, and ensures reliable, consistent deployments.</p><p>Get started by:</p><ul><li>Creating a test CloudFormation stack with a private hosted zone.</li><li>Expanding templates for different environments.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb66f4ec0b20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Troubleshooting AWS EC2 Instances Not Starting via Lambda or Step Functions]]></title>
            <link>https://medium.com/@justinzhang90/troubleshooting-aws-ec2-instances-not-starting-via-lambda-or-step-functions-d7db3168b4fe?source=rss-b6a18042cb92------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7db3168b4fe</guid>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Justin Zhang]]></dc:creator>
            <pubDate>Sat, 07 Sep 2024 07:01:47 GMT</pubDate>
            <atom:updated>2024-09-07T07:01:47.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*ZRjMablBFgbM_Lf4.jpeg" /></figure><p>Have you ever tried to start an Amazon EC2 instance using AWS Lambda or Step Functions, only to find that, despite the logs showing the instance status transitioning from “stopped” to “running,” the instance never actually starts? This can be a frustrating and confusing experience, especially when you’re dealing with encrypted volumes and AWS’s error messages provide little clarity about what’s gone wrong.</p><p>This issue is more common than you might think and usually occurs when your instance’s root or attached volumes are <strong>encrypted</strong>, but the AWS service (Lambda or Step Functions) does not have the correct permissions to use the associated encryption key (KMS key).</p><p><strong>Why Does This Happen?</strong></p><p>When you start an EC2 instance with encrypted volumes using Lambda or Step Functions, the service requires permission to access and use the encryption key (typically a KMS key). If the service lacks the required permissions, AWS will attempt to start the instance but fail silently without providing a clear error about the permission issue. As a result, the EC2 instance appears to be running, but it never truly starts, leading to confusion.</p><p><strong>How to Resolve the Issue</strong></p><p>Here are the steps to ensure that your EC2 instance will start successfully when invoked via AWS Lambda or Step Functions:</p><p>1. <strong>Ensure the Lambda or Step Functions Service Role Has Access to the KMS Key</strong></p><p>The AWS service initiating the instance needs permission to use the encryption key associated with your EC2 instance’s volume. You need to add a policy in the service’s IAM role (Lambda or Step Functions) that grants access to the key. For example:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;kms:Decrypt&quot;,<br>        &quot;kms:Encrypt&quot;,<br>        &quot;kms:GenerateDataKey&quot;,<br>        &quot;kms:DescribeKey&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;arn:aws:kms:&lt;region&gt;:&lt;account-id&gt;:key/&lt;key-id&gt;&quot;<br>    }<br>  ]<br>}</pre><p>Ensure that the resource in the policy correctly matches the KMS key ARN you are using for the encrypted volumes.</p><p>2. <strong>Ensure the KMS Key Allows the Service to Use It</strong></p><p>In addition to granting permissions via the service role, you need to ensure the KMS key itself has permissions for the service to access it. Go to the KMS console, select the encryption key used for your EC2 volume, and update its key policy to allow Lambda or Step Functions access. An example policy might look like this:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;Service&quot;: &quot;lambda.amazonaws.com&quot;<br>      },<br>      &quot;Action&quot;: &quot;kms:*&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><p>By following these steps, you’ll save time troubleshooting and get your EC2 instances up and running without further confusion.</p><p>Let me know if you’d like any changes or adjustments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7db3168b4fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Using Ansible on Mac]]></title>
            <link>https://medium.com/@justinzhang90/introduction-to-using-ansible-on-mac-a-comprehensive-guide-4b0b7f9ea4a9?source=rss-b6a18042cb92------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b0b7f9ea4a9</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Justin Zhang]]></dc:creator>
            <pubDate>Fri, 26 Jan 2024 08:38:26 GMT</pubDate>
            <atom:updated>2024-01-26T08:58:35.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TY442X3HhOO04MiZTC_vBQ.png" /></figure><p>Ansible is an incredible asset for managing complex IT workflows and configurations. Its simplicity and flexibility make it a popular choice among system administrators and DevOps professionals. This article aims to guide Mac users through the process of installing and using Ansible for automation tasks.</p><h3>1. Installing Ansible using Homebrew</h3><p>One of the simplest methods to install Ansible on a Mac is through Homebrew, a popular package manager. If you haven’t installed Homebrew yet, begin by opening your terminal and executing the following command:</p><pre>/bin/bash -c &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)&quot;</pre><p>After installing Homebrew, you can easily install Ansible by running the following command in your terminal:</p><pre>brew install ansible</pre><h3>2. Installing ansible-lint</h3><p>To maintain high-quality Ansible playbooks, it’s essential to follow best practices and coding standards. ansible-lint is a tool that helps in identifying playbook issues. Install it using Homebrew:</p><pre>brew install ansible-lint</pre><p>Once installed, you can use ansible-lint to check your playbooks for common mistakes and coding standards.</p><h3>3. Creating and Adding localhost to /etc/ansible/hosts</h3><p>The /etc/ansible/hosts file is Ansible&#39;s inventory, where it locates the machines it manages. Begin by creating this file and adding the IP addresses of the desired servers. Here&#39;s how:</p><pre>sudo mkdir -p /etc/ansible<br>sudo touch /etc/ansible/hosts</pre><p>Then, add your server’s IP address to the hosts file. You can use any text editor; for instance, using nano:</p><pre>sudo nano /etc/ansible/hosts</pre><p>Add localhost under a group for easy reference, like so:</p><pre>[servers]<br>localhost ansible_connection=local</pre><h3>4. Using Visual Studio Code to Create a Playbook</h3><p>You can use Visual Studio Code (VSCode) for developing Ansible playbooks. First, ensure you have VSCode installed on your Mac. Then, follow these steps:</p><h4>Install the Ansible Extension</h4><p>Open VSCode, go to the Extensions view by clicking on the square icon on the sidebar, or press Cmd+Shift+X. Search for Ansible and install the extension.<br>This extension automatically formats YAML files as Ansible playbooks when named with .ansible.yml or .ansible.yaml . You can find more details in the <a href="https://marketplace.visualstudio.com/items?itemName=redhat.ansible">extension page</a>.<br> It also integrates with ansible-lint, triggering automatically when you open or save a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHtLrrYUD4phaI_BD7lrTg.png" /></figure><h4>Create and run a Playbook for Installing Nginx</h4><p>A playbook in Ansible is a YAML file where you define automation tasks. Let’s create a simple playbook to install Nginx on mac.</p><ol><li>Create a new file in VSCode with the .ansible.yml extension, for example, install_nginx.ansible.yml .</li><li>Add the following contents to your playbook:</li></ol><pre>---<br>- name: Install Nginx on macOS<br>  hosts: servers<br>  tasks:<br>    - name: Install Nginx<br>      community.general.homebrew:<br>        name: nginx<br>        state: present<br>    - name: Start Nginx using Homebrew services<br>      ansible.builtin.command: brew services start nginx<br>      register: output<br>      changed_when: output.rc == 0</pre><p>This playbook consists of a single task to install the latest version of Nginx on all machines in the servers group (defined in your /etc/ansible/hosts file).</p><p>Run the playbook using the following command:</p><pre>ansible-playbook ./install_nginx.ansible.yml</pre><h3>5. Accessing the Nginx Default Page for Confirmation</h3><p>Open a web browser and navigate to the IP address of the server where Nginx was installed. You can use the IP address you added to your /etc/ansible/hosts file. Simply enter:</p><pre>http://[your-server-ip]:8080</pre><p>Replace [your-server-ip] with the actual IP address of your server.</p><p>If Nginx has been successfully installed and is running, you should see the Nginx default welcome page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K5g5kxjMZIKmdEo-9E63vQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b0b7f9ea4a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>