DEV Community

Yasuhiro Matsuda for AWS Community Builders

Posted on

CloudFront経由のアクセスでプロトコルを識別する

主にWordpress向けのネタになると思うが、ALB経由でのアクセスでプロトコルを識別する場合には、ターゲットに対してX-Forwarded-Proto リクエストヘッダーを使用してアクセスされるため、HTTP_X_FORWARDED_PROTOの環境変数で識別できる一方、CloudFront経由のアクセスでプロトコルを識別するする場合には、CloudFront-Forwarded-Protoヘッダをオリジンアクセス時に付加することで、HTTP_CLOUDFRONT_FORWARDED_PROTOの環境変数で識別できる。

しかしながら、CloudFrontのオリジンリクエストポリシー名がマネージドポリシーを使っている場合、AllViewerではCloudFront-Forwarded-Protoヘッダがオリジンに送られることはなく、HTTP_CLOUDFRONT_FORWARDED_PROTOの環境変数で識別することができない。

Managed-AllViewerAndCloudFrontHeaders-2022-06というマネージドポリシーが用意されているので、これを設定することで要件を満たすようになる。

CloudFront のリクエストヘッダーの追加には以下の記述が冒頭あるが、どのように設定できるのかが同一ページに記載されていないので、紹介してみた。

CloudFront がビューワーから受け取り、オリジンまたはエッジ関数に転送するリクエストに特定の HTTP ヘッダーを追加するように CloudFront を設定できます。

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post