如何在模板文件中为 CloudFront 函数设置 FunctionCode 属性?

How to set FunctionCode property for a CloudFront Function in a template file?

我正在尝试使用云形成(YAML 模板文件)在我的堆栈中部署 CloudFront 函数。如何为我的 CloudFront 函数指定 FunctionCode (AWS docs) 属性?

AddHTMLPostfixFunction:
    Type: AWS::CloudFront::Function
    Properties:
      Name: !Sub "${ApplicationName}-add-html-postfix"
      AutoPublish: true
      FunctionCode: "---> Path to my .js-file? <---"
      FunctionConfig:
        Comment: "Adds .html postfix to viewer requests"
        Runtime: cloudfront-js-1.0

除了 CLI commands that has been documented from AWS.

,我找不到这方面的任何示例

可以使用内联代码!

AddHTMLPostfixFunction:
    Type: AWS::CloudFront::Function
    Properties:
      Name: !Sub "${ApplicationName}-add-html-postfix"
      AutoPublish: true
      FunctionCode: |
        function handler(event) {
          var hasExtension = /(.+)\.[a-zA-Z0-9]{2,5}$/
          var request = event.request
          var uri = request.uri

          // If the request does not have any extension, add '.html'
          if (uri && !uri.match(hasExtension)) {
            request.uri = `${uri}.html`
          }

          return request
        }
      FunctionConfig:
        Comment: "Adds .html postfix to viewer requests"
        Runtime: cloudfront-js-1.0