title: How to pass parameters to an AWS Lambda Function using Python
body: <p>I have written an AWS Lambda function in Python that filters through instances and turns them on or off depending on how they are tagged. This will show you a working function, and the set-up needed to get it working. If you have questions on anything post it in the comments.</p>
  
  <p>Here is my Lambda Function as of now:</p>
  
  <pre><code>import boto3
  def lambda_handler(event, context):
      startStop = event['startStop']
      vertical = event['vertical']
      isRunning = ''
  
      if(startStop == 'start'):
          isRunning = 'stopped'
      elif (startStop == 'stop'):
          isRunning = 'running'
  
      ec2 = boto3.resource('ec2')
      filters = [
          {
              'Name': 'instance-state-name', 
              'Values': [isRunning] 
          },
          {
              'Name': 'tag:Vertical',
              'Values': [vertical]
          }
      ]
  
      instances = ec2.instances.filter(Filters=filters)
  
      runningInstances = [instance.id for instance in instances]
  
      if len(runningInstances) &gt; 0:
          if(startStop == 'start'):
              shuttingDown = ec2.instances.filter(InstanceIds=runningInstances).start()
          elif (startStop == 'stop'):
              shuttingDown = ec2.instances.filter(InstanceIds=runningInstances).stop()
  </code></pre>
  
  <p>For reference, here is my mapping template:</p>
  
  <pre><code>{
      "startStop":"$input.params('startStop')",
      "vertical":"$input.params('vertical')"
  }
  </code></pre>
  
  <p>And this is how I am passing in the parameters within the URL:</p>
  
  <pre><code>https://awslambdaapiurl.../prod/-params?startStop=start&amp;vertical=TEST
  </code></pre>