SNS block send SMS for specific countries

0

Is it possible to block countries for SMS sending in SMS settings (SNS service).

Example - Russia and Belarus

3 Answers
0

Hi,

you can look into SNS subscription filter policies: https://docs.aws.amazon.com/sns/latest/dg/sns-subscription-filter-policies.html.

You could have a filter policy that prevents messages to be forwarded if the a country field is from one of those ones. https://docs.aws.amazon.com/sns/latest/dg/example-filter-policies.html

Hope it helps ;)

profile picture
EXPERT
answered 2 years ago
0

as i know

https://docs.aws.amazon.com/sns/latest/dg/example-filter-policies.html

filter policies can block messages but these filters cannot be used to block messages according to country

but you can implement country-based restrictions in your application code or by using an external service.

example

import phonenumbers

def is_restricted_country(phone_number, restricted_countries):
    parsed_number = phonenumbers.parse(phone_number)
    country_code = phonenumbers.region_code_for_country_code(parsed_number.country_code)
    return country_code in restricted_countries

import boto3

def send_sms(phone_number, message):
    if not is_restricted_country(phone_number, restricted_countries):
        sns_client = boto3.client('sns')
        response = sns_client.publish(
            PhoneNumber=phone_number,
            Message=message
        )
        print(f"SMS sent to {phone_number}. Response: {response}")
    else:
        print(f"SMS not sent. {phone_number} belongs to a restricted country.")

profile picture
EXPERT
answered 2 years ago
0
AWS
DeKi
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions