简体   繁体   English

在 S3 文件上运行 Python 脚本

[英]Run a Python script on S3 Files

I want to run a python script on my entire S3 Bucket.我想在我的整个 S3 存储桶上运行一个 python 脚本。 The script takes the files and inserts them into a csv file.该脚本获取文件并将它们插入到 csv 文件中。

how can I run on the S3 files like a local script does?如何像本地脚本一样在 S3 文件上运行? using "python https://s3url/ " doesn't work for me.使用“python https://s3url/ ”对我不起作用。

You can use boto3 to get the list of all the files in s3 bucket:您可以使用 boto3 获取 s3 存储桶中所有文件的列表:

import boto3

bucketName = "Your S3 BucketName"

# Create an S3 client
s3 = boto3.client('s3')

for key in s3.list_objects(Bucket=bucketName)['Contents']: 
    print(key['Key'])

A good idea would be to use boto3 .一个好主意是使用boto3 Here is a simple guide on how to use the module这是有关如何使用该模块的简单指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM