'Send custom message in SNS via AWS lambda

I managed to send notification from SNS to MS Teams as a webhook. However, I would like to attach my S3 presigned URL in my SNS. How would I do it? Here's the sample code.

    import urllib.parse
    import urllib3
    import boto3
    import logging
    import json
    from datetime import datetime, timedelta

    s3 = boto3.client('s3')

    http = urllib3.PoolManager() 
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    def lambda_handler(event, context):
      bucket = 'bucket_name'
      key = 'key.csv'
      presigned_url = s3.generate_presigned_url('get_object', Params = {'Bucket': 'bucket', 'Key': 'key'}, ExpiresIn = 1800)
    
      url = "www.teams_webhook.com"
      updated_time = (datetime.now() + timedelta(hours=32)).strftime('%d-%m-%Y, %H:%M')
      inform_user = 'Your file is ready to download. This link will expire on :' + updated_time + presigned_url

      message = {
        "text": event['Records'][0]['Sns']['Message']
      }

      encoded_msg = json.dumps(message).encode('utf-8')
      response = http.request('POST', url, body=encoded_msg)
      logger.info('Status Code: {}'.format(response.status))
      logger.info('Response: {}'.format(response.data))



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source