RT: Guide: Notification Service

Notification Service Lambda, invoked via Python/boto3

Using the notification_service package

You can also find this documentation from your SDC workstation: https://gitlab.prod.sdc.dot.gov/Commons/notification-service/blob/main/python/README.md

Requirements

  • Python 3

  • boto3

Using the package

  1. Copy the notification_service directory in to the directory with your other Python code

my-research-project-repo/ ├── notification_service/ │ ├── email.py │ └── sms.py ├── README.md ├── raw-data-extraction.py ├── data-processing.py ├── data-analysis.py └── send-notifications.py
  1. Import the package

import notification_service.email as email import notification_service.sms as sms
  1. Email notification example

email_payload = { "addresses": [ # If name is used, then name must use MIME encoded-word syntax # You can also use a simple email addresse email.encode_address(name="John Q. Public", address="john.public@dot.gov"), "john.q.public@dot.gov" ], # Subject longer that 78 characters will be truncated. "subject": "SDC: Demo research_teams_notification_service", # Body text longer than 128 characters will be truncated "body_text": "This is a demo of the research_teams_notification_service." } email_response = email.send(email_payload) print(email_response)
  1. SMS notification example

You can also see the send-notifications.py file for examples.

The notification_service package

The inner workings of the notification_service package expose a few more options when sending email and sms messages.

Request syntax

Send an email

Parameters

  • FunctionName (string), required

    • research_teams_notification_service

  • Payload (JSON formatted string), required

    • type (string), required

      • email

    • to_addresses (list of strings), not more than 50 recipients, required

    • subject (string), max 78 characters, required

    • body_text (string), max 128 characters, required

    • reply_to_addresses (list of strings), required

Payload example

A note on to_addresses and reply_to_addresses

  • The sender name (also known as the friendly name) may contain non-ASCII characters. These characters must be encoded using MIME encoded-word syntax, as described in RFC 2047.

  • If you want to use the friendly name try email.header

Send a text message (SMS)

Parameters

  • FunctionName (string), required

    • research_teams_notification_service

  • Payload (JSON formatted string), required

    • type (string), required

      • sms

    • phone_number (string), 10 digit number, US numbers only, required

    • message (string), max 128 characters, required

Payload example