Skip to content

Parameter envelope is not taken in consideration in @Validation on requestHandler accepting SQSEvent #959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chihebdaoues opened this issue Oct 25, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@chihebdaoues
Copy link

chihebdaoues commented Oct 25, 2022

My team is trying to use `aws-lambda-powertools' validation utility to validate request/response schemas on a couple of lambda functions we have and we noticed that the envelope parameter is not being taken in consideration when provided.

What were you trying to accomplish?
We have an SQS queue that subscribes to an SNS topic and a lambda function that subscribes to the SQS queue. Which I think is fairly common pattern. I was trying to annotate the request handler with validate to put some validation on the event that originated from the SNS topic schema and as such I needed to use the envelope parameter.

@Validation(inboundSchema = "classpath:/schemas/requestSchema.json", envelope = "records[*].powertools_json(body).powertools_json(Message)")
    public Void requestHandler(SQSEvent event, Context context) {
....

Expected Behavior

I expected the Validation to use the envelope provided, but I think powertools is actually using the envelope for SQSEvents. I was expecting the default behavior to be overridden by the provided envelope.

Current Behavior

Looking at the code in ValidationAspect.java#L108, I see that the provided envelope will be used as the last resort. And since my event is an SQSEvent, it evaluates to true on ValidationAspect.java#L71 and as such my envelope is not being used.

The current behavior is enforcing a one solution fits all for validating all the builtin events.

Possible Solution

Test if the envelope is not empty at the start of the if...else block and if so use it. This would allow the user to override the default behavior which enables clients to customize the validation as they want.

Steps to Reproduce (for bugs)

  1. Create an SNS topic
  2. Subscribe to the topic using an SQS queue
  3. Create a lambda that subscribes to the SQS queue
  4. Try to validate the schema of message that originated from the SNS topic

Environment

  • Powertools version used: 1.12.2
  • Packaging format (Layers, Maven/Gradle): Gradle
  • AWS Lambda function runtime: JAVA11
@chihebdaoues chihebdaoues added the bug Something isn't working label Oct 25, 2022
@jeromevdl
Copy link
Contributor

Hi @chihebdaoues,

Thanks for noticing this. I agree, if the envelope is set, it should take precedence over the defaults.

@msailes
Copy link
Contributor

msailes commented Dec 14, 2022

This is available in v1.13.0

@msailes msailes closed this as completed Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants