question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

aws-serverless-express + serverless-offline plugin = server error listen EACCES /tmp/server0.sock

See original GitHub issue

I am experimenting running the aws-serverless-express module in combination with the serverless-offline plugin for the serverless framework. This combination results in a critical error upon sending the request to the corresponding path and not when the serverless offline start command is run. Testing the offline plugin with another route not using the aws-serverless-express module runs fine and gives me a response. This is what I have:

package.json

{
  "name": "ExpresssLambdaServerless",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {},
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "aws-serverless-express": "^3.0.2",
    "express": "^4.16.2"
  },
  "devDependencies": {
    "serverless-offline": "^3.16.0"
  }
}

serverless.yml

service: aws-nodejs 
provider:
  name: aws
  runtime: nodejs6.10
functions:
  helloExpress:
    handler: index.handlerExpress
    events:
      - http: GET express
  helloPlain:
    handler: index.handlerPlain
    events:
      - http: GET plain
plugins:
  - serverless-offline

index.js

'use strict';
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');
const server = awsServerlessExpress.createServer(app);

// does NOT work
exports.handlerExpress = (event, context, callback) => awsServerlessExpress.proxy(server, event, callback);
// works
exports.handlerPlain = (event, context, callback) => {

	callback(null, { 
		statusCode: 200, 
		body: JSON.stringify({
		 works: true
		}) 
	});
};

app.js

'use strict';
const express = require('express');
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');
const app = express();
app.get('/express', (req, res) => {
  
  res.status(200).json({
    works: false
  });
});
module.exports = app;

Console output:

Git bash as admin on Windows 10
node -v: v8.9.0
$ sls offline start
Serverless: Starting Offline: dev/us-east-1.

Serverless: Routes for helloExpress:
Serverless: GET /express

Serverless: Routes for helloPlain:
Serverless: GET /plain

Serverless: Offline listening on http://localhost:3000

Serverless: GET /plain (λ: helloPlain)
Serverless: The first request might take a few extra seconds
Serverless: [200] {"statusCode":200,"body":"{\"works\":true}"}

Serverless: GET /express (λ: helloExpress)
Serverless: The first request might take a few extra seconds
ERROR: server error
{ Error: listen EACCES /tmp/server0.sock
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at Server.setupListenHandle [as _listen2] (net.js:1334:19)
    at listenInCluster (net.js:1392:12)
    at Server.listen (net.js:1487:5)
    at startServer (my-pc-path\node_modules\aws-serverless-express\index.js:136:19)
    at Object.proxy (my-pc-path\node_modules\aws-serverless-express\index.js:175:16)
    at exports.handlerExpress (my-pc-path\index.js:7:67)
    at handler (my-pc-path\node_modules\serverless-offline\src\index.js:751:25)
    at Object.internals.handler (my-pc-path\node_modules\hapi\lib\handler.js:96:36)
    at request._protect.run (my-pc-path\node_modules\hapi\lib\handler.js:30:23)
    at module.exports.internals.Protect.internals.Protect.run (my-pc-path\node_modules\hapi\lib\protect.js:64:5)
    at exports.execute (my-pc-path\node_modules\hapi\lib\handler.js:24:22)
    at each (my-pc-path\node_modules\hapi\lib\request.js:384:16)
    at iterate (my-pc-path\node_modules\items\lib\index.js:36:13)
    at done (my-pc-path\node_modules\items\lib\index.js:28:25)
    at module.exports.internals.Auth.internals.Auth._authenticate (my-pc-path\node_modules\hapi\lib\auth.js:210:16)
    at internals.Auth.authenticate (my-pc-path\node_modules\hapi\lib\auth.js:202:17)
    at each (my-pc-path\node_modules\hapi\lib\request.js:384:16)
    at iterate (my-pc-path\node_modules\items\lib\index.js:36:13)
    at done (my-pc-path\node_modules\items\lib\index.js:28:25)
    at internals.state (my-pc-path\node_modules\hapi\lib\route.js:357:16)
    at each (my-pc-path\node_modules\hapi\lib\request.js:384:16)
    at iterate (my-pc-path\node_modules\items\lib\index.js:36:13)
    at Object.exports.serial (my-pc-path\node_modules\items\lib\index.js:39:9)
    at internals.Request._lifecycle (my-pc-path\node_modules\hapi\lib\request.js:387:11)
    at internals.Request._execute (my-pc-path\node_modules\hapi\lib\request.js:302:21)
    at Domain.request._protect.enter (my-pc-path\node_modules\hapi\lib\connection.js:261:25)
    at Domain.run (domain.js:242:14)
    at module.exports.internals.Protect.internals.Protect.enter (my-pc-path\node_modules\hapi\lib\protect.js:80:17)
    at Server.<anonymous> (my-pc-path\node_modules\hapi\lib\connection.js:259:30)
    at emitTwo (events.js:126:13)
    at Server.emit (events.js:214:7)
    at parserOnIncoming (_http_server.js:602:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:117:23)
  code: 'EACCES',
  errno: 'EACCES',
  syscall: 'listen',
  address: '/tmp/server0.sock',
  port: -1 }

I tried running the serverless-offline plugin on a different port as well with the same result. My assumption is that both the serverless plugin and the aws-serverless-express modules are creating a server using the same resource and this is why it breaks when the express endpoint is called. I also tried changing the tmp path in index.js file of aws-serverless-express to something different, but didn’t work either.

I would highly appreciate some help. PM me if more info is needed. Thanks!!!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
brettstackcommented, Feb 9, 2018

Fixed in 3.1.1

1reaction
y13icommented, Feb 8, 2018

+1

I think _socketPathSuffix should be random value instead of incrementing number. cf. #5

I created a randomized suffix version https://github.com/y13i/aws-serverless-express/tree/feat-randomized-sock-suffix just for test purpose and you can test it with npm install @y13i/aws-serverless-express.

Should I send a pull request with that version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-serverless-express + serverless-offline plugin = server ...
I am experimenting running the aws-serverless-express module in combination ... plugin = server error listen EACCES /tmp/server0.sock #109.
Read more >
Node.js EACCES error when listening on most ports
It's giving me an EACCES error when it runs http.Server.listen() - but it only occurs on some ports. So, locally I'm running: joe@joebuntu:~$ ......
Read more >
Serverless offline plugin
This Serverless plugin emulates AWS λ and API Gateway on your local machine to speed up your development cycles. To do so, it...
Read more >
serverless-offline/community - Gitter
I remember when it was 5.10.0, the serverless-offline plugin just gave me ... server on port [PORT_DEFAULT_3000]: Error: listen EACCES: permission denied ...
Read more >
How to develop locally using serverless offline - Fauna
Serverless Offline is a time-saving plugin that emulates AWS λ and API Gateway on your local machine.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found