Serverless-offline: Add support for lambda-proxy integration

Created on 10 Oct 2016  路  7Comments  路  Source: dherault/serverless-offline

Not sure if this has been done or not, but there is a new api integration LAMBDA-PROXY and it's supported by serverless#1.0 https://github.com/serverless/serverless/pull/2185

I'm assuming this plugin will need some changes to support the new integration. I also think, adding support for the new integration will be easy, because it requires far less parsing and manipulation of incoming request and outgoing response when compared by the current integration.

Most helpful comment

Temporarily, you could replace the event with the following code in the line 416 of the index.js file.

event = {
  httpMethod: request.method.toUpperCase(),
  headers: request.headers,
  pathParameters: Object.assign({}, request.params),
  queryStringParameters: Object.assign({}, request.query),
  body: JSON.stringify(request.payload),
  stageVariables: this.velocityContextOptions.stageVariables,
};

All 7 comments

馃憤

This should be a really quick win. We should return the proxy like event by default, or apply the current mappings if the integration: lambda has been set.

Temporarily, you could replace the event with the following code in the line 416 of the index.js file.

event = {
  httpMethod: request.method.toUpperCase(),
  headers: request.headers,
  pathParameters: Object.assign({}, request.params),
  queryStringParameters: Object.assign({}, request.query),
  body: JSON.stringify(request.payload),
  stageVariables: this.velocityContextOptions.stageVariables,
};

HI @leonardoalifraco ! Thank you, but I could not get this working. Which line exactly do you mean to replace with this one? (tried 416 in <projectdir>/node_modules/serverless-offline/src/index.js on the v1 branch. Maybe I have to compile something (it's in /src) or it has moved meanwhile?). Any help appreciated!

Take a look at my PR. You can use that one until it gets merged (soon, only some docs are pending)

Hi @leonardoalifraco !

Thanks for getting back. Maybe I am still missing something, but here are the different results I get, using the current v1 branch, aws and your branch (B). I hope I am using the right branch (I tried to clone from the pull request and also directly form your repo's branch).

(A) serverless-offline v1

"serverless-offline": "git+https://github.com/dherault/serverless-offline.git/#serverless_v1"
npm install
sls offline

result:

{
    statusCode: 200,
    headers: {
        Content-Type: "text/html"
    },
    body: "<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <title>sony-dealerlocator early prototype</title> <style> html, body { height: 100%; margin: 0; padding: 0; } #map { height: 90vh; width:100%; } .btn { width:10%; background:#f25529; } #search { height:10vh; width:90%; z-index:30000; display: flex; padding-left:5%; padding-right:5%; } #search #searchTextField { height:100%; width:100%; font-size:30px; outline: none; ..."
}

(B) Your PR

"serverless-offline": "git+https://github.com/leonardoalifraco/serverless-offline.git/#lambda-proxy-event"

also

"serverless-offline": "git+https://github.com/dherault/serverless-offline/#pull/117/head"

npm install
sls offline

result:

{
    statusCode: 500,
    error: "Internal Server Error",
    message: "An internal server error occurred"
}

(C) AWS

sls deploy

result:

<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> ... 
as expected


Which is of course what is expected. (same 500 i get for other function which return the usual json, not html). The code is always the same, except the serverless-offline devDependency in package.json. Happy to help with the docs if I can.

Eager to see it's being fixed.
+1

Merged! v3.2.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattmeye picture mattmeye  路  4Comments

jormaechea picture jormaechea  路  4Comments

stunningpixels picture stunningpixels  路  3Comments

ozbillwang picture ozbillwang  路  4Comments

JimLynchCodes picture JimLynchCodes  路  4Comments