Я пытаюсь отправить вывод emrStatusCheck в службу SNS.Я могу напечатать вывод.Однако когда он предоставляется в службе SNS, это приводит к сообщению об ошибке.Заранее спасибо.
"" Ошибка проверки параметра: \ nНеверный тип для параметра Сообщение, значение: [\ "Cluster_ID = 0000, Name_of_cluster =, status_of_cluster = RUNNING, Instance_Group = CORE, Market = ON_DEMAND, CreationDateTime =2019-02-14 19: 12: 50.944000 + 00: 00, NormalizedInstanceHours = 112, автомасштабирование = нет, Assigned_tags = [{'Key': 'test', 'Value': 'test'}, {'Key': 'test ',' Value ':' test '}, {' Key ':' test ',' Value ':' test '}, {' Key ':' test ',' Value ':' test '}] \ "], тип:, допустимые типы: ",
import boto3
import json
from datetime import timedelta
REGION = 'us-east-1'
Topic_Arn = "arn:aws:sns:us-east-1:000000:Lambd"
emrclient = boto3.client('emr', region_name=REGION)
snsclient = boto3.client('sns', region_name=REGION)
def lambda_handler(event, context):
EMRS = emrclient.list_clusters(
ClusterStates = ['STARTING', 'RUNNING', 'WAITING']
)
clusters = EMRS["Clusters"]
for cluster_details in clusters :
id = cluster_details.get("Id")
describe_cluster = emrclient.describe_cluster(
ClusterId = id
)
cluster_values = describe_cluster["Cluster"]
name = cluster_values.get("Name")
tag_val = cluster_values.get("Tags")
Instancehours = cluster_values.get("NormalizedInstanceHours")
emr_ig = emrclient.list_instance_groups(
ClusterId = id
)
emrid = emr_ig["InstanceGroups"]
for item in emrid :
purchase_type = item.get("Market")
instancegroup_id = item.get("Id")
instancegroup_type = item.get("InstanceGroupType")
status = item.get("Status")
state = status.get("State")
timeline = status.get("Timeline")
autoscaling = item.get("AutoScalingPolicy", None)
#autoscaling_status = autoscaling.get("Status")
#autoscaling_state = autoscaling_status.get("State")
create_date_time = timeline.get("CreationDateTime")
ready_date_time = timeline.get("ReadyDateTime")
emrdetails = "Cluster_ID = " + id + "," + " Name_of_cluster = " + name + "," + " status_of_cluster = " + state + "," + " Instance_Group = " + instancegroup_type + "," + " Market = " + purchase_type + "," + " CreationDateTime = " + str(create_date_time) + "," + " NormalizedInstanceHours = " + str(Instancehours) + "," + " Autoscale = " + str(autoscaling) + "," + " Assigned_tags = " + str(tag_val)
emr_status_list = []
emr_status_list.append(emrdetails)
emrStatusCheck = []
for emr_status in emr_status_list :
if ((emr_status.split(",")[4]).split("=")[1].strip() == str("ON_DEMAND") and (emr_status.split(",")[3]).split("=")[1].strip() == str("CORE") or (emr_status.split(",")[7]).split("=")[1].strip() == str("None")):
emrStatusCheck.append(emr_status)
snsclient.publish(
TopicArn = Topic_Arn,
Message = emrStatusCheck,
Subject = "EMR Cluster Details",
)