amazon web services - Boto3 SNS Publish to a wildcard Topic ARN -
background
aws services regional (e.g. us-west-2
, us-east-1
) , boto3 library requires set default region before accessing client or resources. however, documentation here shows can have sns topic arn wildcard substituted region. documentation says:
documentation: amazon simple notification service (amazon sns)
syntax:
arn:aws:sns:region:account-id:topicname arn:aws:sns:region:account-id:topicname:subscriptionid
examples:
arn:aws:sns:*:123456789012:my_corporate_topic arn:aws:sns:us-east-1:123456789012:my_corporate_topic:02034b43-fefa-4e07-a5eb-3be56f8c54ce
code
when use boto3's sns resource/client publish topic arn (that has wildcard region), below error. when don't have wildcard region (e.g. specify us-west-2
), works. looked boto3 library , seems replace values in json mapping (e.g. inserts topic string) don't understand why invalid parameter if documentation above shows it's valid.
import boto3 client = boto3.client('sns', region_name='us-west-2') client.publish(topicarn='arn:aws:sns:*:123456789:some-topic', message='somemessage')
error message
file "/users/wliu/.virtualenvs/myenv/lib/python2.7/site-packages/botocore/client.py", line 548, in _make_api_call raise clienterror(parsed_response, operation_name) clienterror: error occurred (invalidparameter) when calling publish operation: invalid parameter: topicarn reason: * arn must begin arn:null, not arn:aws:sns:*:123456789:my_topic
the documentation not show it's valid context in using it. you're misapplying or misinterpreting documentation, confusing applicability of patterns , literals. publish requires literal, , doesn't mention wildcards in relevant section of docs of underlying api.
you can use wildcards part of resource arn when specifing resource iam policy statement applies, when particular service supports resouce-level policies.
from sns-specific policy language documentation:
for amazon sns, topics resource type can specify in policy. following amazon resource name (arn) format topics.
example
if had topic named my_topic in each of different regions amazon sns supports, specify topics following arn.
arn:aws:sns:*:123456789012:my_topic
http://docs.aws.amazon.com/sns/latest/dg/usingiamwithsns.html#sns_arn_format
however, applicable policies, support patterns arn:aws:sns:*:123456789012:bob_*
, , such pattern (perhaps more intuitively) not valid topic publish
request.
Comments
Post a Comment