The code below work locally and uploads files from a directory to S3. It's using Boto3 with Python 3.
import os
import boto3
AWS_ACCESS_KEY_ID = 'xxxxx'
AWS_ACCESS_KEY_SECRET = 'xxxxx'
bucket_name = 'dev.MYDOMAINHERE.co.uk'
sourceDir = "../../docs/html/"
destDir = ''
s3 = boto3.resource('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY_SECRET)
bucket = s3.Bucket(bucket_name)
uploadFileNames = []
for (sourceDir, dirname, filenames) in os.walk(sourceDir):
for filename in filenames:
bucket.put_object(Key=filename, Body=open("{}{}".format(sourceDir, filename), "rb"))
break
My problem is what when I run the same code on my production server (Ubuntu) I get the following error, why?
Traceback (most recent call last):
File "upload.py", line 15, in <module>
bucket.put_object(Key=filename, Body=open("{}{}".format(sourceDir, filename), "rb"))
File "/usr/local/lib/python3.4/site-packages/boto3/resources/factory.py", line 344, in do_action
response = action(self, *args, **kwargs)
File "/usr/local/lib/python3.4/site-packages/boto3/resources/action.py", line 77, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/usr/local/lib/python3.4/site-packages/botocore/client.py", line 270, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.4/site-packages/botocore/client.py", line 335, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: 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.
Again locally on my Mac this code works, it is only on my Ubuntu server I get this error.
Aucun commentaire:
Enregistrer un commentaire