【问题标题】:Using Amazon Lambda fails with python example and S3在 python 示例和 S3 中使用 Amazon Lambda 失败
【发布时间】:2016-02-15 02:26:51
【问题描述】:

我正在尝试使用 Amazon Lambda 从 URL 获取数据并将内容存储在 S3 中。与此相关:Automatically retrieve JSON data via URL every X second and store in Amazon DynamoDB

这是我目前的代码:

from time import strftime
import urllib2, boto3

timekey = strftime("%Y-%m-%d %H:%M:%S")
time = strftime("%H:%M:%S")

response = urllib2.urlopen('http://open-stocks.com/api/get-data-' + time + '.json')
data = response.read()

s3 = boto3.resource('s3')
s3.Bucket('my-stocks-bucket').put_object(Key=timekey, Body=data)

我收到以下错误:

module initialization error:
An error occurred (PermanentRedirect) when calling the PutObject operation:
The bucket you are attempting to access must be addressed using the specified endpoint.
Please send all future requests to this endpoint.

怎么办?我没有为我的存储桶输入任何凭据,但它在同一个 AWS 用户上,我有我的 Lambda 函数和存储桶...

【问题讨论】:

    标签: python amazon-web-services amazon-s3 aws-lambda


    【解决方案1】:

    显然bucket和lambda函数需要在同一个区域。现在一切正常。

    【讨论】:

    • 在某些情况下,您需要将资源添加到同一个 VPC。
    猜你喜欢
    • 1970-01-01
    • 2015-08-09
    • 2013-06-16
    • 1970-01-01
    • 2012-09-19
    • 2017-01-01
    • 1970-01-01
    • 2016-02-08
    • 2021-10-26
    相关资源
    最近更新 更多