Skip to content

Latest commit

 

History

History

powertools-examples-validation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Powertools for AWS Lambda (Java) - Validation Example

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.

Deploy the sample application

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

Test the application

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