Kiểm tra truy cập Web Tier

Kiểm tra truy cập Web Tier

  1. Trong tab Outputs của stack cfn-aws-three-tier-demo, sao chép giá trị WebTierLoadBalancerURL.
    • Dán vào trình duyệt (nhớ đổi https thành http nếu có).

AWS CloudFormation

  1. Trình duyệt hiển thị dòng chữ This Amazon EC2 instance is located in Availability Zone: kèm tên Availability Zone của instance đang xử lý request.

AWS CloudFormation

  1. Tải lại trang, tên Availability Zone sẽ đổi sang AZ khác do Application Load Balancer phân phối tải giữa các instance.

AWS CloudFormation

  1. Quay lại tab Outputs.
    • Sao chép giá trị BastionHostPIP.

AWS CloudFormation

  1. Mở terminal trên máy tính cá nhân.
    • Di chuyển tới thư mục chứa file cfn-keypair.pem.

    • SSH vào Bastion Host:

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

Trên Windows, chạy lệnh ssh trong PowerShell và bỏ qua lệnh chmod.

AWS CloudFormation

  • SSH thành công vào Bastion Host.
  1. Trên Bastion Host, tạo file ~/cfn-keypair.pem bằng vi.
    • Dán nội dung private key từ file cfn-keypair.pem trên máy tính cá nhân.

    • Lưu lại bằng :wq!.

      vi ~/cfn-keypair.pem
      

AWS CloudFormation

Chỉ sao chép private key lên Bastion Host trong môi trường lab. File này sẽ bị xóa cùng Bastion Host khi bạn xóa stack. Không chia sẻ nội dung private key.

  1. Lấy private IP của các EC2 instance ở Web Tier bằng lệnh sau trong VS Code terminal (3-Tier là giá trị mặc định của tham số EnvironmentName):

    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. Trên Bastion Host, SSH vào một EC2 instance của Web Tier bằng các lệnh sau:

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

AWS CloudFormation