from PIL import Image
import json
import sys
import boto3

def lambda_handler(event, context):
    sqs_client = boto3.client('sqs')
    s3 = boto3.resource('s3')
    body = event['Records'][0]['body']
    body_events = json.loads(body)

    bucket_name = body_events['Records'][0]['s3']['bucket']['name']
    bucket_file = body_events['Records'][0]['s3']['object']['key']
    s3.meta.client.download_file(bucket_name, bucket_file, '/tmp/{}'.format(bucket_file))

    img = Image.open('/tmp/{}'.format(bucket_file))
    img1 = img.convert('L')
    img1.save('/tmp/{}'.format(bucket_file))
    img.close()
    bucket2 = 'xctestdel'

    s3.meta.client.upload_file('/tmp/{}'.format(bucket_file), bucket2, 'xcloud/{}'.format(bucket_file))