Я хочу вызвать лямбду из другой лямбды внутри автономного сервера. Я хочу создать автономное веб-приложение без сервера. Но я получаю эту ошибку:
{UnknownError: Unsupported Media Type atObject.extractError (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ protocol \ json.js: 51: 27) в Request.extractError (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ protocol \ rest_json.js: 55: 8) в Request.callListeners (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ sequential_executor.js: 106: 20) в Request.emit (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ sequential_executor.js: 78: 10) в Request.emit (C: \ Users \ gourabkonar\ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 683: 14) в Request.transition (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 22: 10) в AcceptorStateMachine.runTo (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ state_machine.js: 14: 12) в C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ state_machine.js: 26: 10 по запросу. (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 38: 9) по запросу. (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 685: 12) в Request.callListeners (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \aws-sdk \ lib \ sequential_executor.js: 116: 18) в Request.emit (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ sequential_executor.js: 78: 10) по запросу.emit (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 683: 14) в Request.transition (C: \ Users \ gourabkonar \ Desktop \ sls-demo \node_modules \ aws-sdk \ lib \ request.js: 22: 10) в AcceptorStateMachine.runTo (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ state_machine.js: 14: 12)в C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ state_machine.js: 26: 10 по запросу. (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 38: 9) по запросу. (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ request.js: 685: 12) в Request.callListeners (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \aws-sdk \ lib \ sequential_executor.js: 116: 18) в callNextListener (C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ sequential_executor.js: 96: 12) в IncomingMessage.onEnd(C: \ Users \ gourabkonar \ Desktop \ sls-demo \ node_modules \ aws-sdk \ lib \ event_listeners.js: 307: 13) в IncomingMessage.emit (events.js: 203: 15) в IncomingMessage.EventEmitter.emit (domain.js: 448: 20) в endReadableNT (_stream_readable.js: 1129: 12) в process._tickCallback (internal / process / next_tick.js: 63: 19) сообщение: «Неподдерживаемый тип носителя», код: «UnknownError»,время: 2019-11-06T17: 02: 27.641Z, requestId: не определено, statusCode: 415, повторяемый: false, retryDelay: 6.643720301281952}
sls-api-dev-создать
const jobs=[
{ id: 1,title: 'NodeJS Developer'},
{id: 2, title:'Angular Developer'}
];
var AWS = require('aws-sdk');
AWS.config.region = 'ap-southeast-2';
let lambda = new AWS.Lambda({
region: 'ap-south-1',
endpoint: 'http://localhost:3000/jobs'
})
module.exports.handler=async(evt,ctx)=>{
console.log(evt.body);
jobs.push(JSON.parse(evt.body));
lambda.invoke({
FunctionName: 'sls-api-dev-hello',
InvocationType: 'Event',
Payload:null
},function(err,data){
console.log('No error');
if(!err)
console.log(data);
else
console.log(err);
})
//console.log(response);
return {
statusCode :200,
body:JSON.stringify({
jobs
})
}
}
sls-api-dev-hello
'use strict';
module.exports.hello = async event => {
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'Welcome to Serverless',
input: event,
},
null,
2
),
};
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};
serverless.yml
service: sls-api
provider:
name: aws
runtime: nodejs10.x
region: ap-south-1
iamRoleStatements:
- Effect: Allow
Action:
- lambda: InvokeFunction
- lambda: InvokeAysnc
Resource: "*"
plugins:
- serverless-offline
- serverless-offline-lambda
functions:
hello:
handler: handler.hello
jobs:
handler: src/jobs/handler.handler
listJobs:
handler: src/jobs/list.handler
events:
- http:
method: GET
path: /jobs
createJobs:
handler: src/jobs/create.handler
environment:
SOME_VARIABLE: http://localhost:3000/jobs
events:
- http:
method: POST
path: /jobs
getJob:
handler: src/jobs/findOne.handler
events:
- http:
method: GET
path: /jobs/{id}
request:
parameters:
id: true
Пожалуйста, онlp, любая помощь будет отличной, так как я новичок в безсерверной работе. Заранее спасибо.