Skip to content

utilities.parser.models.sns.SnsNotificationModel has incorrect field names #265

Closed
@zlalvani

Description

@zlalvani

What were you trying to accomplish?
Using the @event_parser decorator with an SNS -> SQS -> Lambda invocation

Expected Behavior

The parser's validation succeeds and the lambda invokes successfully

Current Behavior

Pydantic validation on the SnsNotificationModel raises the following errors:

[ERROR] ValidationError: 3 validation errors for SnsNotificationModel
UnsubscribeUrl
  field required (type=value_error.missing)
MessageAttributes
  field required (type=value_error.missing)
SigningCertUrl
  field required (type=value_error.missing)

This is because the URL fields should have URL capitalized, e.g. UnsubscribeURL and the MessageAttributes field isn't always present.

Possible Solution

Update the field names, or use a pydantic alias for backwards compatibility with the current name scheme.

Steps to Reproduce (for bugs)

I defined my own envelope class for SNS -> SQS -> Lambda messages, as seen below:

class SnsSqsEnvelope(BaseEnvelope):

    def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
        parsed_envelope = _SqsModel.parse_obj(data)
        output = []
        for record in parsed_envelope.Records:
            sns_notification = SnsNotificationModel.parse_raw(record.body)
            output.append(self._parse(data=sns_notification.Message, model=model))
        return output
  1. Use the above envelope with @event_parser on a lambda handler function
  2. Subscribe an SQS queue to an SNS topic, and have the queue invoke the lambda
  3. Publish a message to the topic

Environment

  • Powertools version used: 1.9.0
  • Packaging format (Layers, PyPi): pypi
  • AWS Lambda function runtime: 3.8

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions