Python AWS boto moto SNS Invalid Parameter Exception: 'not enough values to unpack (expected 6, got 1)'

I just spent a long time debugging this error I was getting in a unit test using moto to mock out the boto3 SNS client:

botocore.errorfactory.InvalidParameterException: An error occurred
(InvalidParameter) when calling the Publish operation: not enough values to
unpack (expected 6, got 1)

This error comes from the innards of moto, where it splits an ARN on : and assumes there will be six sections to unpack into Python variables there. I was using test_sns_topic_arn as this is just a unit test.

The fix is just to use a realistic ARN structure when using moto in tests, e.g.

arn:aws:sns:us-east-2:123456789012:TestTopic

This took a long time to identify due to there being no explicit validation on the ARN, so there wasn’t a helpful error message to indicate that the problem was related to the ARN being used during unit tests.


Tech mentioned