0

I am connecting AWS IoT things via Rest APIs using End points from AWS lambda. But now i want to make it dynamic, i.e. for each different user requesting from alexa, i want to request APIs of corresponding AWS-IoT account. I am assuming there will be different AWS-IoT account for each user, as every user can have a thing named water pump.

I can do so by making one lambda per user. But i want to do it by a common lambda function

HimanshuR
  • 1,390
  • 5
  • 16
  • 35
  • Wouldn't all of your users' things be individual things in **your** AWS IoT account? You wouldn't expect your users to sign up with AWS just to use their thing with your skill, surely... would you? Maybe I'm missing something. – Michael - sqlbot Apr 07 '17 at 06:59
  • How will i differentiate users on lambda apart from access token? – HimanshuR Apr 07 '17 at 07:29
  • More than one user can have same name of a device – HimanshuR Apr 07 '17 at 07:35
  • You can't just go off the name of the device... that doesn't really seem to make sense. You'll have to map *something*, so why would you not correlate the user-id in the incoming request with the (user-selected) device-name chosen by that user, as stored in your backend database, to find the client-id of the correct thing? – Michael - sqlbot Apr 07 '17 at 09:40

1 Answers1

0

Yes, you can and should use a single, common Lambda for all of your users. Each user has a unique ID created by Amazon when yoour skill is installed on their device. Each request send to your lambda will contain this userId so that your skill can save that user's preferences, state, etc.:

{
  "version": "string",
  "session": {
    "new": true,
    "sessionId": "string",
    "application": {
      "applicationId": "string"
    },
    "attributes": {
      "string": {}
    },
    "user": {
      "userId": "string",
...

Refer to the Alexa documentation to understand each of the fields passed in the request: JSON Interface Reference for Custom Skills.

Ron Lisle
  • 1,164
  • 6
  • 11
  • Is this session object available for Home Automation skill too – HimanshuR Apr 10 '17 at 07:05
  • No, sorry. I didn't realize you were talking about a smart home skill. There are no sessions in smart home skills. I think what you are trying to figure out is explained in "Account Linking", which is also used by all smart home skills. – Ron Lisle Apr 12 '17 at 10:38