S3 image bandwidth costs are getting annoying

I have noticed our site’s S3 image service bandwidth (transfer) costs keep going up and up. The pricing is $.09/GB and that can add up pretty fast.. I assume I am not the only site with this issue? I am paying Amazon $70/month for transfer alone now, that’s more than my VM costs. The S3 storage cost is only $5/month, the whole problem is transfer charges.

I don’t have any CDN or caching set up, just a totally generic Discourse running on a Linode VM using the S3 image buckets. What are bigger sites with lots of images doing? CDN (I assume that will cut costs)? Using Digital Ocean Spaces or Minio? Something else I am missing??

Using a CDN for S3 is the right approach. That will drive the transfer costs way down.

If you are in a tight budget, you may be able to use a cloudflare subdomain for that.

Hmm.. looking at the bandwidth costs on Fastly and the Amazon CloudFront (and others) they are pretty much the same as the .09/GB I am paying now :frowning:

Cloudflare seems to not charge for bandwidth?? Maybe that is the thing to try then. Is there a post on how to hook up Cloudflare for S3 images CDN on Discourse? I see the s3_cdn_url but can’t find instructions on how to use it (other than I need to rebake once I set it up). Looking at Cloudflare it seems like you need to have your own domain since the DNS needs to be changed.. so I would have to make a CNAME something like s3-cloudflare.mydomain.com which would point to my S3 bucket IP, and tell Cloudflare to do it’s thing on that URL, and also set s3_cdn_url to that, and then rebake?

Here is a support page I found at Cloudflare which seems to indicate this might work:

https://support.cloudflare.com/hc/en-us/articles/360013791312-Fetching-object-storage-assets-through-the-Cloudflare-CDN-using-a-Cloudflare-Worker

Anybody doing this?? I am a bit surprised there are not many sites with this issue as it is more than doubling the monthly cost for me at least.

