AWS,  技术

如何在AWS中提供API服务

这里讲如何通过利用AWS提供的基础服务对外提供Service。从域名解析到Load Balancer,再到Docker Container的端口映射。

下面是结构图。

以下是几点说明:

  1. Loader Balancer 定义了internal的DNS Name (比如说:internal-daco-sbx08-102899950.us-west-2.elb.amazonaws.com ) . Route 53的 Hosted Zone里面的records就是把外部域名解析到内部的DNS
  2. Load Balancer分三种. Application Load Balancer 是HTTP级别的,Network Load Balancer是TCP级别的。
  3. ALB可以做端口映射,并根据http header(上面的例子是Host),把请求分发到Target Group.
  4. Target Group定义了外部的端口,然后管理外部端口到instance的端口。通常target group的端口和instance的端口是一样的(如果在task definition也就是docker container里面映射了外部端口),也可能不一样(如果没有映射).
  5. Target Group, Service是1:1映射。Target Group会提供health check定时check是不是健康。Task内部实现约定API,做实际check.
  6. ECS, ASG, Lauch Configuration协同工作,各司其职,提供服务和scaling,monitor等各种管理。

疑问

  1. 貌似没有配置load balancer的数量。难道这里从来不会是系统瓶颈?
  2. 关于Target Group的外部端口和docker container(task)的内部端口是一对一映射,还是随机映射,而让target group自己管理,不知道哪个是best practice。

One Comment

  • liangqi

    Target Group & Service 1:1 mapping
    One record in subDomain(prod.auw2.xx) in Route 53 & Service: 1:1 mapping. One service has its own sub domain (data-connect.prod.auw2.xx) which can be used to internal API call.
    Application Load Balance & ECS 1:1 mapping (Load Balance defines how to route to each services in cluster). So multiple records (each for one service) maps to ALB with different host name. Based on host name, ALB distribute the traffic to different Target Group (Service)
    Auto Scaling Group & ECS 1:1 mapping
    Launch Configuration & ECS 1:1 mapping (Lauch Configuration defines the instance types, AMI and etc)

Leave a Reply

Your email address will not be published. Required fields are marked *