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
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
Import the package
import notification_service.email as email
import notification_service.sms as sms
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)
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), requiredemail
to_addresses
(list of strings), not more than 50 recipients, requiredsubject
(string), max 78 characters, requiredbody_text
(string), max 128 characters, requiredreply_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), requiredsms
phone_number
(string), 10 digit number, US numbers only, requiredmessage
(string), max 128 characters, required
Payload example