我正在尝试读取我之前写入的 S3 文件的内容。当我从本地 boto3 脚本读取时,我可以看到文件的内容,但是当我使用 Chalice 在 Lambda 上运行代码时,我得到“NotFoundError”
这是Chalice App的代码
from chalice import Chalice
import boto3
import json
from botocore.exceptions import ClientError
from chalice import NotFoundError
app = Chalice(app_name='scraper-one')
app.debug = True
s3 = boto3.resource('s3')
bucket = 'scraper-one'
key = 'csv'
@app.route("/")
def index():
return {"hello": "world"}
@app.route('/{content}', methods=['GET', 'PUT'])
def to_s3(content):
request = app.current_request
if request.method == 'PUT':
s3.put_object(bucket=bucket, Key=key, Body=content)
return {"content": content}
elif request.method == 'GET':
try:
obj = s3.Object(bucket, key)
return json.loads(obj.get()['Body'].read().decode('utf-8'))
except ClientError as e:
raise NotFoundError(key)
这是运行良好的本地脚本。
import boto3
s3 = boto3.resource('s3')
bucket = 'scraper-one'
key = 'csv'
obj = s3.Object(bucket, key)
print(obj.get()['Body'].read().decode('utf-8'))
关于我缺少什么的任何想法?