My current Lambda_function code is: (it's purpose is to resize images when to 600x400 when uploaded and then having them saved)
import boto3
import os
import pathlib
from io import BytesIO
from PIL import Image
s3 = boto3.resource('s3')
def delete_this_bucket(name):
bucket = s3.Bucket(name)
for key in bucket.objects.all():
try:
key.delete()
bucket.delete()
except Exception as e:
print("SOMETHING IS BROKEN !!")
def create_this_bucket(name, location):
try:
s3.create_bucket(
Bucket=name,
CreateBucketConfiguration={
'LocationConstraint': location
}
)
except Exception as e:
print(e)
def upload_test_images(name):
for each in os.listdir('./testimage'):
try:
file = os.path.abspath(each)
s3.Bucket(name).upload_file(file, each)
except Exception as e:
print(e)
def copy_to_other_bucket(src, des, key):
try:
copy_source = {
'Bucket': src,
'Key': key
}
bucket = s3.Bucket(des)
bucket.copy(copy_source, key)
except Exception as e:
print(e)
def resize_image(src_bucket, des_bucket):
size = 600, 400
bucket = s3.Bucket(src_bucket)
in_mem_file = BytesIO()
client = boto3.client('s3')
for obj in bucket.objects.all():
file_byte_string = client.get_object(Bucket=src_bucket, Key=obj.key)['Body'].read()
im = Image.open(BytesIO(file_byte_string))
im.thumbnail(size, Image.ANTIALIAS)
# ISSUE : https://stackoverflow.com/questions/4228530/pil-thumbnail-is-rotating-my-image
im.save(in_mem_file, format=im.format)
in_mem_file.seek(0)
response = client.put_object(
Body=in_mem_file,
Bucket=des_bucket,
Key='resized_' + obj.key
)
def lambda_handler(event, context):
bucket = s3.Bucket('bucketname1')
for obj in bucket.objects.all():
copy_to_other_bucket(bucket, 'bucketname1', obj.key)
resize_image(bucket.name, 'bucketname1')
print(bucket)
And I'm having errors with ssl verification it says.
"errorMessage": "SSL validation failed for https://bucketname1.s3.eu-west-3.amazonaws.com/?encoding-type=url [Errno 2] No such file or directory",
"errorType": "SSLError",
Can anyone help me with what the problem is? I think it might be either a problem in code or some AWS lambda settings configuration.