Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs] Different behaviour running on AWS Lambda vs Local #3587

Closed
nicopsz opened this issue Jan 17, 2019 · 2 comments
Closed

[Logs] Different behaviour running on AWS Lambda vs Local #3587

nicopsz opened this issue Jan 17, 2019 · 2 comments

Comments

@nicopsz
Copy link

nicopsz commented Jan 17, 2019

I run Scrapy from script https://doc.scrapy.org/en/latest/topics/practices.html#run-scrapy-from-a-script to launch a script from AWS Lambda. I compile the project with SAM and everything is correct.

But now, I have the problem with LOG_LEVEL parameter.

settings = {
                'USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36',
                'LOG_ENABLED': True,
                'LOG_LEVEL': 'ERROR'
             }

process = CrawlerProcess(settings=settings)

When execute this code in local, all is correct, only receive the LOG_LEVEL: ERROR, but when execute this code in AWS Lambda, I receive the LOG_LEVEL: DEBUG, and I don´t know how to resolve.

Is like the Spider doesn´t receive the settings of the Crawler. Any help?

Thanks!

@nicopsz nicopsz changed the title Different behaviour running on AWS Lambda vs Local [Logs] Different behaviour running on AWS Lambda vs Local Jan 17, 2019
@nicopsz
Copy link
Author

nicopsz commented Jan 23, 2019

Auto-answer:

It is necessary to remove the log handlers at first:

import logging
import scrapy
 

# --------     NECESSARY ACTION     --------  # 
root_logger = logging.getLogger()
for log_handler in root_logger.handlers:
    root_logger.removeHandler(log_handler)
# -------------------------------------------  #  

def handler(event, context):  # Lambda entry point

    # SPIDER

    settings = {
            'LOG_ENABLED': True,
            'LOG_LEVEL': 'ERROR'
            }

    process = CrawlerProcess(settings=settings)    

    process.crawl(Spider)
    process.start()

@nicopsz nicopsz closed this as completed Jan 23, 2019
@felipe-costa-compado
Copy link

@nicopsz How are you running scrapy in aws lambda?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants