从s3存储桶下载文件到EC2根路径

时间:2018-12-27 07:35:39

标签: python amazon-web-services amazon-s3 amazon-ec2

尝试从my_bucket下载xml文件时遇到麻烦。

示例:

s3:Path: my_bucket>>First_archives_file>>Second_archives_file>>xmlFile.xml

我正在尝试以下方法:

for row2 in self.cursor.fetchall():
        print(row2[0].strip())#PATH : prueba-cgirano/LoadXml/AME880912I89/2018/01/0628757E-7FEC-4A9B-961F-69F1A62875C0.xml
        print(row2[1].strip())#FILE_NAME : 0628757E-7FEC-4A9B-961F-69F1A62875C0

        path = python_path(str(row2[1].strip()+'.xml')).replace('\\','/')
        print(path) #/root/0628757E-7FEC-4A9B-961F-69F1A62875C0.xml

        print('path')
        try:
            #self.s3.Bucket('my_bucket').download_file(str(row2[1].strip()+'.xml'),str(row2[1].strip()+'.xml'))
            self.s33 = boto3.client('s3',aws_access_key_id='MY_KEY',aws_secret_access_key='MY_ACCESS_KEY')
            #self.s33.download_file('my_bucket',str(row2[1].strip()+'.xml'),path+str(row2[1].strip()+'.xml'))
            self.s33.download_file('pruebas-cgirano',str(row2[0].strip().replace('pruebas-cgirano/','')),path)

            result = self.print_info(path)
            print(result)
            if e.response['Error']['Code']=="404":
                print('The object does not exist.')
            else:
                raise
        except Exception as err:
            print(err)

但这给了我这个错误:

调用HeadObject操作时发生错误(404):未找到

我需要浏览许多archive_file以获得xmlFile,然后下载到我的EC2实例中以管理内容。我已经有管理内容的逻辑,问题是我无法将xml文件下载到我的EC2实例。

0 个答案:

没有答案