File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
examples/powertools-examples-validation Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 3
3
This project contains an example of Lambda function using the validation module of Powertools for AWS Lambda (Java).
4
4
For more information on this module, please refer to the [ documentation] ( https://docs.powertools.aws.dev/lambda-java/utilities/validation/ ) .
5
5
6
+ The handler [ InboundValidation] ( src/main/java/org/demo/validation/InboundValidation.java ) validates incoming HTTP requests
7
+ received from the API gateway against [ schema.json] ( src/main/resources/schema.json ) .
8
+
6
9
## Deploy the sample application
7
10
8
11
This sample is based on Serverless Application Model (SAM). To deploy it, check out the instructions for getting
9
12
started with SAM in [ the examples directory] ( ../README.md )
10
13
11
14
## Test the application
12
15
16
+ To test the validation, we can POST a JSON object shaped like our schema:
17
+ ``` bash
18
+ 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"}'
19
+ ```
20
+
21
+ If we break the schema - for instance, by removing one of the compulsory fields,
22
+ we will get an error back from our API and will see a ` ValidationException ` in the logs:
23
+
24
+ ``` bash
25
+ sam logs --tail --stack-name $MY_STACK
26
+ ```
You can’t perform that action at this time.
0 commit comments