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

0

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

profile picture
전문가
질문됨 6달 전20회 조회
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
전문가
답변함 6달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