Reputation: 181
I have the following code
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()
I intend to use this with API Gateway to have a URL that I can query and serve a file from S3 like this:
function url: http://magic-lambda-function.aws....com/magic this is the URL that API Gateway provides.
If I would call http://magic-lambda-function.aws....com/magic/folder1/folder2/file1 ,read the file1 from s3_bucket/folder1/folder2/file1 and output it.
Has anyone tried something similar? Thank you in advance for any help.
PS: I can't serve the files directly from S3 because their names contain queries.
Upvotes: 6
Views: 3610
Reputation: 46839
You don't need a Lambda function to do this, you can use AWS API Gateway and set up a service proxy - much simpler. AWS has built this functionality for you already (almost).
Upvotes: 3