title: How to access the event object with python in AWS Lambda?
body: <p>To follow up on this question:
  <a href="https://stackoverflow.com/questions/44548888/filter-cloudwatch-logs-to-extract-instance-id">Filter CloudWatch Logs to extract Instance ID</a></p>
  
  <p>I think it leaves the question incomplete because it does not say how to access the event object with python.</p>
  
  <p>My goal is to:</p>
  
  <ul>
  <li>read the instance that was triggered by a change in running state</li>
  <li>get a tag value associated with the instance</li>
  <li>start all other instances that have the same tag</li>
  </ul>
  
  <p>The Cloudwatch trigger event is:</p>
  
  <pre><code>{
    "source": [
      "aws.ec2"
    ],
    "detail-type": [
      "EC2 Instance State-change Notification"
    ],
    "detail": {
      "state": [
        "running"
      ]
    }
  }
  </code></pre>
  
  <p>I can see examples like this:</p>
  
  <pre><code>def lambda_handler(event, context):
  
      # here I want to get the instance tag value
      # and set the tag filter based on the instance that 
      # triggered the event
  
      filters = [{
              'Name': 'tag:StartGroup',
              'Values': ['startgroup1'] 
          },
          {
              'Name': 'instance-state-name', 
              'Values': ['running']
          }
      ]
  
      instances = ec2.instances.filter(Filters=filters)
  </code></pre>
  
  <p>I can see the event object but I don't see how to drill down into the tag of the instance that had it's state changed to running.</p>
  
  <p>Please, what is the object attribute through which I can get a tag from the triggered instance?</p>
  
  <p>I suspect it is something like:</p>
  
  <pre><code>myTag = event.details.instance-id.tags["startgroup1"]
  </code></pre>