You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code of function initializeServerless working properly and setting this.serverless to the generated sls
asyncinitializeServerless(){process.env.SLS_DEBUG="*"constslsService=awaitServerlessInvoker.loadServerlessYaml(path.join(this.servicePath,"serverless.yml"))constconfig={serviceDir: path.dirname(this.servicePath),configurationFilename: "serverless.yml",configuration: slsService,commands: [],options: {},}constsls=newServerless(config)// creates the new Serverlessreturnsls.init().then(()=>{sls.service.load().then(()=>{sls.service.setFunctionNames({})sls.service.mergeArrays()sls.service.validate()**this.serverless=sls**// should set this.serverless to the created Serverless})})}
Actual behavior:
The initializeServerless function does not seem to set this.serverless = sls in time so that this.loadServerlessEvents throws an error as this.serverless is still null. (TypeError: Cannot read properties of null (reading 'service') at ServerlessInvoker.loadServerlessEvents)
asyncinvoke(httpRequest,event,context){// Read the serverless.yml filereturnthis.initializeServerless().then(()=>**this.loadServerlessEvents()**)// error thrown by this function.then((httpEvents)=>{// find the event that matches the specified httpRequestlethttpEvent=httpEvents.find((e)=>e.test(httpRequest))if(!httpEvent){thrownewError(`Serverless http event not found for HTTP request "${httpRequest}" in service path "${this.servicePath}".`)}
asyncloadServerlessEvents(){letfuncs=**this.serverless.service**// is null.getAllFunctions().map((fname)=>{letfuncObj=this.serverless.service.getFunction(fname)letevents=this.serverless.service.getAllEventsInFunction(fname)letf={name: fname,handler: funcObj.handler,events: events.filter((e)=>Object.keys(e).includes("http")&&e.http!==null),}
Setting this.serverless = sls earlier or solved the problem for me:
constsls=newServerless(config)returnsls.init().then(()=>{**this.serverless=sls**// e.g. heresls.service.load().then(()=>{sls.service.setFunctionNames({})sls.service.mergeArrays()sls.service.validate()})
Steps to reproduce the problem:
Create test class with a serverlessInvoker instance
service: service
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs18.x
region: eu-central-1
resources:
# externalize Resources to separated file to get support by IDE for cloudformation
- ${file(serverless-resources.yml)}
…vice') at ServerlessInvoker.loadServerlessEvents" when calling invoke (#127)
ensures initializeServerless() runs sequentially as described in #126fixes#126
Co-authored-by: scott willeke <scott@willeke.com>
Expected behavior:
Code of function
initializeServerless
working properly and settingthis.serverless
to the generatedsls
Actual behavior:
The
initializeServerless
function does not seem to setthis.serverless = sls
in time so thatthis.loadServerlessEvents
throws an error asthis.serverless
is stillnull
.(TypeError: Cannot read properties of null (reading 'service') at ServerlessInvoker.loadServerlessEvents)
Setting
this.serverless = sls
earlier or solved the problem for me:Steps to reproduce the problem:
Create test class with a serverlessInvoker instance
and exectue the invoke function
a serverless.yml
serverless-resources.yml
Environment:
serverless-http-invoker 3.0.6
serverless 3.31.0
node 18
macOS 13.1.1
The text was updated successfully, but these errors were encountered: