@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Validation
Validation is used to specify that the annotated method input and/or output needs to be valid.Validation should be used on the RequestHandler.handleRequest(Object, Context)
or RequestStreamHandler.handleRequest(InputStream, OutputStream, Context) methods.
Using the Java language, RequestHandler input and output are already
strongly typed, and if a json event cannot be deserialize to the specified object,
invocation will either fail or retrieve a partial event.
More information in the documentation (java-handler).
But when using built-in types from the
aws-lambda-java-events library,
such as APIGatewayProxyRequestEvent
or SQSEvent,
using the Validation annotation will permit to validate the underlying content,
for example the body of an API Gateway request, or the records body of an SQS event.
Validation has built-in validation for the following input types:
| Type of event | Class | Path to content |
| API Gateway REST | APIGatewayProxyRequestEvent | body |
| API Gateway HTTP | APIGatewayV2HTTPEvent | body |
| Cloudformation Custom Resource | CloudFormationCustomResourceEvent | resourceProperties |
| CloudWatch Logs | CloudWatchLogsEvent | awslogs.powertools_base64_gzip(data) |
| EventBridge / Cloudwatch | ScheduledEvent | detail |
| Kafka | KafkaEvent | records[*][*].value |
| Kinesis | KinesisEvent | Records[*].kinesis.powertools_base64(data) |
| Kinesis Firehose | KinesisFirehoseEvent | Records[*].powertools_base64(data) |
| Kinesis Analytics from Firehose | KinesisAnalyticsFirehoseInputPreprocessingEvent | Records[*].powertools_base64(data) |
| Kinesis Analytics from Streams | KinesisAnalyticsStreamsInputPreprocessingEvent | Records[*].powertools_base64(data) |
| Load Balancer | ApplicationLoadBalancerRequestEvent | body |
| SNS | SNSEvent | Records[*].Sns.Message |
| SQS | SQSEvent | Records[*].body |
Validation has built-in validation for the following output types:
| Type of response | Class | Path to content |
| API Gateway REST | APIGatewayProxyResponseEvent | body |
| API Gateway HTTP | APIGatewayV2HTTPResponse | body |
| API Gateway WebSocket | APIGatewayV2WebSocketResponse | body |
| Load Balancer | ApplicationLoadBalancerResponseEvent | body |
| Kinesis Analytics | KinesisAnalyticsInputPreprocessingResponse | Records[*].powertools_base64(data) |
You can specify either inboundSchema or outboundSchema or both, depending on what you want to validate.
The schema must be passed as a json string (constant), or using the syntax "classpath:/some/path/to/schema.json" ,
provided that the schema.json file is available in the classpath at the specified path.
| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
envelope
path to the subelement
|
java.lang.String |
inboundSchema
schema used to validate the lambda function input
|
java.lang.String |
outboundSchema
schema used to validate the lambda function output
|
com.networknt.schema.SpecVersion.VersionFlag |
schemaVersion
json schema specification version (default is 2019-09)
|
Copyright © 2020. All rights reserved.