Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Latest commit

b89594d · Jul 20, 2023

History

History

powertools-examples-validation

README.md

Lambda Powertools for 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