Comments (6)
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.
I see the pb, solving it 😃
from serverless-offline.
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.
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.
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}
.
from serverless-offline.
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)
- Unhandled exception in handler 'index'. HOT 1
- Bump serverless-offline version to 12.0.5 HOT 1
- How to run lambda integration mode in serverless locally
- App hangs when launching in debug mode on Webstorm HOT 2
- ALB event doesn't reflect custom headers specified in handler.ts HOT 2
- dotnet6 future donet7 support HOT 1
- clientCert property is undefined when client certificates are used
- Extend support for ALB event paths
- Enable mixed API usage with same routes
- SLS_ACCOUNT_ID identity override for schedule events
- I think you removed Node 16 support too soon HOT 1
- How to set timeout properly HOT 1
- Add support for nodejs20.x runtime
- Stripping trailing slashes breaks django admin
- Inconsistency in `authorizer` Model When Using `serverless-offline` with AWS PowerTools for Lambda HOT 2
- How to clear cache on cognito HOT 1
- x-api-key no longer being provided HOT 4
- Lambci docker images are deprecated and no more maintained. HOT 1
- contentHandling
- MaxListenersExceededWarning with esbuild
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-offline.