Pay-as-You-Go(무료 플랜 제외)에서 AWS CloudFront 생성

발행: (2026년 2월 22일 오전 09:21 GMT+9)
9 분 소요
원문: Dev.to

Source: Dev.to

Rost

AWS 무료 플랜이 나에게는 작동하지 않으며
AWS 콘솔에서 새 CloudFront 배포에 대해 Pay‑as‑you‑go 옵션이 숨겨져 있습니다.

AWS에서 Hugo 기반 사이트를 호스팅할 때는 일반적으로 버킷을 CloudFront 뒤에 두고 Lambda@Edge 함수를 연결합니다. 이렇게 하면 디렉터리 경로(예: /blog/)에 대한 요청이 S3 웹사이트‑스타일 오리진을 위해 /blog/index.html로 재작성됩니다. 그 후 hugo deploy 혹은 AWS CLI를 사용한 배포를 통해 빌드된 사이트를 동기화할 수 있습니다.

핵심: 해당 Lambda를 사용하는 CloudFront 배포가 필요하고, 정액제 플랜 약정을 피하려면 pay‑as‑you‑go 요금제를 선택해야 합니다. 콘솔에서는 이제 Free 또는 Pro 플랜만 선택할 수 없습니다.

이 글에서는 기존 배포의 구성을 재사용하고 AWS CLI와 이 글의 scripts 폴더에 있는 스크립트를 이용해 pay‑as‑you‑go 배포를 만드는 방법을 보여줍니다.

콘솔에서 Free 또는 Pro만 제공될 때

Amazon은 CDN을 WAF, DDoS 보호, Route 53 및 기타 서비스와 함께 고정 월 요금으로 제공하는 플랫‑레이트 요금제(Free, Pro, Business, Premium)를 도입했습니다. CloudFront 콘솔에서 새 배포를 만들면 이제 Free 또는 Pro(및 그 이상) 요금제 옵션만 표시됩니다. Pro 요금제는 $15 / 월부터 시작하며, 여기에는 눈에 보이는 “pay‑as‑you‑go” 옵션이 없습니다.

pay‑as‑you‑goCloudFront API 또는 AWS CLI(create-distribution)를 통해 배포를 생성할 때 여전히 기본값입니다. 따라서 이미 이전에(또는 CLI를 통해) 배포를 만든 상태이고, 같은 동작을 하는 다른 배포—예를 들어 S3 웹사이트 오리진에 index.html용 Lambda@Edge를 추가한 경우—를 만들고 싶다면 그 배포의 구성을 내보내고, 수정한 뒤 새 배포를 생성하면 됩니다. 새 배포는 나중에 플랫‑레이트 요금제에 연결하지 않는 한 pay‑as‑you‑go 방식으로 청구됩니다.

필요한 것

  • 기존 CloudFront 배포(예: 다른 Hugo 사이트에 사용 중이거나 콘솔 변경 전 생성된 배포)로, 구성 파일을 복사할 수 있는 배포.
  • AWS CLI가 설치되어 있고 cloudfront:GetDistributionConfigcloudfront:CreateDistribution을 실행할 수 있는 권한이 있는 자격 증명으로 구성됨.
  • jq(또는 유사 도구)로 JSON 구성을 편집할 수 있음.

아래에 사용된 예제 스크립트는 이 게시물의 scripts 폴더에 있습니다:

  • current-distribution-config.json
  • new-distribution-config.json
  • updated-distribution-config.json
  • final-distribution-config.json

1단계: 기존 배포 구성 가져오기

# Replace ABCDEFG with your existing distribution ID
aws cloudfront get-distribution-config --id ABCDEFG > current-distribution-config.json

get-distribution-configETagDistributionConfig를 포함하는 래퍼 객체를 반환합니다. 새 배포를 생성할 때는 내부의 DistributionConfig만 전달하면 되므로, 이를 추출합니다:

jq '.DistributionConfig' current-distribution-config.json > new-distribution-config.json

이 시점에서 new-distribution-config.json은 다음과 같은 (축약된) 형태를 가집니다. 여기에는 CallerReference, Aliases, Origins, DefaultRootObject, 그리고 Lambda@Edge 연관이 포함된 DefaultCacheBehavior가 들어 있습니다.

