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

curl: (52) Empty reply from server with SAM local invoke. #3016

Closed
moroclash opened this issue Jul 4, 2021 · 4 comments
Closed

curl: (52) Empty reply from server with SAM local invoke. #3016

moroclash opened this issue Jul 4, 2021 · 4 comments
Labels
area/local/invoke sam local invoke command stage/needs-investigation Requires a deeper investigation type/bug

Comments

@moroclash
Copy link

Description:

I spend a lot of time tackling this problem, but it seems not sensible at all,
I have tried to build an AWS lambda function based on Custom Docker images, and I prepared the images well, and it works fine on my PC (with sam local invoke) and return the expected output, but I moved the files to EC2, and re-built the image, but when to test it locally it didn't work, the idea is simple, when invoking the image, there is Splash webdriver star and listen to http://0.0.0.0:8050 then go running the app.handler using RIE, and handler just making a request through splash by redirecting the request of the site using http://0.0.0.0:8050, but the response of curl was (52) Empty reply from server, which means there is a problem with that IP or port (not responding from server), but the same task works very well on my pc without this issue.

Steps to reproduce:

here is my Dockerfile
RG FUNCTION_DIR="/function"

FROM scrapinghub/splash as build-image
# FROM python:buster as build-image
USER root

# Include global arg in this stage of the build
ARG FUNCTION_DIR

# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
  apt-get install -y \
  g++ \
  make \
  cmake \
  unzip \
  libcurl4-openssl-dev

# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY . ${FUNCTION_DIR}

# Install the function's dependencies
RUN pip install \
    --target ${FUNCTION_DIR} \
        awslambdaric

FROM scrapinghub/splash as splash
USER root

ARG FUNCTION_DIR

ADD aws-lambda-rie /usr/local/bin/aws-lambda-rie
WORKDIR ${FUNCTION_DIR}

COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
RUN pip install -r requirements.txt
RUN pip install --upgrade twisted

ENTRYPOINT [ "./entery_point.sh" ]
CMD [ "app.lambda_handler" ]
entery_point.sh
#!/bin/sh
export PYTHONIOENCODING=utf-8

su splash -c "python3 ../app/bin/splash --proxy-profiles-path /etc/splash/proxy-profiles --js-profiles-path /etc/splash/js-profiles --filters-path /etc/splash/filters --lua-package-path /etc/splash/lua_modules/?.lu" &

if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/local/bin/aws-lambda-rie python3 -m awslambdaric $@
else
  exec python3 -m awslambdaric $@
fi    
app.py
import json
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
import os

def lambda_handler(event, context):
    os.system("curl http://0.0.0.0:8050/render.html?url=https://www.youtube.com/watch?v=8lJqXnf5wUw")
    return {
        "statusCode": 200,
        "body": json.dumps(
            {   
                "message": "don't look here, it's not important :)",
            }
        ),
    }
 

Observed result:

# this part refer that splash is running
##############################
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-splash'
2021-07-04 01:10:08.262982 [-] Splash version: 3.5
2021-07-04 01:10:10.127206 [-] Qt 5.14.1, PyQt 5.14.2, WebKit 602.1, Chromium 77.0.3865.129, sip 4.19.22, Twisted 21.2.0, Lua 5.2
2021-07-04 01:10:10.136148 [-] Python 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
2021-07-04 01:10:10.139174 [-] Open files limit: 8192
2021-07-04 01:10:10.139286 [-] Open files limit increased from 8192 to 1048576
2021-07-04 01:10:10.231634 [-] proxy profiles support is enabled, proxy profiles path: /etc/splash/proxy-profiles
2021-07-04 01:10:10.232199 [-] memory cache: enabled, private mode: enabled, js cross-domain access: disabled
2021-07-04 01:10:11.190742 [-] verbosity=1, slots=20, argument_cache_max_entries=500, max-timeout=90.0
2021-07-04 01:10:11.193003 [-] Web UI: enabled, Lua: enabled (sandbox: enabled), Webkit: enabled, Chromium: enabled
2021-07-04 01:10:11.196077 [-] Site starting on 8050
2021-07-04 01:10:11.196401 [-] Starting factory <twisted.web.server.Site object at 0x7fba14043c18>
2021-07-04 01:10:11.201506 [-] Server listening on http://0.0.0.0:8050

# trying to CURL
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0
curl: (52) Empty reply from server
Killed

END RequestId: fa35f978-9785-4ed9-908f-24b24a0cdd48
REPORT RequestId: fa35f978-9785-4ed9-908f-24b24a0cdd48  Init Duration: 4.51 ms  Duration: 25832.99 ms   Billed Duration: 25900 ms       Memory Size: 128 MB     Max Memory Used: 128 MB 
{"statusCode": 200, "body": "{\"message\": \"don't look here, it's not important :)\"}"}

Expected result:

I know that the function returns the expected results, but the problem it's not work as expected, I have used the same image once on the local pc, and it works correctly and as expected (with sam and with docker), once on EC2, but the above problem happened, and i tried to deploy it, but the same problem happened.

I also tried to mimic the same task to run it using docker, by making a file that starts Splash then makes curl request, and name it main, then run the docker image using
docker run --rm -it --entrypoint python3 lambda-splash:latest main.py
and it returned the expected output well, so that means the problem, not in the Docker network, it seems in RLE,
any ideas ?

Additional environment details (Ex: Windows, Mac, Amazon Linux, etc)

  1. OS: EC2, Ubuntu 20, t3.micro
  2. sam --version: SAM CLI, version 1.25.0
  3. AWS region: us-east-2

Add --debug flag to command you are running

@wchengru wchengru added area/local/invoke sam local invoke command type/bug stage/needs-investigation Requires a deeper investigation labels Jul 4, 2021
@moroclash
Copy link
Author

moroclash commented Jul 26, 2021

@wchengru any updates?!, or any suggestion to deep debug?

@xazhao
Copy link
Contributor

xazhao commented Aug 11, 2021

@moroclash Hi I'm not familiar with tools you're using. Here is another issue about running sam local invoke in Docker: #2492. Maybe you could take a look?

@jfuss
Copy link
Contributor

jfuss commented Dec 12, 2022

I am going to close this given no responses. If this is still an issue, please create a new Github Issue with reproducible steps so we can understand better were things might be going wrong for you.

@jfuss jfuss closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2022
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command stage/needs-investigation Requires a deeper investigation type/bug
Projects
None yet
Development

No branches or pull requests

4 participants