설명
CloudFront를 통해 제공할 서비스는 default_cache_behavior.target_origin_id를 origins에 정의한 원본 ID와 맞추고 enabled: true로 설정하세요.
잠재적 영향
배포가 꺼져 있으면 CloudFront가 콘텐츠를 제공할 수 없습니다. 원본에 직접 접근할 수 있으면 CloudFront에서 적용한 인증이나 필터를 거치지 않을 수 있습니다.
해결 방법
서비스 도메인의 DNS와 실제 콘텐츠 요청이 배포를 거치는지 확인하고 로그가 도착하는지 시험하세요. 필요한 원본 접근 제한과 인증을 적용하고 사용자별 비공개 응답이 공유되지 않도록 캐시를 구성하세요.
예시
HTTPS를 지원하는 원본과 CloudFront가 로그를 쓸 수 있는 버킷이 필요합니다.
변경 전
yaml
- name: CloudFront 배포 생성
community.aws.cloudfront_distribution:
state: present
caller_reference: unique test distribution ID
default_cache_behavior:
target_origin_id: "my test origin-000111"
forwarded_values:
query_string: true
cookies:
forward: all
headers:
- "*"
viewer_protocol_policy: allow-all
smooth_streaming: true
compress: true
allowed_methods:
items:
- GET
- HEAD
cached_methods:
- GET
- HEAD
enabled: false
logging:
enabled: true
include_cookies: false
bucket: mylogbucket.s3.amazonaws.com
prefix: myprefix/
첫 태스크는 배포를 끄고 캐시 동작이 참조하는 원본을 정의하지 않아 새 배포를 만들 수 없습니다.
변경 후
yaml
- name: CloudFront 배포 생성
community.aws.cloudfront_distribution:
state: present
caller_reference: unique test distribution ID
origins:
- id: "my test origin-000111"
domain_name: www.example.com
origin_path: /production
custom_origin_config:
http_port: 80
https_port: 443
origin_protocol_policy: https-only
origin_ssl_protocols:
- TLSv1.2
default_cache_behavior:
target_origin_id: "my test origin-000111"
forwarded_values:
query_string: true
cookies:
forward: all
headers:
- "*"
viewer_protocol_policy: allow-all
compress: true
allowed_methods:
items:
- GET
- HEAD
cached_methods:
- GET
- HEAD
logging:
enabled: true
include_cookies: false
bucket: mylogbucket.s3.amazonaws.com
prefix: myprefix/
enabled: true
두 번째 태스크는 원본에 HTTPS를 쓰지만 viewer_protocol_policy: allow-all은 클라이언트의 HTTP도 허용합니다. 이 예시의 기존 캐시 설정은 모든 요청 헤더를 전달하므로 객체를 캐시하지 않습니다.