Browse Source

add py/s3+lambda+sqs.py.

xdc 5 năm trước cách đây
mục cha
commit
a3d39450f1
1 tập tin đã thay đổi với 22 bổ sung0 xóa
  1. 22 0
      py/s3+lambda+sqs.py

+ 22 - 0
py/s3+lambda+sqs.py

@@ -0,0 +1,22 @@
+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))