How to print each string in a new line in an email using AWS SNS service.
If I print a message in Python output all strings is in new lines:
JavaScript
x
3
1
Started copying.. snapshot_id: snap-000000aeaada0000 from: region_src to: region_dst with new snapshot_id: new_snapshot_id
2
Started copying.. snapshot_id: snap-000000aeaada0001 from: region_src to: region_dst with new snapshot_id: new_snapshot_id
3
but in an email it is all in one line:
JavaScript
1
2
1
Started copying.. snapshot_id: snap-05b3834aeaada5a02 from: region_src to: region_dst with new snapshot_id: new_snapshot_id Started copying.. snapshot_id: snap-012d3db747de08d1f from: region_src to: region_dst with new snapshot_id: new_snapshot_id
2
JavaScript
1
34
34
1
import boto3
2
3
region_src = 'us-east-1'
4
sns_arn = "arn:aws:sns:us-east-1:000000000099:AWS_LAMBDA_NOTIFICATIONS"
5
6
def copy_snapshot_src_to_dst(snapshot_id):
7
message = ("Started copying.. snapshot_id: " + str(snapshot_id) + " from: " + "region_src" + " to: " + "region_dst" + " with new snapshot_id: " + "new_snapshot_id")
8
#print(message)
9
10
return message
11
12
def lambda_handler():
13
snapshots_id = [('snap-000000aeaada0000', [{'Key': 'Backup_Type', 'Value': 'Demo'}, {'Key': 'Backup Initiator Rule', 'Value': 'Daily-6d-retention'}, {'Key': 'Disaster_Recovery', 'Value': 'Full'}, {'Key': 'aws:backup:source-resource', 'Value': 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'}, {'Key': 'Name', 'Value': 'HOSTNAME'}]), ('snap-000000aeaada0001', [{'Key': 'Name', 'Value': 'HOSTNAME'}, {'Key': 'Backup Initiator Rule', 'Value': 'Daily-6d-retention'}, {'Key': 'Backup_Type', 'Value': 'Demo'}, {'Key': 'Disaster_Recovery', 'Value': 'Full'}, {'Key': 'aws:backup:source-resource', 'Value': 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'}])]
14
message = ""
15
16
for i in snapshots_id:
17
snapshot_id = i[0]
18
message += copy_snapshot_src_to_dst(snapshot_id) + 'n'
19
print(message)
20
send_sns(message)
21
22
def send_sns(message):
23
if sns_arn:
24
print("Sending SNS alert")
25
sns = boto3.client("sns", region_name=region_src)
26
response = sns.publish(
27
TargetArn=sns_arn,
28
Subject=("AWS LAMBDA NOTIFICATION"),
29
Message=(message)
30
)
31
32
33
lambda_handler()
34
Advertisement
Answer
replace 'n'
by ".n"
and after that in an email – each string is in a new line.