S3에 저장된 이미지들을 글로벌 서비스하기 위한 CDN을 구성해보자
0. CloudFront 란?
- Amazon CloudFront는 .html, .css, .js 및 이미지 파일과 같은 정적 및 동적 웹 콘텐츠를 사용자에게 더 빨리 배포하도록 지원하는 웹 서비스
- CloudFront는 엣지 로케이션이라고 하는 데이터 센터의 전 세계 네트워크를 통해 콘텐츠를 제공
- 사용자가 콘텐츠를 요청하면 지연 시간이 가장 낮은 엣지 로케이션으로 요청이 라우팅되므로 가능한 최고의 성능으로 콘텐츠가 제공
CloudFront에 대한 더 많은 정보 : https://docs.aws.amazon.com/ko_kr/AmazonCloudFront/latest/DeveloperGuide/Introduction.html
https://galid1.tistory.com/355
1. S3 버킷 생성

test-cf-cdn 라는 버킷명으로 도쿄리전에 생성

생성한 버킷에 이미지를 하나 업로드 하였다.


default 설정으로 버킷의 모든 퍼블릭 엑세스가 차단되어있으므로 외부에서 이미지에 접근 할 수 없는 상태이다.
2. CloudFront Distribution 생성

AWS CloudFront 대시보드에서 Create Distribution 클릭

Origin Domain Name에 이전에 생성한 버킷이름을 찾아서 등록해준다.

실제 배포가 아닌 학습, 테스트용 이므로 세부 설정은 나중에 하기로 하고 일단, Create Distribution을 눌러 생성을 진행 해준다.

배포가 진행중이라고 표시되고 있다.
3. CloudFront Origins 설정

AWS CloudFront Distribution 대시보드 내 Origins and Origin Groups 탭에 들어가보면, 처음 Distribution 생성 시 타겟 S3버킷이 origin으로 설정되어있는 상태이다. 해당 origin을 체크 후 Edit을 눌러준다.

위와 같이 origin 설정을 추가 해준다.

그리고 S3 버킷에 들어가 버킷 정책을 확인해보면, 위와 같이 새로운 CloudFront 정책이 추가된 것을 확인 할 수 있다.
4. 결과
S3버킷은 퍼블릭 접근이 차단 되어있으므로, 외부에서 객체 URL로 버킷 및 객체에 접근(s3:GetObject) 불가하고,
외부에서 CloudFront를 통해서 이미지에 접근 할 수 있다.
