In [11]:
import boto3

rds = boto3.setup_default_session(region_name='us-west-2')
client = boto3.client('sns')
sns = boto3.resource('sns')

# this only needs to be done once when initally defining the topic
# client.create_topic(Name='TEMCA')
topic = sns.Topic('arn:aws:sns:us-west-2:544397524871:test')
response = topic.set_attributes(
   AttributeName='DisplayName',
   AttributeValue='test'
)


---------------------------------------------------------------------------
ClientError                               Traceback (most recent call last)
<ipython-input-11-a05bdac494de> in <module>()
     10 response = topic.set_attributes(
     11    AttributeName='DisplayName',
---> 12    AttributeValue='test'
     13 )

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\boto3\resources\factory.pyc in do_action(self, *args, **kwargs)
    516             # instance via ``self``.
    517             def do_action(self, *args, **kwargs):
--> 518                 response = action(self, *args, **kwargs)
    519 
    520                 if hasattr(self, 'load'):

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\boto3\resources\action.pyc in __call__(self, parent, *args, **kwargs)
     81             operation_name, params)
     82 
---> 83         response = getattr(parent.meta.client, operation_name)(**params)
     84 
     85         logger.debug('Response: %r', response)

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\botocore\client.pyc in _api_call(self, *args, **kwargs)
    256                     "%s() only accepts keyword arguments." % py_operation_name)
    257             # The "self" in this scope is referring to the BaseClient.
--> 258             return self._make_api_call(operation_name, kwargs)
    259 
    260         _api_call.__name__ = str(py_operation_name)

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\botocore\client.pyc in _make_api_call(self, operation_name, api_params)
    546 
    547         if http.status_code >= 300:
--> 548             raise ClientError(parsed_response, operation_name)
    549         else:
    550             return parsed_response

ClientError: An error occurred (InvalidClientTokenId) when calling the SetTopicAttributes operation: The security token included in the request is invalid.

In [ ]:


In [5]:
topic = sns.Topic('arn:aws:sns:us-east-1:544397524871:TEMCA')

In [6]:
topic.subscribe(Protocol='sms', Endpoint='1-971-645-0815')


---------------------------------------------------------------------------
ClientError                               Traceback (most recent call last)
<ipython-input-6-b7a40f99b628> in <module>()
----> 1 topic.subscribe(Protocol='sms', Endpoint='1-971-645-0815')

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\boto3\resources\factory.pyc in do_action(self, *args, **kwargs)
    516             # instance via ``self``.
    517             def do_action(self, *args, **kwargs):
--> 518                 response = action(self, *args, **kwargs)
    519 
    520                 if hasattr(self, 'load'):

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\boto3\resources\action.pyc in __call__(self, parent, *args, **kwargs)
     81             operation_name, params)
     82 
---> 83         response = getattr(parent.meta.client, operation_name)(**params)
     84 
     85         logger.debug('Response: %r', response)

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\botocore\client.pyc in _api_call(self, *args, **kwargs)
    256                     "%s() only accepts keyword arguments." % py_operation_name)
    257             # The "self" in this scope is referring to the BaseClient.
--> 258             return self._make_api_call(operation_name, kwargs)
    259 
    260         _api_call.__name__ = str(py_operation_name)

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\botocore\client.pyc in _make_api_call(self, operation_name, api_params)
    546 
    547         if http.status_code >= 300:
--> 548             raise ClientError(parsed_response, operation_name)
    549         else:
    550             return parsed_response

ClientError: An error occurred (InvalidClientTokenId) when calling the Subscribe operation: The security token included in the request is invalid.

In [7]:
topic.subscribe(Protocol='email', Endpoint ='jayb@alleninstitute.org')


---------------------------------------------------------------------------
ClientError                               Traceback (most recent call last)
<ipython-input-7-b2c9b02ff858> in <module>()
----> 1 topic.subscribe(Protocol='email', Endpoint ='jayb@alleninstitute.org')

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\boto3\resources\factory.pyc in do_action(self, *args, **kwargs)
    516             # instance via ``self``.
    517             def do_action(self, *args, **kwargs):
--> 518                 response = action(self, *args, **kwargs)
    519 
    520                 if hasattr(self, 'load'):

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\boto3\resources\action.pyc in __call__(self, parent, *args, **kwargs)
     81             operation_name, params)
     82 
---> 83         response = getattr(parent.meta.client, operation_name)(**params)
     84 
     85         logger.debug('Response: %r', response)

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\botocore\client.pyc in _api_call(self, *args, **kwargs)
    256                     "%s() only accepts keyword arguments." % py_operation_name)
    257             # The "self" in this scope is referring to the BaseClient.
--> 258             return self._make_api_call(operation_name, kwargs)
    259 
    260         _api_call.__name__ = str(py_operation_name)

C:\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\botocore\client.pyc in _make_api_call(self, operation_name, api_params)
    546 
    547         if http.status_code >= 300:
--> 548             raise ClientError(parsed_response, operation_name)
    549         else:
    550             return parsed_response

ClientError: An error occurred (InvalidClientTokenId) when calling the Subscribe operation: The security token included in the request is invalid.

In [27]:
sns.platform_applications.all()


Out[27]:
sns.platform_applicationsCollection(sns.ServiceResource(), sns.PlatformApplication)

In [34]:
topic.subscriptions.all()


Out[34]:
sns.Topic.subscriptionsCollection(sns.Topic(arn='arn:aws:sns:us-east-1:544397524871:TEMCA'), sns.Subscription)

In [37]:
response = topic.publish(
    Message='Zounds',
    Subject='Zounds'
)

In [ ]: