是否有任何方法可以在aws中获得输出,以便为列表中的每个项目打印单独的行



好的,所以我有这个lambda函数,它附加了return_values[无论什么]列表,并以下面的格式发送到aws,问题是它用逗号分隔列表项,而不是用所需的新行。是否有方法使此格式正确?我已经尝试过打印(*结果,sep='n'),但这只是返回为None,因为打印只返回到控制台。

输出如下:

Here is a list of EC2 tags that need review.
Please correct the tags using the approved values list located below
<insert site here>.
------------------------------------------------------------------------------------
Summary of incorrect tags keys and/or values:
------------------------------------------------------------------------------------
Incorrect Tag Keys    :   []
Incorrect Tag Values  :   ['i-abc has a incorrect builder tag value.']
------------------------------------------------------------------------------------
Summary of missing tags keys and/or values:
------------------------------------------------------------------------------------
Missing Tag Keys     :   []
Missing Tag Values   :   []
------------------------------------------------------------------------------------
Summary of unknown values:
------------------------------------------------------------------------------------
Unknown Tag Values   :   ["i-abc has unknown for it's builder tag value.", "i-def has unknown for it's builder tag value.", "i-ghi has unknown for it's builder tag value."]
------------------------------------------------------------------------------------

Unknown在同一行出现了三次,目的是将每行的结果分开。代码的总体思路如下,感谢帮助。

def lambda_handler(event, context): 
reservations = ec.describe_instances().get('Reservations', [])
return_value = {} #creates empty dictionary#
return_value['missingtagkeys'] = [] #within return values dictionary, create a missing tag key list#
return_value['missingtagvalues'] = [] #within return values dictionary, creates a missing tag values key list#
return_value['incorrecttagkeys'] = [] #within return values dictionary, create a incorrect tag key list#
return_value['incorrecttagvalues'] = [] #within return values dictionary, create a incorrect tag value list#
return_value['unknowntagvalues'] = [] #within return values dictionary, create a unknown tag value list# 

incorrect_keys = return_value['incorrecttagkeys']
incorrect_values = return_value['incorrecttagvalues']
missing_keys = return_value['missingtagkeys']
missing_values = return_value['missingtagvalues']
unknowng_value = return_value['unknowntagvalues']

email_body = """
Here is a list of EC2 tags that need review.  
Please correct the tags using the approved values list located below  
<insert site here>.

------------------------------------------------------------------------------------
Summary of incorrect tags keys and/or values:
------------------------------------------------------------------------------------
Incorrect Tag Keys    :   {incorrectkeys}
Incorrect Tag Values  :   {incorrectvalues}
------------------------------------------------------------------------------------
Summary of missing tags keys and/or values:
------------------------------------------------------------------------------------
Missing Tag Keys     :   {missingkeys}
Missing Tag Values   :   {missingvalues}
------------------------------------------------------------------------------------
Summary of unknown values:
------------------------------------------------------------------------------------
Unknown Tag Values   :   {unknowngvalues}
------------------------------------------------------------------------------------
""".format(incorrectkeys = incorrect_keys, 
incorrectvalues = incorrect_values, 
missingkeys = missing_keys, 
missingvalues = missing_values, 
unknownvalues = unknown_value)  


sns_client.publish(
TopicArn = 'arn:aws:sns',
Subject = 'Incorrect Tags Detected',
Message = str(email_body) + str(return_value),
)
return return_value

最后一个例子是我如何让它工作的。

list_abc = ['aaa', 'bbb', 'ccc']
string = ''.join(list_abc)
print(string)
>>> aaabbbccc
string = ','.join(list_abc)
print(string)
>>> aaa,bbb,ccc
string = '-'.join(list_abc)
print(string)
>>> aaa-bbb-ccc
string = 'n'.join(list_abc)
print(string)
>>> aaa
>>> bbb
>>> ccc

相关内容

  • 没有找到相关文章