0

I'm trying to use Amazon Lambda for getting data from an URL and store the content in S3. Related to this: Automatically retrieve JSON data via URL every X second and store in Amazon DynamoDB

This is my code so far:

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)

I'm getting the following error:

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.

What to do? I've not entered any credentials for my bucket, but it's on the same AWS user I've got my Lambda function and Buckets...

1 Answer 1

2

Apparently bucket and lambda function needs to be in the same region. Now things work.

Sign up to request clarification or add additional context in comments.

1 Comment

In some cases you need to add the resources to the same VPC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.