Search code examples
amazon-web-servicesdockermicroservicesgrpc

Deploy containerized microservices (gRPC) to AWS ECS


I was to deploy multiple microservices to AWS ECS.

The communication protocol is gRPC.

On local env those containers are working because they are in the same network.

My questions are:

  • If I'll deploy them to AWS ECS will they work as expected?
  • I have to setup some custom VPC?

For example:

  • This is one of my gRPC servers:
 async function bootstrap() {
  const microserviceOptions = {
    transport: Transport.GRPC,
    options: {
      url: '0.0.0.0:50050',
      package: 'user',
      protoPath: path.join(
        __dirname,
        '../node_modules/@george-hutanu/slick-shared-packages/src/gRPC/proto-schemas/user.proto',
      ),
    },
  };
  const app = await NestFactory.createMicroservice(
    HasuraModule,
    microserviceOptions,
  );
  await app.listen();
}

(() => bootstrap())();

This is one of my gRPC clients:

export const gRPCUserClientConfig: ClientOptions = {
  transport: Transport.GRPC,
  options: {
    url: '0.0.0.0:50050',
    package: 'user',
    protoPath: path.join(
      __dirname,
      '../../../../node_modules/@george-hutanu/slick-shared-packages/src/gRPC/proto-schemas/user.proto',
    ),
  },
}

Those microservices being in separate containers will they know about that '0.0.0.0:50050' network?


Solution

  • It seems you're looking for service-to-service connectivity in AWS ECS and if you deploy your current setup, it won't work.

    Actually, you got 4 options to do this in AWS ECS.

    1. Elastic Load Balancing (ELB): One of the easiest approaches. Your services will have an ELB URL and your services communicate using this ELB URL.
    2. Amazon ECS Service Discovery: With this approach you will be using an AWS service called 'CloudMap' which enables direct communications between services. CloudMap maintains a DNS hostname that resolves to the internal IP addresses of your ECS tasks. CloudMap is using Route53 for creating this DNS Map.
    3. AWS App Mesh: App Mesh is a service mesh that standardizes how your services communicate, giving you end-to-end visibility by deploying a lightweight envoy proxy alongside the application container and helping to ensure high availability for your applications.
    4. ECS Service Connect: Service connect is a recently introduced service which simplifies service-to-service communication across VPC and ECS Cluster by combining the capabilities of service discovery(CloudMap) and service mesh (App Mesh) inside an ECS service configuration.