Search code examples
pythonboto3amazon-ses

AWS SNS Message format using Boto3


I have set up an SNS notification and can successfully send a list into the message as follows:

sns.publish(TopicArn='arn:aws:sns:eu-xxx-x:1234567:my_sns', Message=f"New URLS are {newUrls}")

This gives the following output in the SNS message:

New URLS are ['http://www.123.bar', 'http://abc.foo', 'http://foo.bar']

How do I structure the output to look like this with new lines and no square brackets for the list: (this is a trivial task in Python but I am struggling to do this with the message parameter)

New URLS are:

http://www.123.bar

http://abc.foo

http://foo.bar

I have tried sending a print function into the message parameter but it returns None


Solution

  • This is how I resolved it:

    newUrlsString = "\n".join(newUrls)
    
    nl = "\n"
    
    sns.publish(TopicArn='arn:aws:sns:eu-xxx-x:1234567:my_sns', Message=f"New URLS are: {nl+newUrlsString}")