I’m using Cloudflare on my Discourse site and it works fine. You basically route all your traffic through Cloudflare and tell it what to process or cache and that’s it. There are a few things to keep in mind though:

  1. Configure Cloudflare to NOT cache anything (set up exceptions using page rules, see below).
  2. Don’t let Cloudflare touch your Javascript - specifically, turn off Rocket Loader.
  3. I’m not sure about Brotli compression yet, I disabled it.
  4. Set up page rules to cache the avatar and upload directories as below (ignore rule #1, it’s site specific).

Cloudflare is currently caching a little over 3TB of data per month for me and it’s serving large graphics pretty fast.

If you’re more interested in a CDN I can also recommend https://www.belugacdn.com/ (I’m not affiliated with them). I use them on a large WordPress platform and performance is good, at a fraction of the cost of some other CDN platforms I looked at (those might be even more performant, but Beluga meets my needs).

결국 @scottfsmith 님은 Amazon CloudFront에서 다른 서비스로 전환하셨나요?

저도 비슷한 상황에 놓여 있습니다. 지출이 계속 늘고 있거든요.

CloudFront는 저에게 아직 낯선 서비스입니다. 지난 몇 년간 S3 버킷만 사용해 왔지만, 이곳의 추천을 바탕으로 지난달에 CloudFront를 설정했습니다.

하지만 그 결과 S3 데이터 전송 비용이 CloudFront 데이터 전송 비용으로 이동했을 뿐, 월 총 청구 금액은 그대로입니다.

데이터 전송 비용으로 인해 월 청구서가 지속 불가능한 수준에 도달하고 있는 것을 느끼고 있습니다.

저도 같은 상황입니다. 얼마 전 CloudFront으로 전환했는데, 비용도 비슷하게 나오고 있습니다. 로컬 캐싱 덕분에 비용 절감이 있을 줄 알았거든요. 즉, 같은 지역에서 동일한 이미지가 반복적으로 로드되면 대역폭 사용량이 줄어들 것이라고 생각했지만, 지금까지는 그런 것 같지 않습니다.

CloudFront 대신 사용할 수 있는 다른 CDN이 있을 것 같은데, Discourse는 이미지 URL을 다시 작성하는 것 외에는 거의 범용적인 방식으로 동작하는 것 같습니다(그렇게 보이지만요). 아마 이미지 전용으로 Cloudflare을 사용할 수 있을지도 모릅니다.

저도 정확히 그렇게 이해하고 있었습니다.

우리 트래픽의 98%가 영국 기반이고, 당연히 CloudFront를 통한 S3 출력이기도 98%가 영국으로 향합니다.

현재까지 CDN을 사용함으로써 얻는 이점은 전혀 느끼지 못하고 있습니다. 만약 트래픽이 전 세계에 걸쳐 있었다면, 아마 다른 결과를 볼 수 있었을지도 모릅니다.

앞으로 며칠 동안 Cloudflare에 대해 알아볼 생각입니다(이 두 회사가 왜 이렇게 비슷한 이름을 사용했을까요!). 혹시 이점이 있는지 찾아보겠습니다.

감사합니다 :+1:t2:

무엇을 발견하시면 여기에 후속 조치를 남겨 주세요. 저도 직접 조사해 보려 하고 있었습니다.

@Richie, @scottfsmith 님,

Using Object Storage for Uploads (S3 & Clones)에서 모든 테스트를 수행할 때 사용했던 월 10달러의 고정 비용 CDN인 https://www.stackpath.com/ 등이 있습니다. 이 서비스들이 여러분의 커뮤니티에 더 적합할 수 있습니다.

Stackpath CDN은 월 20달러이며 1TB까지 제한되어 있습니다. 하지만 많은 달에 이 한도를 초과하게 됩니다. 그러면 20TB 한도로 월 200달러로 가격이 인상되는데, 이는 아마존이 청구하는 월 100달러 정도보다 비쌉니다.

다만, 그 목록 중에 더 나은 옵션이 있을 수도 있으니 목록에 대해 상기시켜 주셔서 감사합니다.

imgur은 모두에게 무료이지만, 이걸 위한 플러그인은 없습니다

Tobey Maguire Reaction GIF

그런 플러그인은 어떤 역할을 하게 될까요? 단순히 IMGUR 플러그인을 다운로드하지 않는 것만인가요, 아니면 현재 시스템처럼 모든 이미지를 존재할 것으로 추정되는 어떤 API 인터페이스를 통해 IMGUR에 업로드하는 방식으로 작동할까요?

그게 당신에게 얼마나 가치가 있을까요? CDCK의 비즈니스 모델에는 의미가 없을 것 같다고 생각합니다. 유료 호스팅이 바로 우리 모두에게 Discourse를 가능하게 해주는 요소이기 때문이죠. 그리고 그들의 호스팅은 IMGUR 플러그인 없이도 잘 작동합니다.

혹시 이 설정이 2022년에 잘 동작하는지 확인해 주실 수 있나요? :slight_smile:

네, 아직 Cloudflare 설정을 사용하고 있습니다.

확인해 주셔서 감사합니다.

사용 중인 설정은 전체 페이지 캐싱(Full-page caching)이 아닌 것이 맞나요?

아니면 Cloudflare CDN을 다른 서비스보다 사용하는 데 특별한 이점이 있나요?

아니요, 우리는 업로드와 아바타 디렉터리만 캐싱합니다. 위의 규칙을 참고하세요. 다른 것을 시도하면 Discourse가 깨질 가능성이 높습니다.

무료이기 때문이죠 :slight_smile:

JS와 CSS와 같은 정적 자산은 어떻게 되나요?

이 가이드를 사용하여 CDN을 설정하면 업로드된 파일과 아바타(제가 아는 바로는)와 함께 정적 자산도 전달됩니다.

그렇다면 모든 정적 자산을 Cloudflare를 통해 전달할 경우 Discourse가 왜 깨지나요?

정확히 기억나지 않아요. 몇 년이 지났거든요. 직접 시도해보고 결과를 알려주실래요?

이 스레드가 다시 활성화되었으니 후속 내용을 덧붙여야 할 것 같습니다. Amazon CloudFront의 가격이 상당히 인하된 것 같습니다. 어떤 조치를 취했는지는 모르겠지만, 월 평균 AWS 비용이 약 80달러에서 15달러로 줄었습니다. 이는 이미지 전용으로 S3와 CloudFront를 사용하는, 이미지가 매우 많은 사이트의 경우입니다.

Cloudflare는 문제없습니다. 다만 Rocket Loader 기능을 비활성화하세요.

설정 노력을 들이지 않아도 서버로 돌아가는 대역폭의 절반을 절약할 수 있습니다.

몇 년 전에는 Cloudflare가 Discourse와 잘 작동하지 않았을 수 있지만, 지금은 그렇지 않습니다. 이 부분에 대한 의심이 계속 반복되지 않는 것이 좋겠습니다. 구체적인 문제가 있는 경우, 여기에서 지원 스레드를 시작하여 작동하지 않는 부분을 설명해 주시기 바랍니다.