CloudFront函数始终返回503 [英] Cloudfront Function always returns 503
本文介绍了CloudFront函数始终返回503的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CloudFront函数返回了无效值:Response.statusCode缺失
在AWS控制台中测试成功,那么为什么它在托管网站上不起作用?
重定向处理程序
function handler(event) {
var request = event.request;
var uri = request.uri;
// Check whether the URI is missing a file name.
if (uri.endsWith('/')) {
request.uri += 'index.html';
}
// Check whether the URI is missing a file extension.
else if (!uri.includes('.')) {
request.uri += '/index.html';
}
return request;
}
CloudFront设置
myFunction = new Function(this, 'ViewerResponseFunction', {
functionName: 'RedirectURIFunction',
code: FunctionCode.fromFile({filePath: myFilePath}).render(),
comment: "Comment about the function"
});
originConfigs: [
{
s3OriginSource: {
s3BucketSource: myBucket,
originAccessIdentity: myOAI,
},
behaviors: [{
functionAssociations: [{
function: myCfnFunction,
eventType: FunctionEventType.VIEWER_RESPONSE
}],
isDefaultBehavior: true
}]
]}
推荐答案
来自restrictions page of Lambda@Edge
Lambda功能必须位于美国东部(弗吉尼亚州北部)区域。
您的代码仍将在距离用户最近的边缘位置执行,但函数本身必须位于us-East-1。
根据您的用例(似乎是一个简单的url重定向),您可能想要考虑使用更新的CloudFront函数功能,它更快、更轻量级。此documentation page有一个很好的对比表。编辑:
我以前没有使用过CloudFront函数,但查看CDK文档和您的链接,我可以建议进行一些更改。
myFunction = new Function(this, 'ViewerResponseFunction', {
functionName: 'RedirectURIFunction',
code: FunctionCode.fromFile({filePath: myFilePath}).render(),
comment: "Comment about the function"
});
originConfigs: [
{
s3OriginSource: {
s3BucketSource: myBucket,
originAccessIdentity: myOAI,
},
behaviors: [{
functionAssociations: [{
function: myFunction,
eventType: FunctionEventType.VIEWER_REQUEST
}],
isDefaultBehavior: true
}]
]}
- Function Association接口仅支持L2构造Function,不支持CfnFunction。
- 您链接的GitHub sample提到查看器请求。
这篇关于CloudFront函数始终返回503的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文