gpt4 book ai didi

aws-cloudformation - 如何在模板文件中设置 CloudFront 函数的 FunctionCode 属性?

转载 作者:行者123 更新时间:2023-12-03 07:12:06 32 4
gpt4 key购买 nike

我正在尝试使用云形成(YAML 模板文件)在我的堆栈中部署 CloudFront 函数。如何为我的 CloudFront Function 指定 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

关于aws-cloudformation - 如何在模板文件中设置 CloudFront 函数的 FunctionCode 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67608477/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com