Executing SmartApp on Lamba - Stuck with error

Hello community :wave:,

I am trying to setup a SmartApp using an AWS Lambda using the nodeJS SDK. I’ll keep aside the logic of the app, since I face the issue using a very basic sample application. I’ve already spent a few hours trying to figure out what is happening, but no luck.

The SmartApp:

The code is taken from this sample: Simple Smartapp
It is inserted into the Lambda IDE, the SDK is loaded, the locales/ folder and its content exist, all the express related code was removed and replaced by the Lambda handler:

export const handler = async (event, context, callback) => {
    app.handleLambdaCallback(event, context, callback);
};

The SmartApphas been successfully registered through the developer portal and is deployed to “Test”.

Symptoms:

Whenever I try to install the SmartApp using the iOS mobile app, the following error appears: Something went wrong. Please try to install the SmartApp again.

Steps I already took to try to fix the issue:

  • I’ve tried to execute the very same application on Glitch. It worked like a charm. That is why I am thinking of a Lambda related issue
  • I increased the timeout/memory of the Lambda, did not have any effect
  • I tried to check on the Live Logging feature, but all I can see is a set of CONTROL_EVENT triggered every minute. Whenever I try to (un)install the SmartApp, there is no activity at all
  • I checked on CloudWatch, to see the activity from the Lambda point of view. I can see all the requests/responses. Which leads me to the following conclusions:
    • Smartthings is allowed to reach and invoke the Lambda (excludes some permissions issues?)
    • The last response sent by the lambda is strictly identical to the one sent by the Glitch version (see below). Yet, it doesn’t work with the Lambda.
{
  "statusCode": 200,
  "configurationData": {
    "page": {
      "name": "Lights Open/Close",
      "complete": true,
      "pageId": "mainPage",
      "nextPageId": null,
      "previousPageId": null,
      "sections": [
        {
          "name": "When something opens or closes",
          "settings": [
            {
              "id": "sensor",
              "required": true,
              "type": "DEVICE",
              "name": "Select an open/close sensor",
              "description": "Tap to set",
              "multiple": false,
              "capabilities": [
                "contactSensor"
              ],
              "permissions": [
                "r"
              ]
            }
          ]
        },
        {
          "name": "Turn on and off these lights",
          "settings": [
            {
              "id": "lights",
              "required": false,
              "type": "DEVICE",
              "name": "Select lights & switches",
              "description": "Tap to set",
              "multiple": true,
              "capabilities": [
                "switch"
              ],
              "permissions": [
                "r",
                "x"
              ]
            }
          ]
        }
      ]
    }
  }
}

I am a bit lost with this one. Any help would be really appreciated :pray:

Thanks!

Welcome back to the SmartThings Community, @nikkow!

Are you sure everything from the SmartApp is added through the Lambda IDE?
I’ve seen before that it gets rejected because it’s too heavy, that’s why on this Lambda SmartApp sample Serverless is used: GitHub - SmartThingsCommunity/smartapp-example-no-devices-nodejs-lambda: Give Lambda SmartApps a try without any physical devices..

However, something important to check as well is the scopes you selected (whitelisted) in the Dev Workspace, especially if you use those scopes in the SmartApp definition. Those are set in the property permissions, for example:

.permissions(['r:locations:*'])

Did you select the same scopes in the Lambda project as in the Webhook project with Glitch?

Hi @nayelyz, thanks for your feedback!

I am pretty sure that everything is imported correctly to the Lambda ecosystem. You can see the file tree on the screenshot below (node_modules is not expanded, but contains the SmartApp SDK -v4.2.0- and its subdependencies)

Another clue that indicates everything is imported correctly is that whenever I install the SmartApp through the iOS app, it triggers the Lambda, which outputs the correct and expected JSON. I can monitor them from CloudWatch (see first output below, only an extract: it continues after that):

If something was missing (a dependency, or a package that wouldn’t be imported to the Lambda IDE), it would trigger an error on the logs.

I also checked the permissions: both projects (Glitch and Lambda) have both all the scopes selected. I tried to add the .permissions() part to the Lambda and the .appId(), but it still returns an error on the mobile app (though I can still see the JSON being generated on the CloudWatch logs).

I also tried the sample you provided: no luck, Lambda still gives me the same error on the mobile (and the JSON generated are visible on the logs).

Thanks!

Mmm…have you verified it has the correct permissions added for SmartThings access? I thought that was checked during the registration in the Dev Workspace but I have seen that mostly in Schema Connectors, so, I could be wrong.
They are the ones mentioned in this section of the SmartApp documentation: Hosting with AWS Lambda | SmartThings Developers

Yes, I did double check:

And it is confirmed by the fact the Lambda is invoked when I try to install the SmartApp via the mobile app.

ok, please share the following info to ask the engineering team if they can see any logs:

  1. App ID. This comes from the Dev Workspace
  2. Timestamp on when you try to install the SmartApp including your timezone. Eg. 10:20 am CST
  3. The execution ID that appears in the installation request’s JSON.

Okay, sharing the app ID publicly won’t cause any security issues?

You can send it over DM, or at build@smartthings.com

Thanks, I sent it over DM. Please let me know if you need any other information.