小编Sil*_*hus的帖子

AWS Lambda 函数根据请求从 S3 提供文件

我有以下代码

import boto3

def lambda_handler(event, context):
    s3 = boto3.resource('s3')

    bucket = 'bucketName'
    prefix = 'folder1/'
    request = "requestURL"

    return s3.Object(bucket, prefix + request).get()['Body'].read()
Run Code Online (Sandbox Code Playgroud)

我打算将其与 API Gateway 一起使用,以获得一个可以查询并从 S3 提供文件的 URL,如下所示:

function url: http://magic-lambda-function.aws....com/magic这是 API Gateway 提供的 URL。

如果我调用http://magic-lambda-function.aws....com/magic/folder1/folder2/file1,请从 s3_bucket/folder1/folder2/file1 读取 file1 并输出它。

有人尝试过类似的东西吗?预先感谢您的任何帮助。

PS:我无法直接从 S3 提供文件,因为它们的名称包含查询。

amazon-web-services python-2.7 aws-lambda aws-api-gateway

6
推荐指数
1
解决办法
3378
查看次数

Python KafkaConsumer 从时间戳开始消费消息

我打算跳过主题的开头,只读取从某个时间戳到结尾的消息。关于如何实现这一目标的任何提示?

python-3.x apache-kafka kafka-consumer-api kafka-python

2
推荐指数
1
解决办法
3328
查看次数

从其他服务器提供静态文件,同时保持进程不可见

我要实现的目标是从S3存储桶为多个网站提供文件,而不显示项目的真实路径。文件存储在S3存储桶中,例如:bucket / website

例:

domain: domain.com
static: static.domain.com
Run Code Online (Sandbox Code Playgroud)

我不想为每个网站都创建S3存储桶,所以我想将所有文件存储在存储桶文件夹中,并使用脚本从那里提供服务。

我目前有:

<?php

    $path = "domain";
    $file = "filename";

    // Save a copy of the file
    file_put_contents($file, fopen($path . $file, 'r'));

    // Set the content type and output the contents
    header('Content-Type: ' . mime_content_type($file));
    readfile($file);

    // Delete the file
    unlink($file);

?>
Run Code Online (Sandbox Code Playgroud)

但这不是那么干净,因为我保存了文件然后将其输出。由于网站可能具有相同名称的文件,因此保存文件可能会导致混乱。我也缺少.htaccess文件来进行正确的重写,因此看来您是从static.domain.com/file获得文件的,而不是从static.domain.com/script获得的文件。

关于如何实现这一点的任何建议都很棒!提前谢谢了!

php apache .htaccess amazon-s3

0
推荐指数
1
解决办法
647
查看次数