{
  "CallerReference": "8b2b19eb-6d41-4fc0-8d04-a1313e23e2d7",
  "Aliases": {
    "Quantity": 1,
    "Items": ["micro.com"]
  },
  "DefaultRootObject": "index.html",
  "Origins": {
    "Quantity": 1,
    "Items": [
      {
        "Id": "micro.com.s3.us-west-2.amazonaws.com",
        "DomainName": "micro.com.s3-website-us-west-2.amazonaws.com",
        "OriginPath": "",
        "CustomOriginConfig": {
          "HTTPPort": 80,
          "HTTPSPort": 443,
          "OriginProtocolPolicy": "http-only"
        }
      }
    ]
  },
  "DefaultCacheBehavior": {
    "TargetOriginId": "micro.com.s3.us-west-2.amazonaws.com",
    "ViewerProtocolPolicy": "redirect-to-https",
    "LambdaFunctionAssociations": {
      "Quantity": 1,
      "Items": [
        {
          "LambdaFunctionARN": "arn:aws:lambda:us-east-1:...your-lambda-arn",
          "EventType": "origin-request",
          "IncludeBody": false
        }
      ]
    }
  }
}

Step 2: 고유한 CallerReference 설정

모든 배포에는 고유한 CallerReference가 필요합니다. 다른 배포와 동일한 값을 재사용하면 API가 요청을 거부합니다. 새 문자열이나 타임스탬프를 사용하십시오:

NEW_CALLER_REF="new-distr-$(date +%s)"
jq --arg ref "$NEW_CALLER_REF" '.CallerReference = $ref' new-distribution-config.json > updated-distribution-config.json

Step 3: 별칭 및 오리진 조정 (선택 사항)

새 사이트가 다른 도메인 또는 S3 버킷을 사용하는 경우, updated-distribution-config.json 파일의 AliasesOrigins를 일치하도록 업데이트하십시오 (예: 새 버킷 웹사이트 엔드포인트 및 별칭 목록).

지금은 커스텀 도메인 없이 배포를 원한다면, 별칭을 비워두세요:

jq '.Aliases = {"Quantity": 0, "Items": []}' updated-distribution-config.json > final-distribution-config.json

(원문 기사에 설명된 대로 남은 단계—aws cloudfront create-distribution --distribution-config file://final-distribution-config.json 명령으로 배포를 생성—를 계속 진행하십시오.)

원본 업데이트 (필요한 경우)

배포를 다른 S3 웹사이트 엔드포인트로 지정해야 하는 경우, 동일한 파일의 Origins 섹션을 편집하십시오(예: IdDomainName을 새 버킷의 웹사이트 호스트 이름으로 변경하고, DefaultCacheBehavior.TargetOriginId를 동일한 Id로 설정).

Step 4: Create the New Distribution

aws cloudfront create-distribution --distribution-config file://final-distribution-config.json

The response includes the new distribution’s Id, ARN, DomainName, and Status.
The new distribution uses pay‑as‑you‑go pricing by default. You can then point your DNS (or Route 53) to the new CloudFront domain and, if you use it for Hugo, deploy with Hugo deploy or the AWS CLI as usual (see the Hugo deployment guide linked below).

빠른 참고: 전체 스크립트

# 1) Export and extract DistributionConfig
aws cloudfront get-distribution-config --id EABCDEFGZ > current-distribution-config.json
jq '.DistributionConfig' current-distribution-config.json > new-distribution-config.json

# 2) Unique CallerReference
NEW_CALLER_REF="new-distr-$(date +%s)"
jq --arg ref "$NEW_CALLER_REF" '.CallerReference = $ref' new-distribution-config.json > updated-distribution-config.json

# 3) Optional: no custom domain
jq '.Aliases = {"Quantity": 0, "Items": []}' updated-distribution-config.json > final-distribution-config.json

# 4) Create (pay‑as‑you‑go) distribution
aws cloudfront create-distribution --distribution-config file://final-distribution-config.json

사용량 기반 요금제 vs. 정액제 (요약)

플랜가격 모델핵심 포인트
사용량 기반 요금제데이터 전송 및 요청에 대해 비용을 지불• CloudFront의 영구 무료 티어에는 매월 1 TB 데이터 전송10 M HTTP/HTTPS 요청이 포함됩니다.
• 월별 플랜 요금이 없습니다.
정액제 플랜고정 월 요금 (Free, Pro 등)• 문서는 여기.
• 무료 티어는 더 낮은 할당량을 가집니다 (예: 1 M 요청, 100 GB).
• Pro는 월 $15부터 시작하며 더 높은 용량과 번들 서비스 (WAF, Route 53 등)를 제공합니다.
• 초과 사용 요금이 없습니다.

트래픽이 사용량 기반 무료 티어 내에 들어가고 번들 정액제 기능이 필요하지 않다면, 위에서 보여준 것처럼 CLI를 통해 배포를 생성하면 사용량 기반 요금제를 유지할 수 있습니다. 반면 콘솔 UI에서는 Free 또는 Pro 플랜만 표시됩니다.

유용한 링크

0 조회
Back to Blog

관련 글

더 보기 »