AWSCDNURL中默认根对象来自多个S3存储桶
创始人
2024-09-24 04:30:26
0

可以使用AWS Lambda函数和Amazon CloudFront的自定义起源以实现此目的。

  1. 首先,需要创建一个Lambda函数来处理请求。函数的主要功能是解析请求的URL路径,从不同的S3存储桶中检索对象并返回适当的根对象。以下是示例代码:
import boto3

s3 = boto3.resource('s3')

def handler(event, context):
    # Retrieve the object key from the URL path
    object_key = event["path"][1:]
    # Retrieve the appropriate S3 bucket name based on the object key
    bucket_name = get_bucket_name(object_key)
    # Retrieve the object from S3
    obj = s3.Object(bucket_name, object_key).get()
    # Return the object's data
    return {
        "statusCode": 200,
        "body": obj["Body"].read().decode('utf-8')
    }

def get_bucket_name(object_key):
    # Determine the appropriate S3 bucket to use based on the object key
    # You can implement your own logic here
    return ""
  1. 配置CloudFront分配为自定义起源,并将Lambda函数的ARN输入到“Origin Domain Name”字段中。

  2. 最后,将“Default Root Object”字段设置为Lambda函数负责的根对象的默认值,例如“index.html”。

这样,当CloudFront分配收到请求时,它将调用Lambda函数来检索适当的根对象并将其返回给客户端。

相关内容

热门资讯

透视苹果版!wepoke辅助挂... 透视苹果版!wepoke辅助挂,we辅助poker德之星,详细透视黑科技教程1、许多玩家不知道we辅...
透视插件!wepoke一定有挂... 透视插件!wepoke一定有挂,wepokeai代打,详细透视德州论坛1、wepoke一定有挂系统规...
透视了解!wepoke模拟器,... 透视了解!wepoke模拟器,wopoker分析器下载,详细透视第三方教程;一、wepoke模拟器A...
透视教程!wepoke确实有挂... 透视教程!wepoke确实有挂,wepoke辅助德之星,详细透视揭秘教程;wepoke辅助德之星是一...
透视代打!wepokeai机器... 透视代打!wepokeai机器人,wepoke软件透明挂多少钱,详细透视AI教程1、完成wepoke...
透视好友!wepoke辅助挂,... 透视好友!wepoke辅助挂,wepork私人局有挂吗,详细透视规律教程;1、玩家可以在wepoke...
透视工具!wepoke计算辅助... 透视工具!wepoke计算辅助,wepower有辅助器吗,详细透视2025新版教程1、进入游戏-大厅...
透视透视挂!WePoKe透视挂... 透视透视挂!WePoKe透视挂,wepower软件靠谱吗,详细透视新2025版1、完成WePoKe透...
透视能赢!wepoke辅助挂,... 透视能赢!wepoke辅助挂,wepower系统规律,详细透视分享教程;1、不需要AI权限,帮助你快...
透视挂!wepoke模拟器,w... 透视挂!wepoke模拟器,wepoke小技巧,详细透视新2025版wepoke模拟器辅助器中分为三...