

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS 계정 및 간에 Amazon ECR 컨테이너 이미지 복사 AWS 리전
<a name="copy-ecr-container-images-across-accounts-regions"></a>

*Faisal Shahdad, Amazon Web Services*

## 요약
<a name="copy-ecr-container-images-across-accounts-regions-summary"></a>

이 패턴은 서버리스 접근 방식을 사용하여 기존 Amazon Elastic Container Registry(Amazon ECR) 리포지토리에서 태그가 지정된 이미지를 다른 AWS 계정 및 로 복제하는 방법을 보여줍니다 AWS 리전. 이 솔루션은 AWS Step Functions 를 사용하여 복제 워크플로와 AWS Lambda 함수를 관리하여 대용량 컨테이너 이미지를 복사합니다.

Amazon ECR은 [리전](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry-settings-examples.html#registry-settings-examples-crr-single) 및 [계정 간에 컨테이너 이미지를 복제하는 네이티브 리전 간 및 계정 간](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry-settings-examples.html#registry-settings-examples-crossaccount) 복제 기능을 사용합니다. 그러나 이러한 기능은 복제가 켜져 있는 순간에만 이미지를 복제합니다. 다른 리전 및 계정의 기존 이미지를 복제하는 메커니즘은 없습니다.

이 패턴은 인공 지능(AI) 팀이 컨테이너화된 기계 학습(ML) 모델, 프레임워크(예: PyTorch, TensorFlow 및 Hugging Face) 및 종속성을 다른 계정 및 리전에 배포하는 데 도움이 됩니다. 이를 통해 서비스 제한을 극복하고 GPU 컴퓨팅 리소스를 최적화할 수 있습니다. 특정 소스 계정 및 리전에서 Amazon ECR 리포지토리를 선택적으로 복제할 수도 있습니다. (자세한 내용은 [Amazon ECR의 교차 리전 복제가 도입된](https://aws.amazon.com/blogs/containers/cross-region-replication-in-amazon-ecr-has-landed/) AWS Blog 게시물을 참조하십시오.)

## 사전 조건 및 제한 사항
<a name="copy-ecr-container-images-across-accounts-regions-prereqs"></a>

**사전 조건 **
+ 둘 이상의 활성 AWS 계정 (소스 계정 하나와 대상 계정 하나, 최소)
+ 모든 계정의 적절한 AWS Identity and Access Management (IAM) 권한
+ Lambda 컨테이너 이미지를 빌드하기 위한 Docker
+ AWS Command Line Interface 모든 계정에 대해 구성된 (AWS CLI)

**제한 사항 **
+ **태그가 지정되지 않은 이미지 제외 -** 솔루션은 명시적 태그가 있는 컨테이너 이미지만 복사합니다. 다이`SHA256`제스트와 함께 존재하는 태그가 지정되지 않은 이미지는 건너뜁니다.
+ **Lambda 실행 제한 시간 –** AWS Lambda 최대 15분의 실행 제한 시간으로 제한되며, 이는 대용량 컨테이너 이미지 또는 리포지토리를 복사하는 데 충분하지 않을 수 있습니다.
+ **수동 컨테이너 이미지 관리 -** `crane-app.py` Python 코드를 사용하려면 Lambda 컨테이너 이미지를 다시 빌드하고 재배포해야 합니다.
+ **제한된 병렬 처리 용량 -** `MaxConcurrency` 상태 설정은 동시에 복사할 수 있는 리포지토리 수를 제한합니다. 그러나 소스 계정의 AWS CloudFormation 템플릿에서이 설정을 수정할 수 있습니다. 동시성 값이 높을수록 서비스 속도 제한 및 계정 수준 Lambda 실행 할당량을 초과할 수 있습니다.

## 아키텍처
<a name="copy-ecr-container-images-across-accounts-regions-architecture"></a>

**대상 스택**

패턴에는 네 가지 주요 구성 요소가 있습니다.
+ **소스 계정 인프라 -** 오케스트레이션 구성 요소를 생성하는 CloudFormation 템플릿
+ **대상 계정 인프라 **- 교차 계정 액세스 역할을 생성하는 CloudFormation 템플릿
+ **Lambda 함수 **- 효율적인 이미지 복사를 위해 Crane을 사용하는 Python 기반 함수
+ **컨테이너 이미지 -** 필요한 도구로 Lambda 함수를 패키징하는 Docker 컨테이너

**대상 아키텍처 **

![\[alt text not found\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/images/pattern-img/787185e7-664b-4ed8-b30f-1d9507f13377/images/cc7d9823-3dc8-4090-a203-910b1ac4447c.png)


**Step Functions 워크플로우**

Step Functions 상태 시스템은 다음 다이어그램과 같이 다음을 오케스트레이션합니다.
+ `PopulateRepositoryList`** -** Amazon ECR 리포지토리를 스캔하고 Amazon DynamoDB를 채웁니다.
+ `GetRepositoryList`** -** DynamoDB에서 고유한 리포지토리 목록을 검색합니다.
+ `DeduplicateRepositories`** -** 중복 처리가 없는지 확인합니다.
+ `CopyRepositories`** -** 리포지토리의 병렬 복사를 처리합니다.
+ `NotifySuccess`/`NotifyFailure`** -** 실행 결과를 기반으로 하는 Amazon Simple Notification Service(Amazon SNS) 알림

![\[alt text not found\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/images/pattern-img/787185e7-664b-4ed8-b30f-1d9507f13377/images/1b740084-ba2b-4956-aa12-ebbf52be5e7d.png)


## 도구
<a name="copy-ecr-container-images-across-accounts-regions-tools"></a>

**Amazon 도구**
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)를 사용하면 AWS 리소스 및에서 실행되는 애플리케이션의 지표를 실시간으로 모니터링할 AWS 수 있습니다.
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)는 빠르고 예측 가능하고 확장 가능한 성능을 제공하는 완전 관리형 NoSQL 데이터베이스 서비스입니다.
+ [Amazon Simple Notification Service(Amazon SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)를 사용하면 웹 서버 및 이메일 주소를 포함하여 게시자와 클라이언트 간의 메시지 교환을 조정하고 관리할 수 있습니다.
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)는 AWS 리소스에 대한 액세스를 인증하고 사용할 수 있는 권한을 부여받은 사용자를 제어하여 리소스에 대한 액세스를 안전하게 관리하는 데 도움이 됩니다.
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)는 서버를 프로비저닝하거나 관리할 필요 없이 코드를 실행하는 데 도움이 되는 컴퓨팅 서비스입니다. 필요할 때만 코드를 실행하며 자동으로 확장이 가능하므로 사용한 컴퓨팅 시간만큼만 비용을 지불합니다.
+ [AWS Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)는 Lambda 함수 및 기타를 결합하여 비즈니스 크리티컬 애플리케이션을 구축하는 AWS 서비스 데 도움이 되는 서버리스 오케스트레이션 서비스입니다.

**기타 도구**
+ [Crane](https://michaelsauter.github.io/crane/index.html)은 Docker 오케스트레이션 도구입니다. Docker Compose와 비슷하지만 추가 기능이 있습니다.
+ [Docker](https://www.docker.com/)는 운영 체제 수준의 가상화를 사용하여 컨테이너에 소프트웨어를 제공하는 서비스형 플랫폼(PaaS) 제품 세트입니다.

**코드 리포지토리**
+ 이 패턴의 코드는 GitHub [aws-config-rules](https://github.com/aws-samples/sample-ecr-copy) 리포지토리에서 사용할 수 있습니다. 리포지토리의 CloudFormation 템플릿을 사용하여 기본 리소스를 생성할 수 있습니다.

## 모범 사례
<a name="copy-ecr-container-images-across-accounts-regions-best-practices"></a>

최소 권한 원칙을 따르고 작업을 수행하는 데 필요한 최소 권한을 부여하세요. 자세한 내용은 IAM 설명서의 [최소 권한 부여](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#grant-least-priv) 및 [보안 모범 사례](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)를 참조하세요.

## 에픽
<a name="copy-ecr-container-images-across-accounts-regions-epics"></a>

### 환경 준비
<a name="prepare-your-environment"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
|  AWS CLI 프로필을 구성합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, 데이터 엔지니어, ML 엔지니어 | 
| 필수 정보 수집 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, 데이터 엔지니어, ML 엔지니어 | 
| 리포지토리를 복제합니다. | 프로젝트의 리포지토리를 로컬 워크스테이션에 복제합니다.<pre>git clone https://github.com/aws-samples/sample-ecr-copy</pre> | DevOps 엔지니어, 데이터 엔지니어, ML 엔지니어 | 

### 대상 계정에 대한 인프라 배포
<a name="deploy-infrastructure-for-the-destination-account"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 템플릿 확인 | CloudFormation 템플릿 생성<pre>aws cloudformation validate-template \<br />  --template-body file://"Destination Account cf_template.yml" \<br />  --profile destination-account</pre> | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 
| 대상 인프라를 배포합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 
| 배포를 확인합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 

### 컨테이너 이미지 빌드 및 배포
<a name="build-and-deploy-the-lam-container-image"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 컨테이너 빌드를 준비합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 
| 를 사용하여 컨테이너 이미지를 빌드합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 
| 리포지토리 생성 및 이미지 업로드 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 
| 이미지를 확인하세요. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 

### 소스 계정 인프라 배포
<a name="deploy-the-source-account-infrastructure"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 배포 파라미터 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 
| 소스 템플릿을 검증합니다. | 소스 CloudFormation 템플릿을 검증합니다.<pre>aws cloudformation validate-template \<br />  --template-body file://"Source Account Cf template.yml" \<br />  --profile source-account</pre> | 데이터 엔지니어, DevOps 엔지니어 | 
| 인프라를 배포합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 
| 배포를 확인하고 출력을 수집합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 
| 이메일 구독을 확인합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 데이터 엔지니어, DevOps 엔지니어 | 

### 복사 프로세스 실행 및 모니터링
<a name="run-and-monitor-the-copy-process"></a>


| 작업 | 설명 | 필요한 기술 | 
| --- | --- | --- | 
| 복사 프로세스를 실행하고 모니터링합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 
| 단계 함수를 실행합니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 
| 진행률 모니터링 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 
| 결과를 확인합니다. | 프로세스가 완료될 때까지 기다립니다(30초마다 업데이트됨).<pre>while true; do<br />  STATUS=$(aws stepfunctions describe-execution \<br />    --execution-arn $EXECUTION_ARN \<br />    --profile source-account \<br />    --region $SOURCE_REGION \<br />    --query 'status' \<br />    --output text)<br />  <br />  echo "Current status: $STATUS"<br />  <br />  if [[ "$STATUS" == "SUCCEEDED" || "$STATUS" == "FAILED" || "$STATUS" == "TIMED_OUT" || "$STATUS" == "ABORTED" ]]; then<br />    break<br />  fi<br />  <br />  sleep 30<br />done<br /><br />echo "Final execution status: $STATUS"</pre> | DevOps 엔지니어, ML 엔지니어, 데이터 엔지니어 | 
| 이미지를 확인하세요. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | DevOps 엔지니어, 데이터 엔지니어, ML 엔지니어 | 

## 문제 해결
<a name="copy-ecr-container-images-across-accounts-regions-troubleshooting"></a>


| 문제 | Solution | 
| --- | --- | 
| 단계 함수가 실행되지 않습니다. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/prescriptive-guidance/latest/patterns/copy-ecr-container-images-across-accounts-regions.html) | 

## 관련 리소스
<a name="copy-ecr-container-images-across-accounts-regions-resources"></a>
+ [크레인 설명서](https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md)
+ [Amazon Elastic Container Registry란 무엇입니까?](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html)
+ [란 무엇입니까 AWS Lambda?](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
+ [Step Functions란 무엇입니까?](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)

## 추가 정보
<a name="copy-ecr-container-images-across-accounts-regions-additional"></a>

**구성 파라미터**


| 
| 
| 파라미터 | 설명 | 예제 | 
| --- |--- |--- |
| `SourceAccountId` | 소스 AWS 계정 ID | `11111111111` | 
| `DestinationAccountId` | 대상 AWS 계정 ID | `22222222222` | 
| `DestinationRegion` | 대상 AWS 리전 | `us-east-2` | 
| `SourceRegion` | 소스 AWS 리전 | `us-east-1` | 
| `NotificationEmail` | 이메일 알림 | `abc@xyz.com` | 
| `RepositoryList` | 복사할 리포지토리 | `repo1,repo2,repo3` | 
| `LambdaImageUri` | Lambda 컨테이너 이미지 | `${ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com/ecr-copy-lambda:latest` | 