CloudFormation을 통해 Amazon ECS 서비스 검색을 사용하려면 어떻게 해야 합니까?
AWS CloudFormation을 통해 Amazon Elastic Container Service(Amazon ECS) 서비스 검색을 사용하려고 합니다.
간략한 설명
Amazon ECS 콘솔을 사용하면 서비스 생성 도중에 서비스 검색 리소스를 생성할 수 있습니다. 하지만 CloudFormation용 AWS::ECS::Service 리소스 유형을 사용하는 경우 서비스 생성 도중에 서비스 검색 리소스를 생성할 수 없습니다.
참고: Amazon ECS 콘솔은 CreatePrivateDnsNamespace, CreateService(AWS Cloud Map) 및 CreateService(Amazon ECS) 통합 API를 사용합니다. CloudFormation에서는 AWS:: ServiceDiscovery:: PrivateDnsNamespace, AWS:: ServiceDiscovery:: Service, 및 AWS:: ECS:: Service 리소스 유형을 이용하여 하나의 CloudFormation 템플릿에서 통합을 구현할 수 있습니다.
해결 방법
1. CloudFormation 템플릿의 리소스 섹션에서 example.com과 같은 프라이빗 서비스 검색 네임스페이스를 생성합니다. 기존 Amazon Virtual Private Cloud(Amazon VPC)에 네임스페이스를 생성합니다. 다음의 JSON 및 YAML 예제를 참조하세요.
JSON:
{ "PrivateNamespace": { "Type": "AWS::ServiceDiscovery::PrivateDnsNamespace", "Properties": { "Name": "example.com", "Vpc": "vpc-xxxxxxx" } } }
YAML:
PrivateNamespace: Type: AWS::ServiceDiscovery::PrivateDnsNamespace Properties: Name: example.com Vpc: vpc-xxxxxxx
참고: example.com을 네임스페이스의 이름으로 바꾸십시오. vpc-xxxxxxx를 계정의 VPC ID로 바꾸십시오.
2. 1단계에서 생성한 네임스페이스의 네임스페이스 ID를 사용하여 서비스 검색 서비스를 생성하십시오.
CloudFormation 템플릿의 Ref 내장 함수를 사용하여 네임스페이스 ID 값을 가져올 수 있습니다. 다음의 JSON 및 YAML 예제를 참조하세요.
JSON:
{ "DiscoveryService": { "Type": "AWS::ServiceDiscovery::Service", "Properties": { "Description": "Discovery Service for the Demo Application", "DnsConfig": { "RoutingPolicy": "MULTIVALUE", "DnsRecords": [ { "TTL": 60, "Type": "A" }, { "TTL": 60, "Type": "SRV" } ] }, "HealthCheckCustomConfig": { "FailureThreshold": 1 }, "Name": "example-service-name", "NamespaceId": { "Ref": "PrivateNamespace" } } } }
YAML:
DiscoveryService: Type: AWS::ServiceDiscovery::Service Properties: Description: Discovery Service for the Demo Application DnsConfig: RoutingPolicy: MULTIVALUE DnsRecords: - TTL: 60 Type: A - TTL: 60 Type: SRV HealthCheckCustomConfig: FailureThreshold: 1 Name: example-service-name NamespaceId: !Ref PrivateNamespace
참고:****example-service-name은 서비스의 이름으로 바꾸십시오.
DNSconfig 속성은 Amazon Route 53에서 자동으로 생성되는 DNS 레코드를 지정합니다. 이러한 DNS 레코드는 Amazon ECS 작업이 서비스 검색 서비스에 등록될 때 생성됩니다. A 및 SRV 유형의 DNS 레코드가 지원됩니다. 자세한 내용은 서비스 검색을 사용하도록 서비스를 구성을 참조하세요.
**팁:**HealthCheckCustomConfig 속성을 사용하여 Amazon ECS가 태스크 상태를 서비스 검색에 보고할 수 있도록 하는 것이 모범 사례입니다. Amazon ECS는 컨테이너 확인, 상태 확인 및 태스크 상태의 정보를 사용하여 AWS Cloud Map과 함께 서비스 검색 상태를 업데이트합니다.
3. 이전 단계에서 생성한 서비스 검색 네임스페이스 및 서비스와 통합되는 Amazon ECS 서비스를 생성합니다. AWS:ECS::서비스 리소스의 ServiceRegistries 속성을 사용하여 통합을 지정합니다. 다음의 JSON 및 YAML 예제를 참조하세요.
JSON:
{ "EcsService": { "Type": "AWS::ECS::Service", "Properties": { "Cluster": "awsExampleCluster", "DesiredCount": 4, "LaunchType": "FARGATE", "NetworkConfiguration": { "AwsvpcConfiguration": { "SecurityGroups": [ "sg-xxxxxxx" ], "Subnets": [ "subnet-xxxxxxx" ] } }, "ServiceName": "awsExampleService", "TaskDefinition": "awsExampleTaskDefinition", "ServiceRegistries": [ { "RegistryArn": { "Fn::GetAtt": [ "DiscoveryService", "Arn" ] }, "Port": 80 } ] } } }
YAML:
EcsService: Type: AWS::ECS::Service Properties: Cluster: awsExampleCluster DesiredCount: 4 LaunchType: FARGATE NetworkConfiguration: AwsvpcConfiguration: SecurityGroups: - sg-xxxxxxx Subnets: - subnet-xxxxxxx ServiceName: awsExampleService TaskDefinition: awsExampleTaskDefinition ServiceRegistries: - RegistryArn: !GetAtt DiscoveryService.Arn Port: 80
참고: AWSExampleCluster를 사용자의 클러스터로 바꿉니다. AWSExampleService를 사용자의 서비스로 바꿉니다. AWSExampletaskDefinition을 사용자 태스크 정의로 바꿉니다. sg-xxxxxxx를 사용자 보안 그룹 ID로 바꿉니다. subnet-xxxxxxx를 사용자 서브넷 ID로 바꿉니다.
RegistryArn의 경우, Amazon ECS 서비스와 통합하려는 서비스 검색 서비스의 Amazon 리소스 이름(ARN)을 사용합니다. 내장 함수 Fn::GetAtt를 사용하여 CloudFormation 템플릿에서 이 값을 가져오세요.
awsvpc 모드를 사용하는 경우, 그 값을 포트 또는 ContainerPort 및 ContainerName의 조합 중 하나로 설정하십시오(태스크 정의에 지정된 대로). 호스트 또는 브리지 모드를 사용하는 경우, 그 값을 ContainerPort 또는 ContainerName으로 설정하십시오(태스크 정의에 지정된 대로).
4. CloudFormation 콘솔을 연 다음, 스택 생성을 선택하여 업데이트된 템플릿을 기반으로 리소스를 배포하십시오.
5. VPC 내에서 태스크를 해결할 수 있는지 확인하려면 다음 명령을 실행하십시오.
$ dig awsExampleService.awsExampleNamespace. +short $ dig srv awsExampleService.awsExampleNamespace. +short $ curl awsExampleService.awsExampleNamespace. -I
참고: awsExampleService의 값은 AWS::ECS::Service 리소스의 이름입니다. awsExampleNamespace의 값은 AWS::ServiceDiscovery::PrivateDnsNamespace 리소스의 이름입니다.
이 명령은 다음과 비슷한 출력을 반환합니다.
$ dig awsExampleService.awsExampleNamespace. +short의 경우:
172.31.182.0 172.31.160.124 172.31.137.81 172.31.149.244
$ dig srv awsExampleService.awsExampleNamespace. +short의 경우:
1 1 80 ffe95d27ea8d4f7aba0dfed87297fc5a.awsExampleService.awsExampleNamespace. 1 1 80 44a17fa781974a93bb563bc1826a8697.awsExampleService.awsExampleNamespace. 1 1 80 d640ecb3d283421bb2d1318caf4b0d66.awsExampleService.awsExampleNamespace. 1 1 80 65aff6fff33144b2ad79d283ab52cfe9.awsExampleService.awsExampleNamespace.
$ curl awsExampleService.awsExampleNamespace. -I의 경우:
HTTP/1.1 200 OK Server: nginx/1.15.12 Date: Wed, 15 May 2019 02:25:19 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 16 Apr 2019 13:08:19 GMT Connection: keep-alive ETag: "5cb5d3c3-264" Accept-Ranges: bytes

관련 콘텐츠
- 질문됨 4달 전lg...
- 질문됨 4달 전lg...
- 질문됨 2달 전lg...
- 질문됨 한 달 전lg...
- AWS 공식업데이트됨 3년 전
- AWS 공식업데이트됨 3년 전
- AWS 공식업데이트됨 8달 전
- AWS 공식업데이트됨 일 년 전