

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 [AWS](https://github.com/awsdocs/aws-doc-sdk-examples)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# CloudFront Functions ビューワーリクエストイベントにオリジンヘッダーを追加する
<a name="cloudfront_example_cloudfront_functions_add_origin_header_section"></a>

次のコード例は、CloudFront Functions ビューワーリクエストイベントにオリジンヘッダーを追加する方法を示しています。

------
#### [ JavaScript ]

**CloudFront Functions の JavaScript ランタイム 2.0**  
 GitHub には、その他のリソースもあります。用例一覧と設定および実行方法については、[CloudFront Functions の例](https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/add-origin-header)リポジトリをご覧ください。

```
async function handler(event) {
    var request = event.request;
    var headers = request.headers;
    var host = request.headers.host.value;
   
   // If origin header is missing, set it equal to the host header.
   if (!headers.origin)
       headers.origin = {value:`https://${host}`};
       
   return request;
}
```

------