AWS - serverless-image-handler

Kevin Park
5 min readJan 16, 2020

--

이미지 리사이징 라이브러리가 많은 성능 개선이 되면서 원본 이미지를 미리 리사이징해두지 않고 요청 시 리사이징해서 처리하는 방식이 비용적인 부분이나 리소스 사용 부분에서 좀 더 나은 방식으로 볼 수 있습니다.

AWS에서는 Serverless Image Handler를 Solution 형태로 제공하고 있습니다. 이미지 리사이징 라이브러리는 Sharp(https://sharp.pixelplumbing.com/en/stable/)를 사용하고 있습니다.

1. Architecture Overview

출처 : https://docs.aws.amazon.com/solutions/latest/serverless-image-handler/images/overview_sih-architecture.png

클라이언트가 특정 사이즈의 이미지를 요청할 때 CloudFront를 통해 CDN 서버에 Cache 되어 있지 않은 이미지의 경우 API Gateway를 통해 Lambda를 호출하여 원본 이미지를 리사이징하여 전달하도록 구성되어 있습니다.

2. CloudFomation template를 통한 Deployment

제공되는 template를 통해 손쉬운 배포가 가능합니다.

https://s3.amazonaws.com/solutions-reference/serverless-image-handler/latest/serverless-image-handler.template

스택 세부 정보 지정

Image Sources Bucket이 여러 개인 경우 “ , ” 로 구분하여 지정할 수 있으며 Demo UI를 yes로 지정할 경우 Demo website가 S3 정적 웹 사이트 호스팅을 통해 생성됩니다. 다음 스택 옵션 구성은 변경 없이 진행합니다.

3. Deployment 완료

Deployment가 완료되면 output과 각 리소스를 확인 할 수 있습니다.

CloudFormation Output을 확인 합니다.
Demo UI 버킷과 logs 버킷 생성 됩니다.
API Gateway에 ServerlessImageHandler가 생성 됩니다.
Lambda 애플리케이션이 생성 됩니다.
CloudFront에 Demo Website와 image handler가 Distribution 됩니다.

4. Demo Website Test

CloudFormation output에서 확인한 DemoUrl로 접속하여 Demo를 진행 할 수 있습니다. 10Mb가 넘는 파일은 Original Image에서 확인할 수 없으며 리사이징 결과가 10Mb가 넘는 파일도 확인 할 수 없습니다. 원본이 10Mb가 넘지만 리사이징 결과가 10Mb가 안 된다면 정상적으로 확인이 됩니다.

Request Body를 Base64 인코딩하여 ApiEndpoint(CloudFormation output의 ApiEndpoint)로 요청하면 리사이징 된 이미지를 확인할 수 있습니다.

5. CloudFront Domain 연결

ApiEndpoint가 CloudFront의 Domain name을 사용하고 있어서 변경 처리를 합니다. Alternate Domain Names에 사용할 domain name을 입력하고 SSL 인증서도 해당 도메인의 인증서로 교체합니다. 이후 Route53에 해당 레코드를 생성하고 연결해 줍니다.

감사합니다.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kevin Park
Kevin Park

No responses yet

Write a response