question

newuser-515d5694-4e6f-428c-bd60-b602628809ef avatar image

My AWS Lambda function is not getting 'request.header.namespace' in the request directive from Smart Home Skills API

I have created an Alexa Skill (Smart Home type) and configured it with ARN associated with my AWS Lambda function (eu-west). I have also linked it with "Login with Amazon" and set the scope to "profile". I have then created an AWS Lambda function for Smart Home, and added triggers for "Alexa Skills Kit" and "Alexa Smart Home" correctly. I have also configured test events, and they are able to correctly turn on and turn off my devices through my device cloud APIs. When I test device discovery using the test event, the test succeeds and the request and response directives looks fine when I checked the CloudWatch logs. The request directive in the log entry contains the request header that identifies the namespace as "Alexa.ConnectedHome.Discovery" correctly. However, when I initiate "Add Device" from the Alexa App or Echosim.io, I get "No new devices found" in the App. When I looked at CloudWatch log, it shows that the request directive does not contain the request header at all. The request directive only contains the request id. Since there is no header, no namespace in the request directive, the log entry shows an error: "TypeError: Cannot read property 'namespace' of undefined at exports.handler (/var/task/index.js:374:27)". This clearly shows that the request directive does not contain the header information. Since I have configured it as "Smart Home" type, I had expected the Alexa Smart Home API to call my Lambda function with the 'request.header.namespace' set to "Alexa.ConnectedHome.Discovery". But, this is not the case. I checked out various online forums including Amazon support. But, none of them helped. Can you please help me resolve the device discovery issue?

alexa skills kitalexa smart homelambda
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

KAIYIN@AMAZON.COM avatar image
KAIYIN@AMAZON.COM answered

Are you using V2 API or V3? Looks like the one that you expected in Lambda is V2, but in developer.amazon.com you can only select V3 as default since V2 is deprecated.

Look at the sample code in Lambda, V2 and V3 has different request format:

logger.info("Directive:") logger.info(json.dumps(request, indent=4, sort_keys=True))

version = get_directive_version(request) if version == "3": logger.info("Received v3 directive!")

if request["directive"]["header"]["name"] == "Discover": response = handle_discovery_v3(request) else: response = handle_non_discovery_v3(request)

else: logger.info("Received v2 directive!")

if request["header"]["namespace"] == "Alexa.ConnectedHome.Discovery": response = handle_discovery() else: response = handle_non_discovery(request)

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.