python - 如何使 s3 存储桶子图像迭代通用
问题描述
我在 s3 上的存储桶被命名为 'python' ,它的子文件夹是 'boss' 。所以我想在 lambda 函数中获取文件夹老板的所有图像。目前我正在硬编码值,但将图像放在根目录中而不是子文件夹中。
bucket="python"
key="20180530105812.jpeg"
然后我想对所有图像一一调用这个函数
def lambda_handler(event, context):
# Get the object from the event
bucket="ais-django"
key="20180530105812.jpeg"
try:
# Calls Amazon Rekognition IndexFaces API to detect faces in S3 object
# to index faces into specified collection
response = index_faces(bucket, key)
# Commit faceId and full name object metadata to DynamoDB
解决方案
在 s3 客户端上使用 list_object 操作。
bucket="python"
client=boto3.client('s3')
response = client.list_objects(
Bucket=bucket,
Prefix='boss'
)
numberofobjects=len(response['Contents'])
for x in range(1, numberofobjects):
try:
response2=index_faces(bucket, response['Contents'][x]['Key'])
推荐阅读
- rest - GitHub REST API 用于获取 repo 的所有打开的拉取请求 COUNT 而不下载它们
- wordpress - 将个人 Docker 映像上传到 Azure 容器注册表 - ErrImagePull
- python - Django“TypeError:'...'对象不可迭代”
- c++ - 返回 `std::string_view` 不包括第一个字符
- vb.net - 如何正确执行组合框依赖?
- c# - C#中的用户类
- android - MaterialApp 小部件的标题属性不起作用
- google-maps - 当我将 Googleplayservices v71 与 Xamarin Forms Maps v4.3 一起使用时出现异常
- sql - 计算表中最常见的
- java - 如何修复凯撒密码程序中的“char 无法转换为 java.lang.String”