title: Lambda that can get arguments from both direct invocation and SNS message
body: <p>Is it possible to construct a Lambda handler such that it will be able to get its arguments from either SNS, <em>or</em> via direct invocation?<br>
  In other words, the same Lambda can be invoked either explicitly or via subscription to SNS topic.</p>
  
  <p>Purpose is to have a Lambda that is usually triggered via SNS 90% of the time, but also allow for manual invocation via Console or web API.</p>
  
  <p>It looks like this may be possible via something like</p>
  
  <pre><code>def lambda_handler(event, context):
     args = parse_sns_event(event) if 'Records' in event else event
  </code></pre>
  
  <p>Assuming that 'Records' is <a href="https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-sns" rel="nofollow noreferrer">the top-level key in the Lambda SNS event</a>, and that 'Records' is not the name of one of the expected arguments.</p>
  
  <p>Is there a better way to do this?  (Short of having two Lambdas - one main worker plus another to receive the SNS message and invoke the other)</p>