19 from botocore.exceptions
import ClientError
23 HOMECU_SCRIPT_HELP =
'sendAwsSms.py -p <phone number> -s <subject> -m <message> [-t] [-r <region>]' 28 AWS_REGION =
'us-west-2' 41 opts, args = getopt.getopt(argv,
"p:s:m:r:t")
42 except getopt.GetoptError:
43 main_return[
'status'] =
'999' 44 main_return[
'error'] = HOMECU_SCRIPT_HELP
45 print(json.dumps(main_return))
49 missing_subject =
True 50 missing_message =
True 51 arg_transaction =
False 59 missing_subject =
False 62 missing_message =
False 64 arg_transaction =
True 69 if missing_phone
or missing_message
or missing_subject:
70 main_return[
'status'] =
'999' 71 main_return[
'error'] = HOMECU_SCRIPT_HELP
72 print (json.dumps(main_return))
80 if len(arg_phone) != 11
or not arg_phone.isdigit():
81 main_return[
'status'] =
'999' 82 main_return[
'error'] =
"Unsupported phone number" 83 print (json.dumps(main_return))
86 sms_phone_nbr = arg_phone
93 homecu_sms_type =
'Transactional' 95 homecu_sms_type =
'Promotional' 102 client = boto3.client(
'sns', region_name=AWS_REGION)
107 response = client.set_sms_attributes(
109 'DefaultSMSType': homecu_sms_type
115 response = client.publish(
116 PhoneNumber = sms_phone_nbr,
117 Message = sms_message,
118 Subject = sms_subject
120 except Exception
as e:
121 main_return[
'status'] =
'999' 122 main_return[
'error'] = e
123 print (json.dumps(main_return))
127 main_return[
'response'] = response
128 print (json.dumps(main_return));
130 if __name__ ==
"__main__":