SHARE
TWEET

Untitled

a guest Nov 19th, 2019 122 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. import boto3
  3. from botocore.exceptions import ClientError
  4. import logging
  5. import botocore
  6.  
  7. def lambda_handler(event, context):  
  8.     f = open('data.txt') # Open file on read mode
  9.     lines = f.read().split("\n") # Create a list containing all lines
  10.     print lines
  11.     print(type(lines))
  12.     s3_client = boto3.client("s3")
  13.     response = s3_client.list_buckets()
  14.     for bucket in response["Buckets"]:
  15.         print bucket
  16.         # Only removes the buckets with the name you want.
  17.         if "ir.creapp.building-requests" in bucket["Name"]:
  18.             s3_objects = s3_client.list_objects_v2(Bucket=bucket["Name"])
  19.             # Deletes the objects in the bucket before deleting the bucket.
  20.             if "Contents" in s3_objects:
  21.                 for s3_obj in s3_objects["Contents"]:
  22.                     rm_obj = s3_client.delete_object(
  23.                         Bucket=bucket["Name"], Key=s3_obj["Key"])
  24.                     print(rm_obj)
  25.             rm_bucket = s3_client.delete_bucket(Bucket=bucket["Name"])
  26.             print(rm_bucket)
  27.  
  28.  
  29.     f.close() # Close file
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top