aws-samples / cdk-alexa-skill

MIT No Attribution
10 stars 3 forks source link

How to formulate skill.json file for a smart home skill #34

Open wz2b opened 3 weeks ago

wz2b commented 3 weeks ago

I'm not sure how to formulate a skill.json for a smart home skill. For it to show up as a smart home skill, rather than a custom skill, I think you're supposed to specify the API. The problem is, I don't know how to do that. If you were doing it by hand you would specify the 'endpoint' but in this case it's not static. The function is created by the CDK script. I think what you have to do is just let cdk-alexa-skill do it, because when you don't specify any API at all it creates a skill that points to the right function -- but it's not a smart home skill, it's a custom skill.

How do you build a smart home skill with cdk-alexa-skill?

{
  "manifest": {
    "publishingInformation": {
      "locales": {
        "en-US": {
          "name": "xxxx",
          "summary": "yyyy",
          "description": "zzzz",
          "examplePhrases": [  ],
          "keywords": []
        }
      },
      "testingInstructions": "",
      "category": "SMART_HOME",
      "distributionCountries": []
    },
    "manifestVersion": "1.0",

    "apis": {
      "smartHome": {
        "endpoint": {
          "uri": "arn:aws:lambda:us-east-1:040623927470:function:sampleSkill"
        },
    }
  }
}
wz2b commented 3 weeks ago

I have been working on this and running into problem after problem. I am not able to create an Alexa Smart Home skill even when specifying "smartHome" as the API. As is often the case with CDK, the failure is fairly opaque:

Error occurred while updating the skill. Cause: Skill not found with id: amzn1.ask.skill.267a770c-xxxx-4891-83fc-xxxxxxxx
xxxx-ha-skill 

That's coming from the CDK script itself, where it's trying to create the skill and failing for some unknown reason. Part of this could be because of timing. As pointed out in the blog post explaining how all this should work:

When the Skill’s endpoint is set to a Lambda Function, the ASK service validates that the
Skill has the appropriate permissions to invoke that Lambda Function. 

To get around that I tried setting up the lambda function to remove event source filtering (just as a test), eliminating the cycle, but that didn't fix the problem. I then thought perhaps the function isn't callable yet (CDK dependency resolution should take care of that but who knows) so I tried creating a script to create everything but the skill (including the lambda) then modified it to create just the skill - at this point the lambda would definitely be callable. It still failed.

So I think this whole thing is sketchy back at the ask.CfnSkill layer.

What's more worrying, though, is that there are still a pretty great number of manual steps you have to perform. A home skill won't work without account linking, and I can't see a way CLoudFormation lets you set that up.

I'm nearly at the point of giving up on the approach. It might be better to just create a custom CDK resource and use the SMAPI APIs including Account Linking. That has its own complications, and the author advised against it:

While the ASK Skill Management API is another option, managing imperative API
calls within a CI/CD pipeline would not be ideal.

I agree it's not ideal, especially related to authentication (to use SMAPI). But at this point I don't see a way around it.

  1. CDK sets up the lambda function, IAM permissions, etc. (and any thing else the skill needs, like dynamodb). If not using LWA, the stack could also set up a different auth mechanism - possibly by including a Cognito configuration as part of the stack
  2. A custom CDK resource creates the skill, sets up the account linking, then sets up Skill ID Verification (if required).