I am getting "Lambda can't find the file lambda_function.py. Make sure that your handler upholds the format: file-name.method." error just above the AWS Lambda function code block. You can see the warning here
But as you can see in this code block, my file name is lambda_function and my function name is lambda_handler.
import boto3
import os
import logging
import uuid
from webdriver_screenshot import WebDriverScreenshot
logger = logging.getLogger()
logger.setLevel(logging.INFO)
s3 = boto3.client('s3')
def lambda_handler(event, context):
logger.info('## ENVIRONMENT VARIABLES')
logger.info(os.environ)
screenshot_file = "{}-{}".format(''.join(filter(str.isalpha, os.environ['URL'])), str(uuid.uuid4()))
driver = WebDriverScreenshot()
logger.info('Generate fixed height screenshot')
driver.save_screenshot(os.environ['URL'], '/tmp/{}-fixed.png'.format(screenshot_file), height=1024)
logger.info('Generate full height screenshot')
driver.save_screenshot(os.environ['URL'], '/tmp/{}-full.png'.format(screenshot_file))
driver.close()
if all (k in os.environ for k in ('BUCKET','DESTPATH')):
## Upload generated screenshot files to S3 bucket.
s3.upload_file('/tmp/{}-fixed.png'.format(screenshot_file),
os.environ['BUCKET'],
'{}/{}-fixed.png'.format(os.environ['DESTPATH'], screenshot_file))
s3.upload_file('/tmp/{}-full.png'.format(screenshot_file),
os.environ['BUCKET'],
'{}/{}-full.png'.format(os.environ['DESTPATH'], screenshot_file))
My code folder is like this and the main python code is in src folder. In AWS Lambda, my folder is looking like this. I do not understand what is the problem.
Even worse, when I try to test the code in AWS Lambda environment, this error is showing up. It says:
Unable to import module 'lambda_function': No module named 'boto3'
But I have the boto3 module in the layer, it is uploaded from my S3 Bucket. It is succesfully added to the function
The only thing I am suspecting, I may wrote environment variables wrong as shown here: environment variables due to I am a beginner in coding and AWS Lambda, I just copied both the PATH and PYTHONPATH from somewhere.
I don't know what to do next and need some support here.
Thanks.