简体   繁体   中英

How can I generate AWS SNS alert to trigger MS Teams notification when an object fails to load?

I am trying to generate an SNS alert for MS Teams, and anytime I try to execute the function in Lambda I get the following error... [ERROR] InvalidParameterException: An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: Subject Traceback

Does anyone have any idea where I went wrong or what I can change to generate an MS Teams alert successfully?

def sns_alert(object):
'''Sends SNS Teams alert failed to load object'''
try:
    message = f'{object} failed to load'
    subject = f'{object} failed to load'
    sc = boto3.client(service_name='sns')
    response = sc.publish(
    TopicArn = 'arn:MSTEAMS-SNS-TOPIC', 
    Message = json.dumps({'default': json.dumps(message)}),
    Subject = json.dumps({'default': json.dumps(subject)}),
    MessageStructure = 'json'
    
)
    return response
except Exception as e:
    raise e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM