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

Unable to connect to local server #1156

Closed
mbrg opened this issue Jan 7, 2021 · 2 comments
Closed

Unable to connect to local server #1156

mbrg opened this issue Jan 7, 2021 · 2 comments

Comments

@mbrg
Copy link

mbrg commented Jan 7, 2021

Bug Report

serverless offline start executes successfully, but I'm unable to connect to the local server. I'm trying to POST to the Lambda endpoint with curl but I get no response (and no logs on the server process either).

To verify that this is not a firewall issue, I used node's http-server and was successfully able to call it with curl 127.0.0.1:8080.

Current Behavior

Running serverless offline executes successfully:

$ SLS_DEBUG=* sls offline start --migrate --verbose --stage local

Serverless: Running "serverless" installed locally (in service node_modules)
...
...
offline: Offline [http for lambda] listening on http://localhost:4002
offline: Function names exposed for local invocation by aws-sdk:
           * collector: collectors-service-local-collector
[offline] Lambda Invocation Routes (for AWS SDK or AWS CLI):
           * POST http://localhost:4002/2015-03-31/functions/myfunction/invocations
[offline] Lambda Async Invocation Routes (for AWS SDK or AWS CLI):
           * POST http://localhost:4002/2014-11-13/functions/myfunction/invoke-async/

Curl waits forever:

$ curl -X POST 127.0.0.1:4002/2015-03-31/functions/myfunction/invocations
# never returns

$ curl -X POST localhost:4002/2015-03-31/functions/myfunction/invocations
# never returns

$ curl -X POST http://127.0.0.1:4002/2015-03-31/functions/myfunction/invocations
# never returns

$ curl -X POST http://localhost:4002/2015-03-31/functions/myfunction/invocations
# never returns

Connection thru Python3 boto3 doesn't work as well

import boto3
cli = boto3.client("lambda", endpoint_url=f"http://localhost:4002/")
cli.invoke(FunctionName="myfunction",InvocationType="RequestResponse")

botocore.exceptions.ReadTimeoutError: Read timeout on endpoint URL: "http://localhost:4002/2015-03-31/functions/myfunction/invocations"

Sample Code

  • file: serverless.yml
service: <my-service>

frameworkVersion: '2'

plugins:
  - serverless-python-requirements
  - serverless-iam-roles-per-function
  - serverless-pseudo-parameters
  - serverless-plugin-scripts
  - serverless-offline

package:
  exclude:
    - .dynamodb/**
    - .pytest_cache/**
    - node_modules/**
  excludeDevDependencies: false

provider:
  name: aws
  runtime: python3.6
  stage: ${opt:stage}
  region: ${opt:region}
  tracing:
    apiGateway: true
    lambda: true
  logRetentionInDays: 7

custom:
  serverless-offline:
    httpPort: 4000
    lambdaPort: 4002
    stage: local
  pythonRequirements:
    pythonBin: python3.6
    slim: true
    slimPatternsAppendDefaults: false
    slimPatterns:
      - "**/*.pyc"
      - "**/*.pyo"
      - "**/__pycache__*"
    invalidateCaches: true
    useStaticCache: false
    vendor: ../common/src

functions:
  myfunction:
     handler: src/handler.handler
     iamRoleStatementsInherit: true
     maximumEventAge: 21600 # 6 hours in seconds
     maximumRetryAttempts: 2
     events:
       - eventBridge:
           eventBus: <my-eventbus-arn>
           pattern:
             source:
             - <my-source>
             detail-type:
              - <my-detail>

Expected behavior/code
Being able to invoke functions locally.

Environment

  • serverless version: 2.17.0
  • serverless-offline version: 6.8.0
  • node.js version: v15.5.1
  • OS: Ubuntu-18.04.05 LTS (running on Win10 19042.685 using WSL2)
  • python version: 3.6.9
@hajekjiri
Copy link

As pointed out in #1150, this seems to be an issue with node v15.5.x. Downgrading to v15.4.0 should fix the problem.

I downgraded to the LTS (v14.15.4) because that was the easiest solution with my package manager and it also fixed the issue.

@mbrg
Copy link
Author

mbrg commented Jan 10, 2021

Thanks @hajekjiri, that worked!

@mbrg mbrg closed this as completed Jan 10, 2021
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