Amazon-Web-Services – Use AWS ECS to link Docker containers with multiple other containers via CloudFormation

This is an example. There is a docker container A (such as connecting to a back-end service). I run multiple containers from docker image B (such as connecting to a back-end front-end through a service). Now, I want to link all containers from B (B1, B2, B3, etc.) to container A.

How to achieve the above goals in ECS? If I create two containers (A and B) in a single task definition, then when running multiple services of this task, multiple containers of A and B will run.

Please note that I am working Use CloudFormation to achieve the above goals.

Thanks in advance.

the simplest The method is to create multiple ECS services. You can create these clusters in the same cluster or in different clusters (it really depends on how you want to set up the infrastructure). Put the service of container B behind the application load balancer, and then let The load balancer connects to each container while processing the request from container A. To perform this operation in CloudFormation, you need to create the following CloudFormation resource type:

AWS::ECS::Service

AWS::ElasticLoadBalancingV2::LoadBalancer

AWS::ElasticLoadBalancingV2::TargetGroup

AWS::ElasticLoadBalancingV2::Listener

Basically, You add each resource type to the CloudFormation template. Resources will refer to each other in these ways:

> AWS::ECS::Service -> TargetGroup’s ARN (in the LoadBalancers attribute)
> AWS::ElasticLoadBalancingV2::Listener -> LoadBalancer’s ARN (LoadBalancerArn attribute), TargetGroup’s ARN (in DefaultActions attribute)

Please note that you can use the “Scheme” attribute to make AWS::ElasticLoadBalancingV2: LoadBalancer resources are internal or Internet-facing. If you want to keep Service B confidential, you only need to set it to “Internal”.

Of course, you also need to add various resource types to build an ECS cluster/ The rest of the service, but I assume you have used this part in the template.

Once the CloudFormation stack changes are deployed, the load balancer will have a URL (you can use “Fn::GetAtt” Add it to the output of the stack: [“LogicalIDOfLBResource”,”DNSName”] – see the “DNSName” return value in the docs here). When you make a request to this URL, the load balancer will automatically connect to any B container and return a response from the container, so you You can use this URL in the A container to connect from A to B.

This is an example. There is a docker container A (such as connecting to a back-end service). I get from docker image B runs multiple containers (such as connecting to the front end of the back-end through a service). Now, I want to link all containers from B (B1, B2, B3, etc.) to container A.

How to achieve the above goals in ECS? If I create two containers (A and B) in a single task definition, then when running multiple services of this task, multiple containers of A and B will run.

Please note that I am working Use CloudFormation to achieve the above goals.

Thanks in advance.

The easiest way is to create multiple ECS services. You can use the same Create these clusters in a cluster or different clusters (it really depends on how you want to set up the infrastructure). Put the service of container B behind the application load balancer, and then let the load balancer connect to during the processing of requests from container A Individual containers. To perform this operation in CloudFormation, you need to create the following CloudFormation resource types:

AWS::ECS::Service

AWS::ElasticLoadBalancingV2::LoadBalancer

AWS::ElasticLoadBalancingV2::TargetGroup

AWS::ElasticLoadBalancingV2::Listener

Basically, you add each resource type to the CloudFormation template. Resources will refer to each other in these ways:

> AWS::ECS::Service -> TargetGroup’s ARN (in the LoadBalancers attribute)
> AWS::ElasticLoadBalancingV2::Listener -> LoadBalancer’s ARN (LoadBalancerArn attribute), TargetGroup’s ARN (in the DefaultActions attribute)

Please note that you can use the “Scheme” attribute to make the AWS::ElasticLoadBalancingV2::LoadBalancer resource internal or facing the Internet. If you want to put the service B is confidential, you only need to set it to “internal”.

Of course, you also need to add various resource types to build the rest of the ECS cluster/service, but I assume you are already in the template This section is used in .

Once the CloudFormation stack changes are deployed, the load balancer will have a URL (you can use “Fn::GetAtt” to add it to the output of the stack: [“LogicalIDOfLBResource ”,“DNSName”] – see the “DNSName” return value in the docs here). When you make a request to this URL, the load balancer will automatically connect to any B container and return a response from the container, so you can use this URL in the A container to connect from A to B.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1880 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.