Here’s my function under test
def publish_sns(error_object, client: boto3.client = None) -> dict:
"""Publish SNS message"""
client = client or boto3.client('sns')
topic_arn = os.getenv('SNS_TOPIC_ARN', 'some default')
subject = f'Appointments encountered a new error {error.statusCode}'
message = (
f'correlationId: {error.correlationId}, created: {error.created}, statusCode: {error.statusCode}, logEventId: '
f'{error.logEventId}, xrayTraceId: {error.xrayTraceId}'
)
return client.publish(
TopicArn=topic_arn,
Message=message,
Subject=subject,
# I shouldn't need these
MessageAttributes={},
MessageStructure='string',
PhoneNumber='8888888888'
)
Here’s the test:
@moto.mock_aws
def test_sns_publish(error):
client = boto3.client('sns')
result = aws_helpers.publish_sns(error, client)
assert 'MessageId' in result
Without the optional parameters I get the following error:
botocore.errorfactory.InvalidParameterException
An error occurred (InvalidParameter) when calling the Publish operation: not enough values to unpack (expected 6, got 1)