'How to delete thousands of objects from s3 bucket with in specific object folder?

Im having thousands of objects in all the folders gocc1, gocc2,etc

s3://awss3runner/gocc1/gocc2/goccf/

i just want to delete the objects(50,000+) from goccf and its versions

import boto3
session = boto3.Session()
s3 = session.resource(service_name='s3')
#bucket = s3.Bucket('awss3runner','goccf')if we use this getting error
bucket = s3.Bucket('awss3runner') # (working but if we use this everything in the bucket getting deleted)
bucket.object_versions.delete()

is there anyway to delete goccf objects and its versions



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source