2017-11-07 1 views
0

boto3 라이브러리를 사용하여 EMR 클러스터를 생성하고 클라우드 감시 이벤트를 사용하여 클러스터 변경 사항을 기반으로 이벤트를 생성하려고합니다.emr 클러스터에 cloudwatch 이벤트 추가하기

그래서 클러스터를 만들 수 있지만 다소 혼란 스럽습니다. CloudWatchEvents section of boto3 works.

boto3 라이브러리의 CWE 문서에 따르면 put_rule 인 문자열은 EventPattern이며 문자열입니다. 그것은 다음과 같은 설명은 다음과 같습니다

EventPattern(문자열) - 이벤트 패턴. 자세한 내용은 Amazon CloudWatch Events 사용자 가이드의 Events and Event Patterns을 참조하십시오. 설명에 제공된 링크를

,이처럼 보이는 JSON 개체를 보여줍니다 : 나는 그것을 알고있는 것처럼

{ 
    "source": [ "aws.ec2" ], 
    "detail-type": [ "EC2 Instance State-change Notification" ], 
    "detail": { 
    "state": [ "running" ] 
    } 
} 

이 사용자 정의 이벤트입니다 만, EMR은 events for CloudWatch을 제공합니다.

EMR 이벤트에 제공된 패턴을 따르려면이 모양의 문자열을 제공해야합니까?

{ 
    "source": ["aws.emr"], 
    "detail-type": "EMR Cluster State Change", 
    "detail": { 
     "clusterid": <clusterid>, 
     "state": "STARTING" 
    } 
} 

이 논리에는 몇 가지 결함이 있습니까? 나는 boto 문서들과 모두 어떻게 어울리는 지 혼란 스럽다.

나는 다음과 같은 코드를 사용하여 문자열로 사전을 변환 시도했다 :

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" 
) 

을하지만, 다음과 같은 오류 돌아 왔을 : 나는 지적했다 AWS 지원에 이야기 한 후

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': '<cluster_id>'}}; line: 1, column: 3] 

답변

0

을 오류.

예제 사전에서는 모든 값이 배열 내에 유지되므로 "clusterid"= "[]"이어야하고 따옴표는 이스케이프해야합니다.

관련 문제