import json
import boto3
s3 = boto3.client('s3')
bucket = "sksmsansdj"
old_key = "test.jpg"
new_key = "index.jpg"
def lambda_handler(event, context):
for e in event["Records"]:
if e["s3"]["object"]["key"] == old_key:
s3.copy_object(Bucket=bucket, CopySource={"Bucket": bucket, "Key": old_key}, Key=new_key)
s3.delete_object(Bucket=bucket, Key=old_key)
return json.dumps({"success": "OK!"})