Search code examples
amazon-web-servicesaws-lambdaalexa-skills-kitaws-iot

Can I determine which AWS service triggered my Lambda function?


I have a Python Lambda function that can respond to both an IoT Button and Alexa skill.

Is there a way to read the event or context handed to the handler function to identify which service triggered the function (Alexa or IoT)?


Solution

  • There is no way to reliably accomplish this. The closest you can get is to familiarize yourself with the contents of the various events generated by different services, and (hope to) identify a reliably unique key present in each of the series you are interested in that you can then check for in your code, e.g. with

    if 'distinctKey' in event.keys():
        # ...
    

    However this is hardly a reliable approach, since it requires that you

    1. examine every possible event structure generated by every potential service and
    2. successfully and confidently identify for each service of interest a key or set of keys that is always reliably present in the service's events and unique to them.