在python示例和S3中使用AmazonLambda失败

在python示例和S3中使用AmazonLambda失败,python,amazon-web-services,amazon-s3,aws-lambda,Python,Amazon Web Services,Amazon S3,Aws Lambda,我试图使用AmazonLambda从URL获取数据,并将内容存储在S3中。与此相关: 这是我目前的代码: 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 + '.js

我试图使用AmazonLambda从URL获取数据,并将内容存储在S3中。与此相关:

这是我目前的代码:

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.

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

显然,bucket和Lambda函数需要位于同一区域。现在一切正常。

在某些情况下,您需要将资源添加到同一VPC。