Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import boto3
- from botocore.exceptions import ClientError
- import logging
- import botocore
- def lambda_handler(event, context):
- f = open('data.txt') # Open file on read mode
- lines = f.read().split("\n") # Create a list containing all lines
- print lines
- print(type(lines))
- s3_client = boto3.client("s3")
- response = s3_client.list_buckets()
- for bucket in response["Buckets"]:
- print bucket
- # Only removes the buckets with the name you want.
- if "ir.creapp.building-requests" in bucket["Name"]:
- s3_objects = s3_client.list_objects_v2(Bucket=bucket["Name"])
- # Deletes the objects in the bucket before deleting the bucket.
- if "Contents" in s3_objects:
- for s3_obj in s3_objects["Contents"]:
- rm_obj = s3_client.delete_object(
- Bucket=bucket["Name"], Key=s3_obj["Key"])
- print(rm_obj)
- rm_bucket = s3_client.delete_bucket(Bucket=bucket["Name"])
- print(rm_bucket)
- f.close() # Close file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement