如何使用AWS CLI管理 ECS服务连接?

0

【以下的问题经过翻译处理】 如何使用AWS CLI管理ECS服务连接? https://docs.aws.amazon.com/es_es/AmazonECS/latest/developerguide/service-connect.html

profile picture
专家
已提问 5 个月前14 查看次数
1 回答
0

【以下的回答经过翻译处理】 有不同的服务与服务连接集成,例如ECS、Route53、CloudMap

创建关联到Service Connect命名空间的集群:

aws ecs create-cluster  --cluster svc-cluster  --service-connect-defaults '{ "namespace": "svc-namespace" }'

您可以在CloudMap服务发现中列出服务:

aws servicediscovery --region $AWS_REGION get-namespace --id svc-namespace

您可以创建一个暴露在服务互连命名空间上的服务:

aws ecs create-service \
  --cluster svc-cluster \
  --service-name "nodejs" \
  --desired-count 1 \
  --task-definition "ecsdemo-nodejs" \
  --service-connect-configuration '{
    "enabled": true,
    "namespace": "svc-namespace",
    "services":
    [
        {
          "portName": "nodejs-port",
          "clientAliases": [
            {
                "port": 3000,
                "dnsName": "nodejs"
              }
            ]
        }
      ],
  }' \
  --launch-type FARGATE \
  --deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true}" \
  --network-configuration "awsvpcConfiguration={subnets=[subnet-123456,subnet-123456],securityGroups=[sg-123456],assignPublicIp="DISABLED"}" \
  --enable-execute-command

要检查服务之间的连通性,您可以在任务中执行ecs exec并连接到其服务发现名称。

在服务对外发布的情况下,则可以使用以下命令访问: curl http://nodejs:3000

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则