Web Tier Access Test

Web Tier Access Test

  1. In the Outputs tab of the cfn-aws-three-tier-demo stack, copy the WebTierLoadBalancerURL value.
    • Paste it into your browser (remember to change https to http if present).

AWS CloudFormation

  1. The browser shows the text This Amazon EC2 instance is located in Availability Zone: followed by the Availability Zone of the instance that handled the request.

AWS CloudFormation

  1. Reload the page, and the Availability Zone changes to another AZ because the Application Load Balancer distributes traffic across the instances.

AWS CloudFormation

  1. Go back to the Outputs tab.
    • Copy the BastionHostPIP value.

AWS CloudFormation

  1. Open a terminal on your computer.
    • Go to the folder that contains cfn-keypair.pem.

    • SSH into the Bastion Host:

      chmod 400 cfn-keypair.pem
      ssh -i cfn-keypair.pem ec2-user@<BastionHostPIP>
      

On Windows, run the ssh command in PowerShell and skip the chmod command.

AWS CloudFormation

  • You are connected to the Bastion Host over SSH.
  1. On the Bastion Host, create the file ~/cfn-keypair.pem with vi.
    • Paste the private key content from the cfn-keypair.pem file on your computer.

    • Save it with :wq!.

      vi ~/cfn-keypair.pem
      

AWS CloudFormation

Copy the private key to the Bastion Host only in a lab environment. The file is deleted together with the Bastion Host when you delete the stack. Do not share the private key content.

  1. Get the private IP addresses of the Web Tier EC2 instances with the following command in the VS Code terminal (3-Tier is the default value of the EnvironmentName parameter):

    aws ec2 describe-instances \
     --filters "Name=tag:aws:autoscaling:groupName,Values=3-Tier-WebTier-AutoScaleGroup" "Name=instance-state-name,Values=running" \
     --query "Reservations[].Instances[].PrivateIpAddress" \
     --output text
    

AWS CloudFormation 8. On the Bastion Host, SSH into one of the Web Tier EC2 instances with the following commands:

chmod 400 ~/cfn-keypair.pem
ssh -i ~/cfn-keypair.pem ec2-user@<web_tier_ec2_private_ip>

AWS CloudFormation