This project contains an example of Lambda function using the validation module of Powertools for AWS Lambda (Java). For more information on this module, please refer to the documentation.
The handler InboundValidation validates incoming HTTP requests received from the API gateway against schema.json.
This sample is based on Serverless Application Model (SAM). To deploy it, check out the instructions for getting started with SAM in the examples directory
To test the validation, we can POST a JSON object shaped like our schema:
curl -X POST https://[REST-API-ID].execute-api.[REGION].amazonaws.com/Prod/hello/ -H "Content-Type: application/json" -d '{"address": "https://checkip.amazonaws.com"}'
If we break the schema - for instance, by removing one of the compulsory fields,
we will get an error back from our API and will see a ValidationException
in the logs:
sam logs --tail --stack-name $MY_STACK