3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CloudFormationでCloudFront Functionsデプロイ時にInternalFailureが発生する

Posted at

発生事象

CloudFormation で CloudFront Functions をデプロイする際に InternalFailure が発生してしまう。

Resource handler returned message: "null" (RequestToken: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, HandlerErrorCode: InternalFailure)

image.png

使用したテンプレート

上記を参考にこんな感じのテンプレートを使いました。

template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: add-security-headers-cloudfront-function

Resources:
  AddSecurityHeaderFunction:
    Type: AWS::CloudFront::Function
    Properties: 
      AutoPublish: false 
      FunctionCode: |
        function handler(event) {
            var response = event.response;
            var headers = response.headers;
            headers['strict-transport-security'] = { value: 'max-age=63072000; includeSubdomains; preload'}; 
            headers['content-security-policy'] = { value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}; 
            headers['x-content-type-options'] = { value: 'nosniff'}; 
            headers['x-frame-options'] = {value: 'DENY'}; 
            headers['x-xss-protection'] = {value: '1; mode=block'}; 
            
            return response;
        }
      Name: add-security-headers-cff

回避策

FunctionConfig プロパティを追加すると回避できます。

      FunctionConfig:
        Comment: add-security-headers-cff
        Runtime: cloudfront-js-1.0

Comment は任意のコメントを記載。Runtime は CloudFront Functions のランタイム環境を指定するが、今のところ cloudfront-js-1.0 のみ有効。

原因

2021/6/4 現在で CloudFormation のユーザーガイドには FunctionConfig プロパティは Required: No と記載されていますが、プロパティを省略すると InternalFailure でデプロイが失敗してしまいます。

CloudFormation の不具合なのかドキュメントの記載ミスなのかは判断できませんので、事象が解消されたことを確認したら追記したいと思います。

対応後

デプロイ成功!!

template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: add-security-headers-cloudfront-function

Resources:
  AddSecurityHeaderFunction:
    Type: AWS::CloudFront::Function
    Properties: 
      AutoPublish: false 
      FunctionConfig:
        Comment: add-security-headers-cff
        Runtime: cloudfront-js-1.0
      FunctionCode: |
        function handler(event) {
            var response = event.response;
            var headers = response.headers;
            headers['strict-transport-security'] = { value: 'max-age=63072000; includeSubdomains; preload'}; 
            headers['content-security-policy'] = { value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}; 
            headers['x-content-type-options'] = { value: 'nosniff'}; 
            headers['x-frame-options'] = {value: 'DENY'}; 
            headers['x-xss-protection'] = {value: '1; mode=block'}; 

            return response;
        }
      Name: add-security-headers-cff

image.png

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?