Following this tutorial: https://levelup.gitconnected.com/resize-an-image-in-aws-s3-using-lambda-function-dc386afd4128
The code in question is used to resize an image upon uploading to bucket x and putting the resized one in bucket x-resized.
All works well up until I reach the testing phase, his s3 zip file gets accepted, however the test phase throws the following error:
{
"errorMessage": "Unable to import module 'CreateThumbnail': No module named 'CreateThumbnail'",
"errorType": "Runtime.ImportModuleError"
}
I should also mention that I changed his CreateThumbnail script from
def handler(event, context):
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
download_path = '/tmp/{}{}'.format(uuid.uuid4(), key)
upload_path = '/tmp/resized-{}'.format(key)
to
def handler(event, context):
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
download_path = '/{}{}'.format(uuid.uuid4(), key)
upload_path = '/resized-{}'.format(key)
From what I figure the script "downloads" the original image from a folder "tmp" and uploads it to a folder "tmp" which I don't have in either of my buckets, as I want it to be done in root.
If anyone can tell me why this happens even though the zip file includes all the required libraries, that would be great (and the CreateThumbnail.py). Thanks.
Fixed the import module problem, now this is the problem:
{
"errorMessage": "Failed to upload /tmp/resized-HappyFace.jpg to flatoro-resized/HappyFace.jpg: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied",
"errorType": "S3UploadFailedError",
"stackTrace": [
" File \"/var/task/CreateThumbnail.py\", line 24, in handler\n s3_client.upload_file(upload_path, '{}-resized'.format(bucket), key)\n",
" File \"/var/task/boto3/s3/inject.py\", line 131, in upload_file\n extra_args=ExtraArgs, callback=Callback)\n",
" File \"/var/task/boto3/s3/transfer.py\", line 287, in upload_file\n filename, '/'.join([bucket, key]), e))\n"
]
}
/tmplocation in lambda. - Arun KCreateThumbnail.handler? The zip seems to work (not tested using S3, but passed your error). I used it just now. - Marcin