Giter Site home page Giter Site logo

Comments (6)

dherault avatar dherault commented on May 27, 2024

I'm on it! Can you provide some lambda function and config ? Also, are you on serverless 0.4 ? Thanks.

EDIT: @ngothanhtai I can access POST data/body/payload with my config. I don't wanna show it to you because I'm interested in yours. Does your lambda works on AWS ? If so I'm even more interested. Thanks again.

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

I see the pb, solving it 😃

from serverless-offline.

ngothanhtai avatar ngothanhtai commented on May 27, 2024

Hi @dherault,
Thanks for your quick response.
I don't define any template for POST content. Everything post from client will available in "event" object.

I used Postman to test the API and here is the result:
Error: Something went wrong while parsing the response as JSON: Unexpected ''
https://gyazo.com/a9b8db481b31da1685970491fd4d1f77

testPost/handler.js

// Lambda Handler
module.exports.handler = function(event, context) {
    console.log(event);
    context.done(null, event);
};

s-function.json:

{
  "name": "testPost",
  "customName": false,
  "customRole": false,
  "handler": "test/testPost/handler.handler",
  "timeout": 6,
  "memorySize": 1024,
  "custom": {
    "excludePatterns": [],
    "envVars": []
  },
  "endpoints": [
    {
      "path": "test/testPost",
      "method": "POST",
      "type": "AWS",
      "authorizationType": "none",
      "apiKeyRequired": false,
      "requestParameters": {},
      "requestTemplates": {
        "application/json": ""
      },
      "responses": {
        "400": {
          "statusCode": "400"
        },
        "default": {
          "statusCode": "200",
          "responseParameters": {},
          "responseModels": {},
          "responseTemplates": {
            "application/json": ""
          }
        }
      }
    }
  ],
  "events": []
}

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

Soooo,
Solving your issue was easy: my bad, I could have seen it coming.
But I had to write a few lambda to know how APIG (weirdly) behaves with content-type.
Please run npm update (v1.0.6) and tell me if it solved your pb.

Thanks for the issue, the plugin got nicer 😅

from serverless-offline.

ngothanhtai avatar ngothanhtai commented on May 27, 2024

The "event" object now have data but only { isOffline: true }. Even though, I passed { "id": 1}.
I tried to run with args --debugOffline and see in payload they have { "id": 1}.
screen shot 2016-03-09 at 12 27 01 am

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

As seen in your screenshot, there is no template found for the application/json content-type.

Here's how to configure your s-function.json file to extract the payload (and client's ip as another example) from the request:

"requestTemplates": {
    "application/json": {
        "payload": "$input.json('$')",
        "sourceIp": "$context.identity.sourceIp"
    }
}

Here's the resulting event object:

{
  payload: {
    id: 1
  },
  sourceIp: "1.2.3.4",
  isOffline: true,
}

If you plan on using other content-type, like multipart/form-data, specify another template for it.

from serverless-offline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.