Problem
EC2 앞에 CloudFront를 넣어서 인프라를 구성했습니다. CloudFront에 SSL 인증서를 설정하기가 EC2에 직접 설정하는 것보다 더 수월하다는 이유에서 넣었습니다. ALB를 넣을 수도 있었겠지만, 비용상 CloudFront를 설정했습니다.
시간이 지난 후, 영상 업로드 기능을 만들면서 CloudFront의 에러를 내보냈습니다.
CloudFront의 에러 응답
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ERROR: The request could not be satisfied</title>
</head>
<body>
<h1>504 ERROR</h1>
<h2>The request could not be satisfied.</h2>
<hr noshade size="1px" />
CloudFront attempted to establish a connection with the origin, but either
the attempt failed or the origin closed the connection. We can't connect to
the server for this app or website at this time. There might be too much
traffic or a configuration error. Try again later, or contact the app or
website owner.
<br clear="all" />
If you provide content to customers through CloudFront, you can find steps
to troubleshoot and help prevent this error by reviewing the CloudFront
documentation.
<br clear="all" />
<hr noshade size="1px" />
<pre>
Generated by cloudfront (CloudFront)
Request ID: oF2PZ6fPMq_UenKko6VCLwkRtohNLdIJtEW3p_c4sPeLvFhSdTVf3w==
</pre
>
<address></address>
</body>
</html>
HTML
복사
How to solve
처음엔 영상 업로드와 관련하여 S3도 역시 CloudFront를 사용하고 있었기 때문에 관련 에러라고 생각했습니다. 하지만 생각해보면 영상을 클라이언트로부터 받아 S3에 업로드하는 과정 중에서는 CloudFront를 사용하지 않았습니다.
관련 내용을 찾아보니 CloudFront에는 request timeout이 있었고, 이 timeout을 넘기면 CloudFront가 자동으로 에러로 응답했습니다. timeout의 기본값은 30초였습니다.
클라이언트에서 영상을 업로드 받은 후 파일을 압축하는 과정과 결과물을 S3로 업로드하는 과정에서 시간이 소요되므로 timeout이 걸리는 경우가 있었습니다.
일단은 CloudFront timeout 최대 설정을 보니 60초였고, 그렇게 설정했습니다. 이렇게 기본적으로 에러가 일어날 수 있는 범위는 줄였습니다만, 문제를 완전히 해결한 것은 아닙니다.
같은 Origin 에 있는 다른 API 들도 (원하지 않았지만) 모두 timeout이 60초로 늘어나게 되었고, 여전히 60초 이상 응답을 주지 않는 경우에 대해서는 에러가 발생합니다. 예전에는 30초 고정이었던 적도 있는 것 같습니다. 관련 내용을 더 찾아보니 이 timeout을 늘려서 써보려는 시도들이 있는 것 같습니다.
추가로 알게 된 점
- CloudFront에서 에러 응답을 줄 때 Custom error response를 줄 수 있다는 것을 알았습니다.
- AWS에 직접 service quota 요청을 보내서 늘리는 방법도 공식 문서에 안내되어 있었습니다. 하지만 이렇게 단순히 timeout을 늘리는 것이 좋은 것은 아니라고 생각했습니다. API를 분리하거나 다른 구조를 통해서 영상 압축에 걸리는 시간을 가져갈 수 있도록 해야할 것 같습니다.