question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors when using KeepAlive-style CloudWatch events

See original GitHub issue

I have a CloudWatch event that essentially acts as a keepalive function by calling my Alexa Lambda backend with a “matched event” once every 10 minutes.

This generates a ton of errors like this in my logs:

"errorMessage": "Cannot read property 'new' of undefined",
    "errorType": "TypeError",
    "stackTrace": [
        "new alexa.request (/var/task/node_modules/alexa-app/index.js:149:30)",
        "/var/task/node_modules/alexa-app/index.js:227:21",
        "tryCatcher (/var/task/node_modules/bluebird/js/main/util.js:26:23)",
        "Promise._resolveFromResolver (/var/task/node_modules/bluebird/js/main/promise.js:483:31)",
        "new Promise (/var/task/node_modules/bluebird/js/main/promise.js:71:37)",
        "alexa.app.request (/var/task/node_modules/alexa-app/index.js:226:12)",
        "handler (/var/task/node_modules/alexa-app/index.js:357:10)"
    ]

I don’t think this is hurting anything, but obviously I’d prefer to see something more constructive and less distracting than those errors.

Is there a better way to build a keepalive function with CloudWatch? Or should alexa-app be a little more resilient when it receives events that it’s not expecting?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
matt-krusecommented, Sep 4, 2018

I have a background task which triggers my Alexa Lambda function from a CloudWatch Event also. I have changed the lambda handler in my code to this, which handles the different request type. I defined my own app.scheduled() function that handles the CW event.

// connect to lambda
exports.handler = function(event, context, callback) {
  if (event && "aws.events"===event.source) {
    // Scheduled Event!
    app.scheduled(event).then((response)=>{
      callback(null,response);
    }).catch((e)=>{
      callback(e);
    });
  }
  else {
    // Alexa Request
    log("Alexa Request");
    app.handler(event, context, callback);
  }
};

This is another common use case that I think would be great to have handled within alexa-app itself.

0reactions
kobimcommented, Oct 28, 2018

maybe calling to .pre() and resolving the request will help?

app.pre(function(request, response) {
  if (request.data && request.data.source === 'aws.events') {
    console.log('ping!');
    response.resolved = true; // will skip the next handlers.
    response.response = {}; // will nullify the response. You can omit this if you don't care for the output.
  }
  return true;
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting CloudWatch Events - AWS Documentation
You can use the steps in this section to troubleshoot CloudWatch Events. ... A client error (ResourceNotFoundException) occurred when calling the GetPolicy ...
Read more >
Lambda with CloudWatch Events — Failure Handling - Medium
The setup will be really simple: A Lambda function that always throws an error, triggered by any CloudWatch event with a source equal...
Read more >
How to monitor AWS Lambda events through Cloudwatch ...
Stream logs to another lambda that can send SNS alert - the lambda can monitor key words like ERROR, Exception etc. Catch exceptions...
Read more >
Monitoring Amazon RAM using CloudWatch Events
Example: Alerting on resource share failures. Consider the scenario where you want to share Amazon EC2 capacity reservations with other accounts in your ......
Read more >
@aws-sdk/client-cloudwatch-events - npm
Start using @aws-sdk/client-cloudwatch-events in your project by ... easy to debug and has better error handling as compared to using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found