首页 > 解决方案 > 从 s3 Bucket 下载文件到 EC2 根路径

问题描述

我在尝试从my_bucket.

例子:

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):未找到

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

标签: pythonamazon-web-servicesamazon-s3amazon-ec2

解决方案


推荐阅读