import boto3 def key_exists(mykey, mybucket): s3_client = boto3.client('s3') try: response = s3_client.list_objects_v2(Bucket=mybucket, Prefix=mykey) for obj in response['Contents']: if mykey == obj['Key']: return 'exists' return False # no keys match except KeyError: return ...
問題描述 使用 boto3 檢查 s3 的存儲桶中是否存在密鑰 (check if a key exists in a bucket in s3 using boto3) 我想知道 boto3 中是否存在密鑰。我可以循環存儲桶內容並檢查密鑰是否匹配。 但這似乎更長而且有點過分。Boto3 官方文檔明確說明瞭如何執行此操作。 可
#!/usr/bin/env python import boto3 s3_client = boto3.client('s3') head = s3_client.head_object( Bucket="<S3 bucket name>", Key="<S3 object key>" ) if 'ServerSideEncryption' in head: print head['ServerSideEncryption'] python amazon-web-services encryption boto3 Share Improve this...
import boto3 s3 = boto3.resource('s3') bucket = s3.Bucket('<givebucketnamehere>') def IsObjectExists(path): for object_summary in bucket.objects.filter(Prefix=path): return True return False if(IsObjectExists("<giveobjectnamehere>")): print("Directory/File exists") e...