title: Adding in cloudwatch events to emr cluster
body: <p>With the boto3 library, I want to  create an EMR cluster, then create events based off of cluster changes using cloud watch events.</p>
  
  <p>So I can create the cluster, but I'm a bit confused with how the <a href="https://boto3.readthedocs.io/en/latest/reference/services/events.html#CloudWatchEvents.Client.put_rule" rel="nofollow noreferrer">CloudWatchEvents section of boto3 works</a>.</p>
  
  <p>According to the documentation for CWE in the boto3 library, there's a parameter to <code>put_rule</code> called <code>EventPattern</code> that is a string.  It's described as the following:</p>
  
  <p><strong>EventPattern</strong> <em>(string)</em> -- The event pattern. For more information, see <a href="http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html" rel="nofollow noreferrer">Events and Event Patterns</a> in the Amazon CloudWatch Events User Guide .</p>
  
  <p>Following the link provided in the description, it shows a JSON object that looks like this:</p>
  
  <pre><code>{
    "source": [ "aws.ec2" ],
    "detail-type": [ "EC2 Instance State-change Notification" ],
    "detail": {
      "state": [ "running" ]
    }
  }
  </code></pre>
  
  <p>As I understand it, this is for custom events, but EMR provides <a href="http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#emr_event_type" rel="nofollow noreferrer">events for CloudWatch</a>. </p>
  
  <p>If I was to follow the pattern provided for an EMR event, would I need to provide a string that looked like this?</p>
  
  <pre><code>{
      "source": ["aws.emr"],
      "detail-type": "EMR Cluster State Change",
      "detail": {
           "clusterid": &lt;clusterid&gt;,
           "state": "STARTING"
      }
  }
  </code></pre>
  
  <p>Is there some flaw with this logic?  I'm a bit confused how it all fits together with the boto docs.</p>
  
  <p>I've tried converting the dictionary to a string by using the following code:</p>
  
  <pre><code>    client.put_rule(
      Name='Cluster_starting',
      EventPattern=str({
          "source": ["aws.emr"],
          "detail-type": "EMR Cluster State Change",
          "detail": {
              "clusterid": cluster_id,
              "state": "STARTING"
          }
      }),
      State="ENABLED"
  )
  </code></pre>
  
  <p>but got back the following error:</p>
  
  <pre><code>botocore.errorfactory.InvalidEventPatternException: An error occurred (InvalidEventPatternException) when calling the PutRule operation: Event pattern is not valid. Reason: Unexpected character (''' (code 39)): was expecting double-quote to start field name at [Source: {'source': ['aws.emr'], 'detail-type': 'EMR Cluster State Change', 'detail': {'state': 'STARTING', 'clusterid': '&lt;cluster_id&gt;'}}; line: 1, column: 3]
  </code></pre>