diff --git a/.github/workflows/maven-build-all.yml b/.github/workflows/maven-build-all.yml new file mode 100644 index 00000000..67c4a611 --- /dev/null +++ b/.github/workflows/maven-build-all.yml @@ -0,0 +1,33 @@ +# This workflow will build all Java packages in this project with Maven (Java 8) + +name: Java CI with Maven + +on: + push: + branches: [ master ] + pull_request: + branches: [ '*' ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + # Install base modules + - name: Build core with Maven + run: mvn -B install --file aws-lambda-java-core/pom.xml + - name: Build events with Maven + run: mvn -B install --file aws-lambda-java-events/pom.xml + + # Package modules that depend on base modules + - name: Build events-sdk-transformer with Maven + run: mvn -B package --file aws-lambda-java-events-sdk-transformer/pom.xml + - name: Build log4j2 with Maven + run: mvn -B package --file aws-lambda-java-log4j2/pom.xml diff --git a/.gitignore b/.gitignore index 32858aad..e7133935 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,10 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# Maven build +target/ + +# IDEA internal +*.iml +.idea diff --git a/README.md b/README.md index f1813df2..57e03ea1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # AWS Lambda Java Support Libraries Interface definitions for Java code running on the AWS Lambda platform. -For issues and questions, you can start with our [FAQ](https://aws.amazon.com/lambda/faqs/) and the [AWS forums](https://forums.aws.amazon.com/forum.jspa?forumID=186) +For issues and questions, you can start with our [FAQ](https://aws.amazon.com/lambda/faqs/) + and the [AWS forums](https://forums.aws.amazon.com/forum.jspa?forumID=186) -To get started writing AWS Lambda functions in Java, check out the [official documentation] (http://docs.aws.amazon.com/lambda/latest/dg/java-gs.html). +To get started writing AWS Lambda functions in Java, check out the [official documentation](http://docs.aws.amazon.com/lambda/latest/dg/java-gs.html). # Disclaimer of use @@ -11,12 +12,13 @@ Each of the supplied packages should be used without modification. Removing dependencies, adding conflicting dependencies, or selectively including classes from the packages can result in unexpected behavior. -# Recent Updates! +# Release Notes -* ### [SQS Support](https://github.com/aws/aws-lambda-java-libs/commit/9a74fdc9d92b5d7f73ae05660090e65cbd098360) -* ### [Kinesis Analytics Support](https://github.com/aws/aws-lambda-java-libs/commit/943352c7f0256afe82773e664e887e1593303508) -* ### [2017 Java Events Update](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events) -* ### [Log4j2 Support](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2) +Check out the per-module release notes: +- [aws-lambda-java-core](aws-lambda-java-core/RELEASE.CHANGELOG.md) +- [aws-lambda-java-events](aws-lambda-java-events/RELEASE.CHANGELOG.md) +- [aws-lambda-java-events-sdk-transformer](aws-lambda-java-events-sdk-transformer/RELEASE.CHANGELOG.md) +- [aws-lambda-java-log4j2](aws-lambda-java-log4j2/RELEASE.CHANGELOG.md) # Where to get packages ___ @@ -27,67 +29,69 @@ ___ com.amazonaws aws-lambda-java-core - 1.1.0 + 1.2.1 com.amazonaws aws-lambda-java-events - 2.2.2 + 3.4.0 com.amazonaws - aws-lambda-java-log4j - 1.0.0 + aws-lambda-java-events-sdk-transformer + 2.0.6 com.amazonaws aws-lambda-java-log4j2 - 1.0.0 + 1.2.0 ``` [Gradle](https://gradle.org) ```groovy -'com.amazonaws:aws-lambda-java-core:1.1.0' -'com.amazonaws:aws-lambda-java-events:2.2.2' -'com.amazonaws:aws-lambda-java-log4j:1.0.0' -'com.amazonaws:aws-lambda-java-log4j2:1.0.0' +'com.amazonaws:aws-lambda-java-core:1.2.1' +'com.amazonaws:aws-lambda-java-events:3.4.0' +'com.amazonaws:aws-lambda-java-events-sdk-transformer:2.0.6' +'com.amazonaws:aws-lambda-java-log4j2:1.2.0' ``` [Leiningen](http://leiningen.org) and [Boot](http://boot-clj.com) ```clojure -[com.amazonaws/aws-lambda-java-core "1.1.0"] -[com.amazonaws/aws-lambda-java-events "2.2.2"] -[com.amazonaws/aws-lambda-java-log4j "1.0.0"] -[com.amazonaws/aws-lambda-java-log4j2 "1.0.0"] +[com.amazonaws/aws-lambda-java-core "1.2.1"] +[com.amazonaws/aws-lambda-java-events "3.4.0"] +[com.amazonaws/aws-lambda-java-events-sdk-transformer "2.0.6"] +[com.amazonaws/aws-lambda-java-log4j2 "1.2.0"] ``` [sbt](http://www.scala-sbt.org) ```scala -"com.amazonaws" % "aws-lambda-java-core" % "1.1.0" -"com.amazonaws" % "aws-lambda-java-events" % "2.2.2" -"com.amazonaws" % "aws-lambda-java-log4j" % "1.0.0" -"com.amazonaws" % "aws-lambda-java-log4j2" % "1.0.0" +"com.amazonaws" % "aws-lambda-java-core" % "1.2.1" +"com.amazonaws" % "aws-lambda-java-events" % "3.4.0" +"com.amazonaws" % "aws-lambda-java-events-sdk-transformer" % "2.0.6" +"com.amazonaws" % "aws-lambda-java-log4j2" % "1.2.0" ``` # Using aws-lambda-java-core -This package defines the Lambda [Context](http://docs.aws.amazon.com/lambda/latest/dg/java-context-object.html) -object as well as [interfaces](http://docs.aws.amazon.com/lambda/latest/dg/java-handler-using-predefined-interfaces.html) that Lambda accepts. +This package defines the Lambda [Context](http://docs.aws.amazon.com/lambda/latest/dg/java-context-object.html) object + as well as [interfaces](http://docs.aws.amazon.com/lambda/latest/dg/java-handler-using-predefined-interfaces.html) that Lambda accepts. # Using aws-lambda-java-events -This package defines [event sources](http://docs.aws.amazon.com/lambda/latest/dg/intro-invocation-modes.html) that AWS Lambda natively accepts. See the [documentation](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events) for more information. +This package defines [event sources](http://docs.aws.amazon.com/lambda/latest/dg/intro-invocation-modes.html) that AWS Lambda natively accepts. +See the [documentation](aws-lambda-java-events/README.md) for more information. -# Using aws-lambda-java-log4j2 +# Using aws-lambda-java-events-sdk-transformer -This package defines the Lambda adapter to use with log4j version 2. See -[documentation](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2) for how to use the adapter. +This package provides helper classes/methods to use alongside `aws-lambda-java-events` in order to transform + Lambda input event model objects into SDK-compatible output model objects. +See the [documentation](aws-lambda-java-events-sdk-transformer/README.md) for more information. -# Using aws-lambda-java-log4j (Not recommended) +# Using aws-lambda-java-log4j2 -This package defines the Lambda adapter to use with log4j version 1. See -the [official documentation](http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-wt-logging-using-log4j) for how to use this adapter. +This package defines the Lambda adapter to use with log4j version 2. +See the [README](aws-lambda-java-log4j2/README.md) or the [official documentation](http://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-wt-logging-using-log4j) for information on how to use the adapter. diff --git a/aws-lambda-java-core/RELEASE.CHANGELOG.md b/aws-lambda-java-core/RELEASE.CHANGELOG.md new file mode 100644 index 00000000..406390d7 --- /dev/null +++ b/aws-lambda-java-core/RELEASE.CHANGELOG.md @@ -0,0 +1,18 @@ +### April 28, 2020 +`1.2.1`: +- Added missing XML namespace declarations to `pom.xml` file ([#97](https://github.com/aws/aws-lambda-java-libs/issues/97)) +- Updated `nexusUrl` in `pom.xml` file ([#108](https://github.com/aws/aws-lambda-java-libs/issues/108)) + +### November 21, 2017 +`1.2.0`: +- Added method to log byte array to `LambdaLogger` + +### October 07, 2015 +`1.1.0`: +- Added `LambdaRuntime` and `LambdaRuntimeInternal` +- Added `getInstallationId()` to `Client` +- Added `getFunctionVersion()` and `getInvokedFunctionArn()` to `Context` + +### June 15, 2015 +`1.0.0`: +- Initial support for java in AWS Lambda diff --git a/aws-lambda-java-core/pom.xml b/aws-lambda-java-core/pom.xml index 7fc787bc..52d2976f 100644 --- a/aws-lambda-java-core/pom.xml +++ b/aws-lambda-java-core/pom.xml @@ -1,9 +1,11 @@ - + 4.0.0 com.amazonaws aws-lambda-java-core - 1.2.0 + 1.2.1 jar AWS Lambda Java Core Library @@ -29,6 +31,11 @@ + + 1.8 + 1.8 + + sonatype-nexus-staging @@ -114,7 +121,7 @@ true sonatype-nexus-staging - https://oss.sonatype.org/ + https://aws.oss.sonatype.org/ false diff --git a/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/Endpoint.java b/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/Endpoint.java new file mode 100644 index 00000000..d2c74c54 --- /dev/null +++ b/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/Endpoint.java @@ -0,0 +1,17 @@ +package com.amazonaws.services.lambda.runtime; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates this the API Gateway endpoint for this Lambda Function. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Endpoint { + + String value(); + +} diff --git a/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/FunctionName.java b/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/FunctionName.java new file mode 100644 index 00000000..e5174607 --- /dev/null +++ b/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/FunctionName.java @@ -0,0 +1,17 @@ +package com.amazonaws.services.lambda.runtime; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that the name of this Lambda Function in the AWS Console. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface FunctionName { + + String value(); + +} diff --git a/aws-lambda-java-events-sdk-transformer/README.md b/aws-lambda-java-events-sdk-transformer/README.md new file mode 100644 index 00000000..da19c996 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/README.md @@ -0,0 +1,115 @@ +# AWS Lambda Java Events SDK Transformer Library + +### About + +Provides helper classes/methods to use alongside `aws-lambda-java-events` in order to transform Lambda input event model + objects into SDK-compatible output model objects + (eg. DynamodbEvent to a List of records writable back to DynamoDB through the AWS DynamoDB SDK v2). + + +### Getting started + +Add the following Apache Maven dependencies to your `pom.xml` file: + +```xml + + + com.amazonaws + aws-lambda-java-events-sdk-transformer + 2.0.8 + + + com.amazonaws + aws-lambda-java-events + 3.6.0 + + +``` + +To use this library as a transformer to the AWS DynamoDB Java SDK v2, also add the following dependency to your `pom.xml` file: + +```xml + + + software.amazon.awssdk + dynamodb + 2.13.18 + + +``` + + +### Example Usage + +To convert a full `DynamodbEvent` object to an SDK v2 compatible `List`: +```java +import com.amazonaws.services.lambda.runtime.events.transformers.DynamodbEventTransformer; + +public class DDBEventProcessor implements RequestHandler { + + public String handleRequest(DynamodbEvent ddbEvent, Context context) { + // Process input event + List convertedRecords = DynamodbEventTransformer.toRecordsV2(ddbEvent); + // Modify records as needed and write back to DynamoDB using the DynamoDB AWS SDK for Java 2.0 + } +} +``` + +To convert a single `DynamodbEvent.DynamodbStreamRecord` object to an SDK v2 compatible `Record`: +```java +import com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbRecordTransformer; + +public class MyClass { + + public void myMethod(DynamodbEvent.DynamodbStreamRecord record) { + // ... + Record convertedRecord = DynamodbRecordTransformer.toRecordV2(record); + // ... + } +} +``` + +To convert a `StreamRecord` object originating from a `DynamodbEvent` to an SDK v2 compatible `StreamRecord`: +```java +import com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbStreamRecordTransformer; + +public class MyClass { + + public void myMethod(StreamRecord streamRecord) { + // ... + software.amazon.awssdk.services.dynamodb.model.StreamRecord convertedStreamRecord = + DynamodbStreamRecordTransformer.toStreamRecordV2(streamRecord); + // ... + } +} +``` + +To convert an `AttributeValue` object originating from a `DynamodbEvent` to an SDK v2 compatible `AttributeValue`: +```java +import com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbAttributeValueTransformer; + +public class MyClass { + + public void myMethod(AttributeValue attributeValue) { + // ... + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValue = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValue); + // ... + } +} +``` + +To convert an `Identity` object originating from a `DynamodbEvent` to an SDK v2 compatible `Identity`: +```java +import com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbIdentityTransformer; + +public class MyClass { + + public void myMethod(Identity identity) { + // ... + software.amazon.awssdk.services.dynamodb.model.Identity convertedIdentity = + DynamodbIdentityTransformer.toIdentityV2(identity); + // ... + } +} +``` \ No newline at end of file diff --git a/aws-lambda-java-events-sdk-transformer/RELEASE.CHANGELOG.md b/aws-lambda-java-events-sdk-transformer/RELEASE.CHANGELOG.md new file mode 100644 index 00000000..3174c0e7 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/RELEASE.CHANGELOG.md @@ -0,0 +1,42 @@ +### November 06, 2020 +`2.0.8`: +- Bumped `aws-lambda-java-events` to version `3.6.0` +- Bumped `junit-jupiter-engine` to version `5.7.0` + +### October 28, 2020 +`2.0.7`: +- Bumped `aws-lambda-java-events` to version `3.5.0` + +### October 07, 2020 +`2.0.6`: +- Fixed NPE when UserIdentity is null ([#169](https://github.com/aws/aws-lambda-java-libs/pull/169)) +- Bumped `aws-lambda-java-events` to version `3.4.0` + +### September 23, 2020 +`2.0.5`: +- Bumped `aws-lambda-java-events` to version `3.3.1` + +### September 14, 2020 +`2.0.4`: +- Bumped `aws-lambda-java-events` to version `3.3.0` + +### August 11, 2020 +`2.0.3`: +- Bumped `aws-lambda-java-events` to version `3.2.0` + +### July 31, 2020 +`2.0.2`: +- Bumped `aws-lambda-java-events` to version `3.1.1` + +### June 15, 2020 +`2.0.1`: +- Fixed NPE when mapping insert/delete events ([#143](https://github.com/aws/aws-lambda-java-libs/pull/143)) + +### May 20, 2020 +`2.0.0`: +- Updated AWS SDK V2 transformers for `DynamodbEvent` to work with `aws-lambda-java-events` versions `3.0.0` and up +- Bumped `software.amazon.awssdk:dynamodb` to version `2.13.18` + +### April 29, 2020 +`1.0.0`: +- Added AWS SDK V2 transformers for `DynamodbEvent` in `aws-lambda-java-events` versions up to and including `2.x` diff --git a/aws-lambda-java-log4j/pom.xml b/aws-lambda-java-events-sdk-transformer/pom.xml similarity index 69% rename from aws-lambda-java-log4j/pom.xml rename to aws-lambda-java-events-sdk-transformer/pom.xml index 006ee39c..1702e9e1 100644 --- a/aws-lambda-java-log4j/pom.xml +++ b/aws-lambda-java-events-sdk-transformer/pom.xml @@ -1,14 +1,18 @@ - + 4.0.0 com.amazonaws - aws-lambda-java-log4j - 1.0.0 + aws-lambda-java-events-sdk-transformer + 2.0.8 jar - AWS Lambda Java Log4j 1.2 Library + AWS Lambda Java Events SDK Transformer Library - Support for using log4j 1.2 with AWS Lambda. + Provides helper classes/methods to use alongside aws-lambda-java-events in order to transform Lambda input event model + objects into SDK-compatible output model objects (eg. DynamodbEvent to a List of records writable back to DynamoDB + through the AWS DynamoDB SDK v2) https://aws.amazon.com/lambda/ @@ -28,18 +32,12 @@ https://aws.amazon.com/ - - - com.amazonaws - aws-lambda-java-core - 1.1.0 - - - log4j - log4j - 1.2.17 - - + + + 1.8 + 1.8 + + sonatype-nexus-staging @@ -47,6 +45,41 @@ + + + software.amazon.awssdk + dynamodb + 2.13.18 + provided + + + com.amazonaws + aws-lambda-java-events + 3.6.0 + provided + + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test + + + + + + + maven-surefire-plugin + 2.22.2 + + + maven-failsafe-plugin + 2.22.2 + + + + dev @@ -125,7 +158,7 @@ true sonatype-nexus-staging - https://oss.sonatype.org/ + https://aws.oss.sonatype.org/ false diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/DynamodbEventTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/DynamodbEventTransformer.java new file mode 100644 index 00000000..c2c81ec5 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/DynamodbEventTransformer.java @@ -0,0 +1,21 @@ +package com.amazonaws.services.lambda.runtime.events.transformers; + +import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; +import com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbRecordTransformer; +import software.amazon.awssdk.services.dynamodb.model.Record; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class DynamodbEventTransformer { + + public static List toRecordsV2(final DynamodbEvent dynamodbEvent) { + return dynamodbEvent + .getRecords() + .stream() + .filter(record -> !Objects.isNull(record)) + .map(DynamodbRecordTransformer::toRecordV2) + .collect(Collectors.toList()); + } +} diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbAttributeValueTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbAttributeValueTransformer.java new file mode 100644 index 00000000..be630727 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbAttributeValueTransformer.java @@ -0,0 +1,84 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.services.dynamodb.model.AttributeValue; + +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class DynamodbAttributeValueTransformer { + + public static AttributeValue toAttributeValueV2(final com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue value) { + if (Objects.nonNull(value.getS())) { + return AttributeValue.builder() + .s(value.getS()) + .build(); + + } else if (Objects.nonNull(value.getSS())) { + return AttributeValue.builder() + .ss(value.getSS()) + .build(); + + } else if (Objects.nonNull(value.getN())) { + return AttributeValue.builder() + .n(value.getN()) + .build(); + + } else if (Objects.nonNull(value.getNS())) { + return AttributeValue.builder() + .ns(value.getNS()) + .build(); + + } else if (Objects.nonNull(value.getB())) { + return AttributeValue.builder() + .b(SdkBytes.fromByteBuffer(value.getB())) + .build(); + + } else if (Objects.nonNull(value.getBS())) { + return AttributeValue.builder() + .bs(value.getBS().stream() + .map(SdkBytes::fromByteBuffer) + .collect(Collectors.toList())) + .build(); + + } else if (Objects.nonNull(value.getBOOL())) { + return AttributeValue.builder() + .bool(value.getBOOL()) + .build(); + + } else if (Objects.nonNull(value.getL())) { + return AttributeValue.builder() + .l(value.getL().stream() + .map(DynamodbAttributeValueTransformer::toAttributeValueV2) + .collect(Collectors.toList())) + .build(); + + } else if (Objects.nonNull(value.getM())) { + return AttributeValue.builder() + .m(toAttributeValueMapV2(value.getM())) + .build(); + + } else if (Objects.nonNull(value.getNULL())) { + return AttributeValue.builder() + .nul(value.getNULL()) + .build(); + + } else { + throw new IllegalArgumentException( + String.format("Unsupported attributeValue type: %s", value)); + } + } + + static Map toAttributeValueMapV2( + final Map attributeValueMap + ) { + return attributeValueMap + .entrySet() + .stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> toAttributeValueV2(entry.getValue()) + )); + } +} diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbIdentityTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbIdentityTransformer.java new file mode 100644 index 00000000..1699286f --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbIdentityTransformer.java @@ -0,0 +1,13 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import software.amazon.awssdk.services.dynamodb.model.Identity; + +public class DynamodbIdentityTransformer { + + public static Identity toIdentityV2(final com.amazonaws.services.lambda.runtime.events.models.dynamodb.Identity identity) { + return Identity.builder() + .principalId(identity.getPrincipalId()) + .type(identity.getType()) + .build(); + } +} diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java new file mode 100644 index 00000000..4f93ca20 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java @@ -0,0 +1,25 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; +import software.amazon.awssdk.services.dynamodb.model.Record; + +public class DynamodbRecordTransformer { + + public static Record toRecordV2(final DynamodbEvent.DynamodbStreamRecord record) { + return Record.builder() + .awsRegion(record.getAwsRegion()) + .dynamodb( + DynamodbStreamRecordTransformer.toStreamRecordV2(record.getDynamodb()) + ) + .eventID(record.getEventID()) + .eventName(record.getEventName()) + .eventSource(record.getEventSource()) + .eventVersion(record.getEventVersion()) + .userIdentity( + record.getUserIdentity() != null + ? DynamodbIdentityTransformer.toIdentityV2(record.getUserIdentity()) + : null + ) + .build(); + } +} diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbStreamRecordTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbStreamRecordTransformer.java new file mode 100644 index 00000000..65985487 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbStreamRecordTransformer.java @@ -0,0 +1,31 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import software.amazon.awssdk.services.dynamodb.model.StreamRecord; + +public class DynamodbStreamRecordTransformer { + + public static StreamRecord toStreamRecordV2(final com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord streamRecord) { + + return StreamRecord.builder() + .approximateCreationDateTime( + streamRecord.getApproximateCreationDateTime().toInstant() + ) + .keys( + DynamodbAttributeValueTransformer.toAttributeValueMapV2(streamRecord.getKeys()) + ) + .newImage( + streamRecord.getNewImage() != null + ? DynamodbAttributeValueTransformer.toAttributeValueMapV2(streamRecord.getNewImage()) + : null + ) + .oldImage( + streamRecord.getOldImage() != null + ? DynamodbAttributeValueTransformer.toAttributeValueMapV2(streamRecord.getOldImage()) + : null + ) + .sequenceNumber(streamRecord.getSequenceNumber()) + .sizeBytes(streamRecord.getSizeBytes()) + .streamViewType(streamRecord.getStreamViewType()) + .build(); + } +} diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/DynamodbEventTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/DynamodbEventTransformerTest.java new file mode 100644 index 00000000..6fedb3fe --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/DynamodbEventTransformerTest.java @@ -0,0 +1,42 @@ +package com.amazonaws.services.lambda.runtime.events.transformers; + +import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.dynamodb.model.Record; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbRecordTransformerTest.record_event; +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbRecordTransformerTest.record_v2; + +public class DynamodbEventTransformerTest { + + private final DynamodbEvent dynamodbEvent; + { + record_event.setEventSourceARN("arn:aws:dynamodb:us-west-2:account-id:table/ExampleTableWithStream/stream/2015-06-27T00:48:05.899"); + dynamodbEvent = new DynamodbEvent(); + dynamodbEvent.setRecords(Collections.singletonList(record_event)); + } + + private final List expectedRecordsV2 = Collections.singletonList(record_v2); + + @Test + public void testDynamodbEventToRecordsV2() { + List convertedRecords = DynamodbEventTransformer.toRecordsV2(dynamodbEvent); + Assertions.assertEquals(expectedRecordsV2, convertedRecords); + } + + @Test + public void testDynamodbEventToRecordsV2_FiltersNullRecords() { + DynamodbEvent event = dynamodbEvent.clone(); + event.setRecords(Arrays.asList(record_event, null)); + Assertions.assertEquals(2, event.getRecords().size()); + + List convertedRecords = DynamodbEventTransformer.toRecordsV2(event); + Assertions.assertEquals(expectedRecordsV2, convertedRecords); + Assertions.assertEquals(1, convertedRecords.size()); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbAttributeValueTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbAttributeValueTransformerTest.java new file mode 100644 index 00000000..e9b3f7b5 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbAttributeValueTransformerTest.java @@ -0,0 +1,317 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.utils.ImmutableMap; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +class DynamodbAttributeValueTransformerTest { + + private static final String valueN = "101"; + private static final List valueNS = Arrays.asList("1", "2", "3"); + private static final String valueS = "SVal"; + private static final List valueSS = Arrays.asList("first", "second", "third"); + private static final ByteBuffer valueB = ByteBuffer.wrap("BVal".getBytes()); + private static final List valueBS = Arrays.asList( + ByteBuffer.wrap("first".getBytes()), + ByteBuffer.wrap("second".getBytes()), + ByteBuffer.wrap("third".getBytes())); + private static final boolean valueBOOL = true; + private static final boolean valueNUL = true; + + private static final String keyM1 = "NestedMapKey1"; + private static final String keyM2 = "NestedMapKey2"; + + //region AttributeValue_event + public static final AttributeValue attributeValueN_event = new AttributeValue().withN(valueN); + public static final AttributeValue attributeValueNS_event = new AttributeValue().withNS(valueNS); + public static final AttributeValue attributeValueS_event = new AttributeValue().withS(valueS); + public static final AttributeValue attributeValueSS_event = new AttributeValue().withSS(valueSS); + public static final AttributeValue attributeValueB_event = new AttributeValue().withB(valueB); + public static final AttributeValue attributeValueBS_event = new AttributeValue().withBS(valueBS); + public static final AttributeValue attributeValueBOOL_event = new AttributeValue().withBOOL(valueBOOL); + public static final AttributeValue attributeValueNUL_event = new AttributeValue().withNULL(valueNUL); + public static final AttributeValue attributeValueM_event = new AttributeValue().withM(ImmutableMap.of( + keyM1, attributeValueN_event, + keyM2, attributeValueS_event + )); + public static final AttributeValue attributeValueL_event = new AttributeValue().withL(Arrays.asList( + attributeValueN_event, + attributeValueNS_event, + attributeValueS_event, + attributeValueSS_event, + attributeValueB_event, + attributeValueBS_event, + attributeValueBOOL_event, + attributeValueNUL_event, + attributeValueM_event, + new AttributeValue().withL(Arrays.asList( + attributeValueN_event, + attributeValueNS_event, + attributeValueS_event, + attributeValueSS_event, + attributeValueB_event, + attributeValueBS_event, + attributeValueBOOL_event, + attributeValueNUL_event, + attributeValueM_event + )) + )); + //endregion + + //region AttributeValue_v2 + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueN_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().n(valueN).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueNS_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().ns(valueNS).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueS_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().s(valueS).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueSS_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().ss(valueSS).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueB_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().b(SdkBytes.fromByteBuffer(valueB)).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueBS_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().bs(valueBS.stream() + .map(SdkBytes::fromByteBuffer) + .collect(Collectors.toList())).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueBOOL_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().bool(valueBOOL).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueNUL_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().nul(valueNUL).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueM_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().m(ImmutableMap.of( + keyM1, attributeValueN_v2, + keyM2, attributeValueS_v2 + )).build(); + public static final software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValueL_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().l(Arrays.asList( + attributeValueN_v2, + attributeValueNS_v2, + attributeValueS_v2, + attributeValueSS_v2, + attributeValueB_v2, + attributeValueBS_v2, + attributeValueBOOL_v2, + attributeValueNUL_v2, + attributeValueM_v2, + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().l(Arrays.asList( + attributeValueN_v2, + attributeValueNS_v2, + attributeValueS_v2, + attributeValueSS_v2, + attributeValueB_v2, + attributeValueBS_v2, + attributeValueBOOL_v2, + attributeValueNUL_v2, + attributeValueM_v2 + )).build() + )).build(); + //endregion + + @Test + public void testToAttributeValueV2_N() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueN = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueN_event); + Assertions.assertEquals(attributeValueN_v2, convertedAttributeValueN); + } + + @Test + public void testToAttributeValueV2_NS() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueNS = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueNS_event); + Assertions.assertEquals(attributeValueNS_v2, convertedAttributeValueNS); + } + + @Test + public void testToAttributeValueV2_S() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueS = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueS_event); + Assertions.assertEquals(attributeValueS_v2, convertedAttributeValueS); + } + + @Test + public void testToAttributeValueV2_SS() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueSS = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueSS_event); + Assertions.assertEquals(attributeValueSS_v2, convertedAttributeValueSS); + } + + @Test + public void testToAttributeValueV2_B() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueB = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueB_event); + Assertions.assertEquals(attributeValueB_v2, convertedAttributeValueB); + } + + @Test + public void testToAttributeValueV2_BS() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueBS = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueBS_event); + Assertions.assertEquals(attributeValueBS_v2, convertedAttributeValueBS); + } + + @Test + public void testToAttributeValueV2_BOOL() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueBOOL = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueBOOL_event); + Assertions.assertEquals(attributeValueBOOL_v2, convertedAttributeValueBOOL); + } + + @Test + public void testToAttributeValueV2_NUL() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueNUL = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueNUL_event); + Assertions.assertEquals(attributeValueNUL_v2, convertedAttributeValueNUL); + } + + @Test + public void testToAttributeValueV2_M() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueM = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueM_event); + Assertions.assertEquals(attributeValueM_v2, convertedAttributeValueM); + } + + @Test + public void testToAttributeValueV2_L() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueL = + DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueL_event); + Assertions.assertEquals(attributeValueL_v2, convertedAttributeValueL); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue()) + ); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull_N() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withN(null)) + ); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull_S() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withS(null)) + ); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull_B() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withB(null)) + ); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull_BOOL() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withBOOL(null)) + ); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull_NUL() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withNULL(null)) + ); + } + + @Test + public void testToAttributeValueV2_IllegalArgumentWhenNull_M() { + Assertions.assertThrows(IllegalArgumentException.class, () -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withM(null)) + ); + } + + @Test + public void testToAttributeValueV2_DoesNotThrowWhenEmpty_NS() { + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withNS()) + ); + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withNS(Collections.emptyList())) + ); + } + + @Test + public void testToAttributeValueV2_DoesNotThrowWhenEmpty_SS() { + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withSS()) + ); + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withSS(Collections.emptyList())) + ); + } + + @Test + public void testToAttributeValueV2_DoesNotThrowWhenEmpty_BS() { + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withBS()) + ); + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withBS(Collections.emptyList())) + ); + } + + @Test + public void testToAttributeValueV2_DoesNotThrowWhenEmpty_L() { + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL()) + ); + Assertions.assertDoesNotThrow(() -> + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL(Collections.emptyList())) + ); + } + + @Test + public void testToAttributeValueV2_EmptyV2ObjectWhenEmpty_NS() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue expectedAttributeValue_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().build(); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withNS())); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withNS(Collections.emptyList()))); + } + + @Test + public void testToAttributeValueV2_EmptyV2ObjectWhenEmpty_SS() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue expectedAttributeValue_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().build(); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withSS())); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withSS(Collections.emptyList()))); + } + + @Test + public void testToAttributeValueV2_EmptyV2ObjectWhenEmpty_BS() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue expectedAttributeValue_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().build(); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withBS())); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withBS(Collections.emptyList()))); + } + + @Test + public void testToAttributeValueV2_EmptyV2ObjectWhenEmpty_L() { + software.amazon.awssdk.services.dynamodb.model.AttributeValue expectedAttributeValue_v2 = + software.amazon.awssdk.services.dynamodb.model.AttributeValue.builder().build(); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL())); + Assertions.assertEquals(expectedAttributeValue_v2, + DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL(Collections.emptyList()))); + } + +} \ No newline at end of file diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbIdentityTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbIdentityTransformerTest.java new file mode 100644 index 00000000..f3781445 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbIdentityTransformerTest.java @@ -0,0 +1,32 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.dynamodb.model.Identity; + +class DynamodbIdentityTransformerTest { + + private static final String principalId = "1234567890"; + private static final String identityType = "type"; + + //region Identity_event + public static final com.amazonaws.services.lambda.runtime.events.models.dynamodb.Identity identity_event = + new com.amazonaws.services.lambda.runtime.events.models.dynamodb.Identity() + .withPrincipalId(principalId) + .withType(identityType); + //endregion + + //region Identity_v2 + public static final Identity identity_v2 = Identity.builder() + .principalId(principalId) + .type(identityType) + .build(); + //endregion + + @Test + public void testToIdentityV2() { + Identity convertedIdentity = DynamodbIdentityTransformer.toIdentityV2(identity_event); + Assertions.assertEquals(identity_v2, convertedIdentity); + } + +} \ No newline at end of file diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java new file mode 100644 index 00000000..3218a856 --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java @@ -0,0 +1,63 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.dynamodb.model.OperationType; +import software.amazon.awssdk.services.dynamodb.model.Record; + +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbIdentityTransformerTest.identity_event; +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbIdentityTransformerTest.identity_v2; +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbStreamRecordTransformerTest.streamRecord_event; +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbStreamRecordTransformerTest.streamRecord_v2; + +public class DynamodbRecordTransformerTest { + + private static final String eventId = "2"; + private static final String eventName = OperationType.MODIFY.toString(); + private static final String eventVersion = "1.0"; + private static final String eventSource = "aws:dynamodb"; + private static final String awsRegion = "us-west-2"; + + //region Record_event + public static final DynamodbEvent.DynamodbStreamRecord record_event = (DynamodbEvent.DynamodbStreamRecord) + new DynamodbEvent.DynamodbStreamRecord() + .withEventID(eventId) + .withEventName(eventName) + .withEventVersion(eventVersion) + .withEventSource(eventSource) + .withAwsRegion(awsRegion) + .withDynamodb(streamRecord_event) + .withUserIdentity(identity_event); + //endregion + + //region Record_v2 + public static final Record record_v2 = + Record.builder() + .eventID(eventId) + .eventName(eventName) + .eventVersion(eventVersion) + .eventSource(eventSource) + .awsRegion(awsRegion) + .dynamodb(streamRecord_v2) + .userIdentity(identity_v2) + .build(); + //endregion + + @Test + public void testToRecordV2() { + Record convertedRecord = DynamodbRecordTransformer.toRecordV2(record_event); + Assertions.assertEquals(record_v2, convertedRecord); + } + + @Test + public void testToRecordV2WhenUserIdentityIsNull() { + DynamodbEvent.DynamodbStreamRecord record = record_event.clone(); + record.setUserIdentity(null); + + Assertions.assertDoesNotThrow(() -> { + DynamodbRecordTransformer.toRecordV2(record); + }); + } + +} \ No newline at end of file diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbStreamRecordTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbStreamRecordTransformerTest.java new file mode 100644 index 00000000..5cd3b01b --- /dev/null +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbStreamRecordTransformerTest.java @@ -0,0 +1,124 @@ +package com.amazonaws.services.lambda.runtime.events.transformers.dynamodb; + +import com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue; +import com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamViewType; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.dynamodb.model.StreamRecord; +import software.amazon.awssdk.utils.ImmutableMap; + +import java.util.Date; + +import static com.amazonaws.services.lambda.runtime.events.transformers.dynamodb.DynamodbAttributeValueTransformerTest.*; + +class DynamodbStreamRecordTransformerTest { + + private static final String keyNK = "Id"; + private static final String keyNSK = "KeyNS"; + + private static final String keySK = "SKey"; + private static final String keySSK = "KeySS"; + + private static final String keyBK = "BKey"; + private static final String keyBSK = "KeyBS"; + + private static final String keyBOOLK = "IsBool"; + private static final String keyNULK = "nil"; + + private static final String keyMK = "MapKey"; + + private static final String keyLK = "LongNum"; + + private static final String oldImageSK = "Message"; + private static final String newImageSK = "Message"; + private static final String streamViewType = StreamViewType.NEW_AND_OLD_IMAGES.toString(); + private static final String sequenceNumber = "222"; + private static final Long sizeBytes = 59L; + private static final Date approximateCreationDateTime = new Date(); + + //region StreamRecord_event + public static final com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord streamRecord_event = + new com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord() + .withKeys(ImmutableMap. builder() + .put(keyNK, attributeValueN_event) + .put(keyNSK, attributeValueNS_event) + .put(keySK, attributeValueS_event) + .put(keySSK, attributeValueSS_event) + .put(keyBK, attributeValueB_event) + .put(keyBSK, attributeValueBS_event) + .put(keyBOOLK, attributeValueBOOL_event) + .put(keyNULK, attributeValueNUL_event) + .put(keyMK, attributeValueM_event) + .put(keyLK, attributeValueL_event) + .build() + ) + .withOldImage(ImmutableMap.of( + oldImageSK, attributeValueS_event, + keyNK, attributeValueN_event + )) + .withNewImage(ImmutableMap.of( + newImageSK, attributeValueS_event, + keyNK, attributeValueN_event + )) + .withStreamViewType(StreamViewType.fromValue(streamViewType)) + .withSequenceNumber(sequenceNumber) + .withSizeBytes(sizeBytes) + .withApproximateCreationDateTime(approximateCreationDateTime); + //endregion + + //region StreamRecord_v2 + public static final StreamRecord streamRecord_v2 = StreamRecord.builder() + .approximateCreationDateTime(approximateCreationDateTime.toInstant()) + .keys(ImmutableMap. builder() + .put(keyNK, attributeValueN_v2) + .put(keyNSK, attributeValueNS_v2) + .put(keySK, attributeValueS_v2) + .put(keySSK, attributeValueSS_v2) + .put(keyBK, attributeValueB_v2) + .put(keyBSK, attributeValueBS_v2) + .put(keyBOOLK, attributeValueBOOL_v2) + .put(keyNULK, attributeValueNUL_v2) + .put(keyMK, attributeValueM_v2) + .put(keyLK, attributeValueL_v2) + .build() + ) + .oldImage(ImmutableMap.of( + oldImageSK, attributeValueS_v2, + keyNK, attributeValueN_v2 + )) + .newImage(ImmutableMap.of( + newImageSK, attributeValueS_v2, + keyNK, attributeValueN_v2 + )) + .sequenceNumber(sequenceNumber) + .sizeBytes(sizeBytes) + .streamViewType(streamViewType) + .build(); + //endregion + + @Test + public void testToStreamRecordV2() { + StreamRecord convertedStreamRecord = DynamodbStreamRecordTransformer.toStreamRecordV2(streamRecord_event); + Assertions.assertEquals(streamRecord_v2, convertedStreamRecord); + } + + @Test + public void testToStreamRecordV2WhenOldImageIsNull() { + com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord streamRecord = streamRecord_event.clone(); + streamRecord.setOldImage(null); + + Assertions.assertDoesNotThrow(() -> { + DynamodbStreamRecordTransformer.toStreamRecordV2(streamRecord); + }); + } + + @Test + public void testToStreamRecordV2WhenNewImageIsNull() { + com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord streamRecord = streamRecord_event.clone(); + streamRecord.setNewImage(null); + + Assertions.assertDoesNotThrow(() -> { + DynamodbStreamRecordTransformer.toStreamRecordV2(streamRecord); + }); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/README.md b/aws-lambda-java-events/README.md index dfdf4354..c81327ba 100644 --- a/aws-lambda-java-events/README.md +++ b/aws-lambda-java-events/README.md @@ -1,37 +1,51 @@ -# AWS Lambda Java Events v2.0 +# AWS Lambda Java Events v3 -### New Event Models Supported -* APIGatewayProxyRequestEvent -* APIGatewayProxyResponseEvent -* CloudFrontEvent -* CloudWatchLogsEvent -* CodeCommitEvent -* IoTButtonEvent -* KinesisFirehoseEvent -* LexEvent -* ScheduledEvent +### Event Models Supported +* `ActiveMQEvent` +* `APIGatewayCustomAuthorizerEvent` +* `APIGatewayProxyRequestEvent` +* `APIGatewayProxyResponseEvent` +* `APIGatewayV2CustomAuthorizerEvent` +* `APIGatewayV2HTTPEvent` +* `APIGatewayV2HTTPResponse` +* `APIGatewayV2WebSocketEvent` +* `APIGatewayV2WebSocketResponse` +* `ApplicationLoadBalancerRequestEvent` +* `ApplicationLoadBalancerResponseEvent` +* `CloudFormationCustomResourceEvent` +* `CloudFrontEvent` +* `CloudWatchLogsEvent` +* `CodeCommitEvent` +* `CognitoEvent` +* `ConfigEvent` +* `ConnectEvent` +* `DynamodbEvent` +* `IoTButtonEvent` +* `KafkaEvent` +* `KinesisAnalyticsFirehoseInputPreprocessingEvent` +* `KinesisAnalyticsInputPreprocessingResponse` +* `KinesisAnalyticsOutputDeliveryEvent` +* `KinesisAnalyticsOutputDeliveryResponse` +* `KinesisAnalyticsStreamsInputPreprocessingEvent` +* `KinesisEvent` +* `KinesisFirehoseEvent` +* `LambdaDestinationEvent` +* `LexEvent` +* `S3BatchEvent` +* `S3BatchResponse` +* `S3Event` +* `ScheduledEvent` +* `SecretsManagerRotationEvent` +* `SimpleIAMPolicyResponse` +* `SNSEvent` +* `SQSEvent` -### New package inclusion model -The old package inclusion model required users to pull unused dependencies into -their package. We have removed this inclusion so that users' jars will be -smaller, which will results in reduced latency times. Customers using older -versions do not need to make any changes to their existing code. +*As of version `3.0.0`, users are no longer required to pull in SDK dependencies in order to use this library.* -The following event models do not require any SDK dependencies -* APIGatewayProxyRequestEvent -* APIGatewayProxyResponseEvent -* CloudFrontEvent -* CloudWatchLogsEvent -* CodeCommitEvent -* CognitoEvent -* ConfigEvent -* IoTButtonEvent -* KinesisFirehoseEvent -* LexEvent -* ScheduledEvent -* SNSEvent -so the dependencies section in the pom.xml file would like this +### Getting Started + +[Maven](https://maven.apache.org) ```xml @@ -39,91 +53,34 @@ so the dependencies section in the pom.xml file would like this com.amazonaws aws-lambda-java-core - 1.1.0 + 1.2.1 com.amazonaws aws-lambda-java-events - 2.2.2 + 3.6.0 ... ``` -#### S3 Event - -For the S3 event the pom would look like this: +[Gradle](https://gradle.org) -```xml - - ... - - com.amazonaws - aws-lambda-java-core - 1.1.0 - - - com.amazonaws - aws-lambda-java-events - 2.2.2 - - - com.amazonaws - aws-java-sdk-s3 - 1.11.163 - - ... - +```groovy +'com.amazonaws:aws-lambda-java-core:1.2.1' +'com.amazonaws:aws-lambda-java-events:3.6.0' ``` -#### Kinesis Event - -For the Kinesis event +[Leiningen](http://leiningen.org) and [Boot](http://boot-clj.com) -```xml - - .... - - com.amazonaws - aws-lambda-java-core - 1.1.0 - - - com.amazonaws - aws-lambda-java-events - 2.2.2 - - - com.amazonaws - aws-java-sdk-kinesis - 1.11.163 - - ... - +```clojure +[com.amazonaws/aws-lambda-java-core "1.2.1"] +[com.amazonaws/aws-lambda-java-events "3.6.0"] ``` -#### Dynamodb Event - -For the Dynamodb event +[sbt](http://www.scala-sbt.org) -```xml - - ... - - com.amazonaws - aws-lambda-java-core - 1.1.0 - - - com.amazonaws - aws-lambda-java-events - 2.2.2 - - - com.amazonaws - aws-java-sdk-dynamodb - 1.11.163 - - ... - +```scala +"com.amazonaws" % "aws-lambda-java-core" % "1.2.1" +"com.amazonaws" % "aws-lambda-java-events" % "3.6.0" ``` diff --git a/aws-lambda-java-events/RELEASE.CHANGELOG.md b/aws-lambda-java-events/RELEASE.CHANGELOG.md new file mode 100644 index 00000000..030f2cfe --- /dev/null +++ b/aws-lambda-java-events/RELEASE.CHANGELOG.md @@ -0,0 +1,170 @@ +### November 06, 2020 +`3.6.0`: +- Added support for Amazon `ActiveMQ` event: ([#185](https://github.com/aws/aws-lambda-java-libs/pull/185)) +- Bumped `junit-jupiter-engine` to version `5.7.0` +- Bumped `lombok` to version `1.18.16` + +### October 28, 2020 +`3.5.0`: +- Added support for S3 Batch events: ([#179](https://github.com/aws/aws-lambda-java-libs/pull/179)) + - `S3BatchEvent` + - `S3BatchResponse` + +### October 07, 2020 +`3.4.0`: +- Added Lambda and IAM authorizers to `APIGatewayV2HTTPEvent` request context ([#167](https://github.com/aws/aws-lambda-java-libs/pull/167)) +- Added support for API Gateway custom authorizer: ([#166](https://github.com/aws/aws-lambda-java-libs/pull/166)) + - `APIGatewayCustomAuthorizerEvent` + - `APIGatewayV2CustomAuthorizerEvent` + - `SimpleIAMPolicyResponse` + +### September 23, 2020 +`3.3.1`: +- Added `multiValueQueryStringParameters` to `ApplicationLoadBalancerRequestEvent` ([#163](https://github.com/aws/aws-lambda-java-libs/pull/163)) + +### September 14, 2020 +`3.3.0`: +- Added support for Secrets Manager Rotation Event ([#130](https://github.com/aws/aws-lambda-java-libs/pull/130)) +- Added support for CloudFormation Custom Resource Event ([#138](https://github.com/aws/aws-lambda-java-libs/pull/138)) +- Added support for Lambda Destination Event ([#139](https://github.com/aws/aws-lambda-java-libs/pull/139)) +- Added support for Amazon Connect Event ([#140](https://github.com/aws/aws-lambda-java-libs/pull/140)) + +### August 11, 2020 +`3.2.0`: +- Added support for Kafka Events ([#154](https://github.com/aws/aws-lambda-java-libs/pull/154)) + +### July 31, 2020 +`3.1.1`: +- Fixed Base64 encoding for ALB and API Gateway HTTP events ([#150](https://github.com/aws/aws-lambda-java-libs/pull/131)) + +### May 20, 2020 +`3.1.0`: +- Added support for Application Load Balancer Target Events ([#131](https://github.com/aws/aws-lambda-java-libs/pull/131)) + - `ApplicationLoadBalancerRequestEvent` + - `ApplicationLoadBalancerResponseEvent` +- Added support for API Gateway HTTP API Events ([#123](https://github.com/aws/aws-lambda-java-libs/pull/123)) + - `APIGatewayV2HTTPEvent` + - `APIGatewayV2HTTPResponse` +- Aliased the existing APIGatewayV2Proxy classes as `APIGatewayV2WebSocketEvent`/`APIGatewayV2WebSocketResponse` ([#125](https://github.com/aws/aws-lambda-java-libs/pull/125)) + +### May 18, 2020 +`3.0.0`: +- Removed AWS SDK v1 dependencies ([#74](https://github.com/aws/aws-lambda-java-libs/issues/74)) + - Copied relevant S3, Kinesis and DynamoDB model classes under namespace `com.amazonaws.services.lambda.runtime.events.models` + - S3: + - `S3EventNotification` + - Kinesis: + - `EncryptionType` + - `Record` + - DynamoDB: + - `AttributeValue` + - `Identity` + - `OperationType` + - `Record` + - `StreamRecord` + - `StreamViewType` + +### May 13, 2020 +`2.2.9`: +- Added field `operationName` to `APIGatewayProxyRequestEvent` ([#126](https://github.com/aws/aws-lambda-java-libs/pull/126)) + +### April 28, 2020 +`2.2.8`: +- Added missing XML namespace declarations to `pom.xml` file ([#97](https://github.com/aws/aws-lambda-java-libs/issues/97)) +- Updated `nexusUrl` in `pom.xml` file ([#108](https://github.com/aws/aws-lambda-java-libs/issues/108)) + +### August 13, 2019 +`2.2.7`: +- Added support for APIGatewayV2 (Web Sockets) ([#92](https://github.com/aws/aws-lambda-java-libs/issues/92)) + - `APIGatewayV2ProxyRequestEvent` + - `APIGatewayV2ProxyResponseEvent` +- Fixed typo in `CognitoEvent` javadoc ([#87](https://github.com/aws/aws-lambda-java-libs/issues/87)) + +### March 11, 2019 +`2.2.6`: +- Added field `customData` to `CommitEvent.Record` ([#79](https://github.com/aws/aws-lambda-java-libs/issues/79)) +- Added field `isBase64Encoded` to `APIGatewayProxyResponseEvent` ([#48](https://github.com/aws/aws-lambda-java-libs/issues/48)) +- Added field `authorizer` to `APIGatewayProxyRequestEvent` ([#77](https://github.com/aws/aws-lambda-java-libs/issues/77)) + +### January 03, 2019 +`2.2.5`: +- Fixed "Paramters" typo in `APIGatewayProxyRequestEvent` and `ConfigEvent` ([#65](https://github.com/aws/aws-lambda-java-libs/issues/65)) + +### November 14, 2018 +`2.2.4`: +- Added default constructor for `S3Event` for easier deserialization + +### November 05, 2018 +`2.2.3`: +- Added support for Multi-Value Headers and Query String Parameters to `APIGatewayProxyRequestEvent` ([#60](https://github.com/aws/aws-lambda-java-libs/issues/60)) + +### July 02, 2018 +`2.2.2`: +- Made `SQSEvent.SQSMessage` default constructor public ([#51](https://github.com/aws/aws-lambda-java-libs/issues/51)) + +### June 29, 2018 +`2.2.1`: +- Made `SQSEvent.SQSMessage` public ([#51](https://github.com/aws/aws-lambda-java-libs/issues/51)) + +### June 28, 2018 +`2.2.0`: +- Added `SQSEvent` + +### March 09, 2018 +`2.1.0`: +- Added Kinesis Analytics events + - `KinesisAnalyticsFirehoseInputPreprocessingEvent` + - `KinesisAnalyticsInputPreprocessingResponse` + - `KinesisAnalyticsOutputDeliveryEvent` + - `KinesisAnalyticsOutputDeliveryResponse` + - `KinesisAnalyticsStreamsInputPreprocessingEvent` + +### November 21, 2017 +`2.0.2`: +- Added missing fields to `APIGatewayProxyRequestEvent` ([#46](https://github.com/aws/aws-lambda-java-libs/issues/46)) + +### October 07, 2017 +`2.0.1`: +- Updated KinesisFirehose event schema. + - `approximateArrivalTimestamp` is now represented as a millisecond epoch instead of an `org.joda.time.DateTime` object. + +### September 20, 2017 +`2.0`: +- Added the following events: + - `APIGatewayProxyRequestEvent` + - `APIGatewayProxyResponseEvent` + - `CloudFrontEvent` + - `CloudWatchLogsEvent` + - `CodeCommitEvent` + - `IoTButtonEvent` + - `KinesisFirehoseEvent` + - `LexEvent` + - `ScheduledEvent` +- Changed dependency management; Users must now supply the SDK package if they are using an event that is connected to an SDK library. + - These events are `S3Event`, `KinesisEvemt`, and `DynamodbEvent`. +- Bumped AWS SDK versions to `1.11.163` + + +### May 16, 2016 +`1.3.0`: +- Bumped AWS SDK versions to `1.11.0` + +### May 16, 2016 +`1.2.1`: +- Bumped AWS SDK versions to `1.10.77` + +### April 22, 2016 +`1.2.0`: +- Added `ConfigEvent` + +### August 21, 2015 +`1.1.0`: +- Added `DynamodbEvent` + +### June 15, 2015 +`1.0.0`: +- Initial support for java in AWS Lambda, includes the following events: + - `CognitoEvent` + - `KinesisEvent` + - `S3Event` + - `SNSEvent` diff --git a/aws-lambda-java-events/pom.xml b/aws-lambda-java-events/pom.xml index e9d915e4..c006d947 100644 --- a/aws-lambda-java-events/pom.xml +++ b/aws-lambda-java-events/pom.xml @@ -1,9 +1,11 @@ - + 4.0.0 - + com.amazonaws aws-lambda-java-events - 2.2.2 + 3.6.0 jar AWS Lambda Java Events Library @@ -29,6 +31,11 @@ + + 1.8 + 1.8 + + sonatype-nexus-staging @@ -42,26 +49,21 @@ joda-time 2.6 + - com.amazonaws - aws-java-sdk-s3 - 1.11.163 - provided - - - com.amazonaws - aws-java-sdk-kinesis - 1.11.163 - provided + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test - com.amazonaws - aws-java-sdk-dynamodb - 1.11.163 + org.projectlombok + lombok + 1.18.16 provided - + dev @@ -140,12 +142,12 @@ true sonatype-nexus-staging - https://oss.sonatype.org/ + https://aws.oss.sonatype.org/ false - + diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayCustomAuthorizerEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayCustomAuthorizerEvent.java new file mode 100644 index 00000000..72883319 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayCustomAuthorizerEvent.java @@ -0,0 +1,59 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * The API Gateway customer authorizer event object as described - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html + * + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class APIGatewayCustomAuthorizerEvent { + + private String version; + private String type; + private String methodArn; + private String identitySource; + private String authorizationToken; + private String resource; + private String path; + private String httpMethod; + private Map headers; + private Map queryStringParameters; + private Map pathParameters; + private Map stageVariables; + private RequestContext requestContext; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class RequestContext { + private String path; + private String accountId; + private String resourceId; + private String stage; + private String requestId; + private Identity identity; + private String resourcePath; + private String httpMethod; + private String apiId; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Identity { + private String apiKey; + private String sourceIp; + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyRequestEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyRequestEvent.java index b827eb47..f9c118ca 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyRequestEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyRequestEvent.java @@ -1,6 +1,7 @@ package com.amazonaws.services.lambda.runtime.events; import java.io.Serializable; +import java.util.List; import java.util.Map; /** @@ -18,8 +19,12 @@ public class APIGatewayProxyRequestEvent implements Serializable, Cloneable { private Map headers; + private Map> multiValueHeaders; + private Map queryStringParameters; + private Map> multiValueQueryStringParameters; + private Map pathParameters; private Map stageVariables; @@ -45,6 +50,8 @@ public static class ProxyRequestContext implements Serializable, Cloneable { private String requestId; + private String operationName; + private RequestIdentity identity; private String resourcePath; @@ -55,6 +62,8 @@ public static class ProxyRequestContext implements Serializable, Cloneable { private String path; + private Map authorizer; + /** * default constructor */ @@ -83,6 +92,14 @@ public ProxyRequestContext withAccountId(String accountId) { return this; } + public Map getAuthorizer() { + return authorizer; + } + + public void setAuthorizer(final Map authorizer) { + this.authorizer = authorizer; + } + /** * @return API Gateway stage name */ @@ -267,6 +284,25 @@ public ProxyRequestContext withPath(String path) { return this; } + /** + * @return The name of the operation being performed + * */ + public String getOperationName() { + return operationName; + } + + /** + * @param operationName The name of the operation being performed + * */ + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + public ProxyRequestContext withOperationName(String operationName) { + this.setOperationName(operationName); + return this; + } + /** * Returns a string representation of this object; useful for testing and debugging. * @@ -295,7 +331,11 @@ public String toString() { if (getApiId() != null) sb.append("apiId: ").append(getApiId()).append(","); if (getPath() != null) - sb.append("path: ").append(getPath()); + sb.append("path: ").append(getPath()).append(","); + if (getAuthorizer() != null) + sb.append("authorizer: ").append(getAuthorizer().toString()); + if (getOperationName() != null) + sb.append("operationName: ").append(getOperationName().toString()); sb.append("}"); return sb.toString(); } @@ -346,6 +386,14 @@ public boolean equals(Object obj) { return false; if (other.getPath() != null && other.getPath().equals(this.getPath()) == false) return false; + if (other.getAuthorizer() == null ^ this.getAuthorizer() == null) + return false; + if (other.getAuthorizer() != null && !other.getAuthorizer().equals(this.getAuthorizer())) + return false; + if (other.getOperationName() == null ^ this.getOperationName() == null) + return false; + if (other.getOperationName() != null && !other.getOperationName().equals(this.getOperationName())) + return false; return true; } @@ -363,6 +411,8 @@ public int hashCode() { hashCode = prime * hashCode + ((getHttpMethod() == null) ? 0 : getHttpMethod().hashCode()); hashCode = prime * hashCode + ((getApiId() == null) ? 0 : getApiId().hashCode()); hashCode = prime * hashCode + ((getPath() == null) ? 0 : getPath().hashCode()); + hashCode = prime * hashCode + ((getAuthorizer() == null) ? 0 : getAuthorizer().hashCode()); + hashCode = prime * hashCode + ((getOperationName() == null) ? 0: getOperationName().hashCode()); return hashCode; } @@ -374,7 +424,6 @@ public ProxyRequestContext clone() { throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone()", e); } } - } public static class RequestIdentity implements Serializable, Cloneable { @@ -914,6 +963,29 @@ public APIGatewayProxyRequestEvent withHeaders(Map headers) { return this; } + /** + * @return The multi value headers sent with the request + */ + public Map> getMultiValueHeaders() { + return multiValueHeaders; + } + + /** + * @param multiValueHeaders The multi value headers sent with the request + */ + public void setMultiValueHeaders(Map> multiValueHeaders) { + this.multiValueHeaders = multiValueHeaders; + } + + /** + * @param multiValueHeaders The multi value headers sent with the request + * @return APIGatewayProxyRequestEvent object + */ + public APIGatewayProxyRequestEvent withMultiValueHeaders(Map> multiValueHeaders) { + this.setMultiValueHeaders(multiValueHeaders); + return this; + } + /** * @return The query string parameters that were part of the request */ @@ -932,11 +1004,42 @@ public void setQueryStringParameters(Map queryStringParameters) * @param queryStringParameters The query string parameters that were part of the request * @return APIGatewayProxyRequestEvent */ - public APIGatewayProxyRequestEvent withQueryStringParamters(Map queryStringParameters) { + public APIGatewayProxyRequestEvent withQueryStringParameters(Map queryStringParameters) { this.setQueryStringParameters(queryStringParameters); return this; } + /** + * @deprecated Because of typo in method's name, use {@link #withQueryStringParameters} instead. + */ + @Deprecated + public APIGatewayProxyRequestEvent withQueryStringParamters(Map queryStringParameters) { + return withQueryStringParameters(queryStringParameters); + } + + /** + * @return The multi value query string parameters that were part of the request + */ + public Map> getMultiValueQueryStringParameters() { + return multiValueQueryStringParameters; + } + + /** + * @param multiValueQueryStringParameters The multi value query string parameters that were part of the request + */ + public void setMultiValueQueryStringParameters(Map> multiValueQueryStringParameters) { + this.multiValueQueryStringParameters = multiValueQueryStringParameters; + } + + /** + * @param multiValueQueryStringParameters The multi value query string parameters that were part of the request + * @return APIGatewayProxyRequestEvent + */ + public APIGatewayProxyRequestEvent withMultiValueQueryStringParameters(Map> multiValueQueryStringParameters) { + this.setMultiValueQueryStringParameters(multiValueQueryStringParameters); + return this; + } + /** * @return The path parameters that were part of the request */ @@ -952,14 +1055,22 @@ public void setPathParameters(Map pathParameters) { } /** - * @param pathParameters The path paramters that were part of the request + * @param pathParameters The path parameters that were part of the request * @return APIGatewayProxyRequestEvent object */ - public APIGatewayProxyRequestEvent withPathParamters(Map pathParameters) { + public APIGatewayProxyRequestEvent withPathParameters(Map pathParameters) { this.setPathParameters(pathParameters); return this; } + /** + * @deprecated Because of typo in method's name, use {@link #withPathParameters} instead. + */ + @Deprecated + public APIGatewayProxyRequestEvent withPathParamters(Map pathParameters) { + return withPathParameters(pathParameters); + } + /** * @return The stage variables defined for the stage in API Gateway */ @@ -1051,7 +1162,7 @@ public APIGatewayProxyRequestEvent withIsBase64Encoded(Boolean isBase64Encoded) this.setIsBase64Encoded(isBase64Encoded); return this; } - + /** * Returns a string representation of this object; useful for testing and debugging. * @@ -1071,8 +1182,12 @@ public String toString() { sb.append("httpMethod: ").append(getHttpMethod()).append(","); if (getHeaders() != null) sb.append("headers: ").append(getHeaders().toString()).append(","); + if (getMultiValueHeaders() != null) + sb.append("multiValueHeaders: ").append(getMultiValueHeaders().toString()).append(","); if (getQueryStringParameters() != null) sb.append("queryStringParameters: ").append(getQueryStringParameters().toString()).append(","); + if (getMultiValueQueryStringParameters() != null) + sb.append("multiValueQueryStringParameters: ").append(getMultiValueQueryStringParameters().toString()).append(","); if (getPathParameters() != null) sb.append("pathParameters: ").append(getPathParameters().toString()).append(","); if (getStageVariables() != null) @@ -1113,10 +1228,18 @@ public boolean equals(Object obj) { return false; if (other.getHeaders() != null && other.getHeaders().equals(this.getHeaders()) == false) return false; + if (other.getMultiValueHeaders() == null ^ this.getMultiValueHeaders() == null) + return false; + if (other.getMultiValueHeaders() != null && other.getMultiValueHeaders().equals(this.getMultiValueHeaders()) == false) + return false; if (other.getQueryStringParameters() == null ^ this.getQueryStringParameters() == null) return false; if (other.getQueryStringParameters() != null && other.getQueryStringParameters().equals(this.getQueryStringParameters()) == false) return false; + if (other.getMultiValueQueryStringParameters() == null ^ this.getMultiValueQueryStringParameters() == null) + return false; + if (other.getMultiValueQueryStringParameters() != null && other.getMultiValueQueryStringParameters().equals(this.getMultiValueQueryStringParameters()) == false) + return false; if (other.getPathParameters() == null ^ this.getPathParameters() == null) return false; if (other.getPathParameters() != null && other.getPathParameters().equals(this.getPathParameters()) == false) @@ -1149,7 +1272,9 @@ public int hashCode() { hashCode = prime * hashCode + ((getPath() == null) ? 0 : getPath().hashCode()); hashCode = prime * hashCode + ((getHttpMethod() == null) ? 0 : getHttpMethod().hashCode()); hashCode = prime * hashCode + ((getHeaders() == null) ? 0 : getHeaders().hashCode()); + hashCode = prime * hashCode + ((getMultiValueHeaders() == null) ? 0 : getMultiValueHeaders().hashCode()); hashCode = prime * hashCode + ((getQueryStringParameters() == null) ? 0 : getQueryStringParameters().hashCode()); + hashCode = prime * hashCode + ((getMultiValueQueryStringParameters() == null) ? 0 : getMultiValueQueryStringParameters().hashCode()); hashCode = prime * hashCode + ((getPathParameters() == null) ? 0 : getPathParameters().hashCode()); hashCode = prime * hashCode + ((getStageVariables() == null) ? 0 : getStageVariables().hashCode()); hashCode = prime * hashCode + ((getRequestContext() == null) ? 0 : getRequestContext().hashCode()); diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyResponseEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyResponseEvent.java index 7a3581b0..da6220bd 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyResponseEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayProxyResponseEvent.java @@ -16,6 +16,8 @@ public class APIGatewayProxyResponseEvent implements Serializable, Cloneable { private String body; + private Boolean isBase64Encoded; + /** * default constructor */ @@ -90,6 +92,29 @@ public APIGatewayProxyResponseEvent withBody(String body) { return this; } + /** + * @return whether the body String is base64 encoded. + */ + public Boolean getIsBase64Encoded() { + return this.isBase64Encoded; + } + + /** + * @param isBase64Encoded Whether the body String is base64 encoded + */ + public void setIsBase64Encoded(Boolean isBase64Encoded) { + this.isBase64Encoded = isBase64Encoded; + } + + /** + * @param isBase64Encoded Whether the body String is base64 encoded + * @return APIGatewayProxyRequestEvent + */ + public APIGatewayProxyResponseEvent withIsBase64Encoded(Boolean isBase64Encoded) { + this.setIsBase64Encoded(isBase64Encoded); + return this; + } + /** * Returns a string representation of this object; useful for testing and debugging. * diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEvent.java new file mode 100644 index 00000000..6abfe051 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEvent.java @@ -0,0 +1,80 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import java.time.Instant; +import java.util.List; +import java.util.Map; + +/** + * The V2 API Gateway customer authorizer event object as described - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html + * + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class APIGatewayV2CustomAuthorizerEvent { + + private String version; + private String type; + private String routeArn; + private List identitySource; + private String routeKey; + private String rawPath; + private String rawQueryString; + private List cookies; + private Map headers; + private Map queryStringParameters; + private RequestContext requestContext; + private Map pathParameters; + private Map stageVariables; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class RequestContext { + + private static DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MMM/yyyy:HH:mm:ss Z"); + + private String accountId; + private String apiId; + private String domainName; + private String domainPrefix; + private Http http; + private String requestId; + private String routeKey; + private String stage; + private String time; + private long timeEpoch; + + public Instant getTimeEpoch() { + return Instant.ofEpochMilli(timeEpoch); + } + + public DateTime getTime() { + return fmt.parseDateTime(time); + } + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class Http { + + private String method; + private String path; + private String protocol; + private String sourceIp; + private String userAgent; + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2HTTPEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2HTTPEvent.java new file mode 100644 index 00000000..20607f6e --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2HTTPEvent.java @@ -0,0 +1,113 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +@AllArgsConstructor +@Builder(setterPrefix = "with") +@Data +@NoArgsConstructor +public class APIGatewayV2HTTPEvent { + private String version; + private String routeKey; + private String rawPath; + private String rawQueryString; + private List cookies; + private Map headers; + private Map queryStringParameters; + private Map pathParameters; + private Map stageVariables; + private String Body; + private boolean isBase64Encoded; + private RequestContext requestContext; + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class RequestContext { + private String routeKey; + private String accountId; + private String stage; + private String apiId; + private String domainName; + private String domainPrefix; + private String time; + private long timeEpoch; + private Http http; + private Authorizer authorizer; + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class Authorizer { + private JWT jwt; + private Map lambda; + private IAM iam; + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class JWT { + private Map claims; + private List scopes; + } + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class Http { + private String method; + private String path; + private String protocol; + private String sourceIp; + private String userAgent; + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class IAM { + private String accessKey; + private String accountId; + private String callerId; + private CognitoIdentity cognitoIdentity; + private String principalOrgId; + private String userArn; + private String userId; + } + + @AllArgsConstructor + @Builder(setterPrefix = "with") + @Data + @NoArgsConstructor + public static class CognitoIdentity { + private List amr; + private String identityId; + private String identityPoolId; + } + } +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2HTTPResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2HTTPResponse.java new file mode 100644 index 00000000..2bd81fad --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2HTTPResponse.java @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +@AllArgsConstructor +@Builder(setterPrefix = "with") +@Data +@NoArgsConstructor +public class APIGatewayV2HTTPResponse { + private int statusCode; + private Map headers; + private Map> multiValueHeaders; + private List cookies; + private String body; + private boolean isBase64Encoded; +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyRequestEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyRequestEvent.java new file mode 100644 index 00000000..c8a64149 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyRequestEvent.java @@ -0,0 +1,11 @@ +package com.amazonaws.services.lambda.runtime.events; + +/** + * @deprecated + * This class is for use with API Gateway WebSockets, and has been renamed explicitly as {@link APIGatewayV2WebSocketEvent} + * To integrate with API Gateway's HTTP API Events, use one of: + * * {@link APIGatewayV2HTTPEvent} (payload version 2.0) + * * {@link APIGatewayProxyRequestEvent} (payload version 1.0) + */ +@Deprecated() +public class APIGatewayV2ProxyRequestEvent extends APIGatewayV2WebSocketEvent {} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyResponseEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyResponseEvent.java new file mode 100644 index 00000000..d920e784 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyResponseEvent.java @@ -0,0 +1,9 @@ +package com.amazonaws.services.lambda.runtime.events; + +/** + * @deprecated + * This class is for responding to API Gateway WebSocket events, and has been renamed explicitly as {@link APIGatewayV2WebSocketResponse} + * To response to API Gateway's HTTP API Events, use {@link APIGatewayV2HTTPResponse} + */ +@Deprecated +public class APIGatewayV2ProxyResponseEvent extends APIGatewayV2WebSocketResponse {} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEvent.java new file mode 100644 index 00000000..43a9966b --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEvent.java @@ -0,0 +1,726 @@ +package com.amazonaws.services.lambda.runtime.events; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author Tim Gustafson + */ +public class APIGatewayV2WebSocketEvent implements Serializable, Cloneable { + + private static final long serialVersionUID = 5695319264103347099L; + + public static class RequestIdentity implements Serializable, Cloneable { + + private static final long serialVersionUID = -3276649362684921217L; + + private String cognitoIdentityPoolId; + private String accountId; + private String cognitoIdentityId; + private String caller; + private String apiKey; + private String sourceIp; + private String cognitoAuthenticationType; + private String cognitoAuthenticationProvider; + private String userArn; + private String userAgent; + private String user; + private String accessKey; + + public String getCognitoIdentityPoolId() { + return cognitoIdentityPoolId; + } + + public void setCognitoIdentityPoolId(String cognitoIdentityPoolId) { + this.cognitoIdentityPoolId = cognitoIdentityPoolId; + } + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public String getCognitoIdentityId() { + return cognitoIdentityId; + } + + public void setCognitoIdentityId(String cognitoIdentityId) { + this.cognitoIdentityId = cognitoIdentityId; + } + + public String getCaller() { + return caller; + } + + public void setCaller(String caller) { + this.caller = caller; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + public String getSourceIp() { + return sourceIp; + } + + public void setSourceIp(String sourceIp) { + this.sourceIp = sourceIp; + } + + public String getCognitoAuthenticationType() { + return cognitoAuthenticationType; + } + + public void setCognitoAuthenticationType(String cognitoAuthenticationType) { + this.cognitoAuthenticationType = cognitoAuthenticationType; + } + + public String getCognitoAuthenticationProvider() { + return cognitoAuthenticationProvider; + } + + public void setCognitoAuthenticationProvider(String cognitoAuthenticationProvider) { + this.cognitoAuthenticationProvider = cognitoAuthenticationProvider; + } + + public String getUserArn() { + return userArn; + } + + public void setUserArn(String userArn) { + this.userArn = userArn; + } + + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 29 * hash + (this.cognitoIdentityPoolId != null ? this.cognitoIdentityPoolId.hashCode() : 0); + hash = 29 * hash + (this.accountId != null ? this.accountId.hashCode() : 0); + hash = 29 * hash + (this.cognitoIdentityId != null ? this.cognitoIdentityId.hashCode() : 0); + hash = 29 * hash + (this.caller != null ? this.caller.hashCode() : 0); + hash = 29 * hash + (this.apiKey != null ? this.apiKey.hashCode() : 0); + hash = 29 * hash + (this.sourceIp != null ? this.sourceIp.hashCode() : 0); + hash = 29 * hash + (this.cognitoAuthenticationType != null ? this.cognitoAuthenticationType.hashCode() : 0); + hash = 29 * hash + (this.cognitoAuthenticationProvider != null ? this.cognitoAuthenticationProvider.hashCode() : 0); + hash = 29 * hash + (this.userArn != null ? this.userArn.hashCode() : 0); + hash = 29 * hash + (this.userAgent != null ? this.userAgent.hashCode() : 0); + hash = 29 * hash + (this.user != null ? this.user.hashCode() : 0); + hash = 29 * hash + (this.accessKey != null ? this.accessKey.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final RequestIdentity other = (RequestIdentity) obj; + if ((this.cognitoIdentityPoolId == null) ? (other.cognitoIdentityPoolId != null) : !this.cognitoIdentityPoolId.equals(other.cognitoIdentityPoolId)) { + return false; + } + if ((this.accountId == null) ? (other.accountId != null) : !this.accountId.equals(other.accountId)) { + return false; + } + if ((this.cognitoIdentityId == null) ? (other.cognitoIdentityId != null) : !this.cognitoIdentityId.equals(other.cognitoIdentityId)) { + return false; + } + if ((this.caller == null) ? (other.caller != null) : !this.caller.equals(other.caller)) { + return false; + } + if ((this.apiKey == null) ? (other.apiKey != null) : !this.apiKey.equals(other.apiKey)) { + return false; + } + if ((this.sourceIp == null) ? (other.sourceIp != null) : !this.sourceIp.equals(other.sourceIp)) { + return false; + } + if ((this.cognitoAuthenticationType == null) ? (other.cognitoAuthenticationType != null) : !this.cognitoAuthenticationType.equals(other.cognitoAuthenticationType)) { + return false; + } + if ((this.cognitoAuthenticationProvider == null) ? (other.cognitoAuthenticationProvider != null) : !this.cognitoAuthenticationProvider.equals(other.cognitoAuthenticationProvider)) { + return false; + } + if ((this.userArn == null) ? (other.userArn != null) : !this.userArn.equals(other.userArn)) { + return false; + } + if ((this.userAgent == null) ? (other.userAgent != null) : !this.userAgent.equals(other.userAgent)) { + return false; + } + if ((this.user == null) ? (other.user != null) : !this.user.equals(other.user)) { + return false; + } + if ((this.accessKey == null) ? (other.accessKey != null) : !this.accessKey.equals(other.accessKey)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "{cognitoIdentityPoolId=" + cognitoIdentityPoolId + + ", accountId=" + accountId + + ", cognitoIdentityId=" + cognitoIdentityId + + ", caller=" + caller + + ", apiKey=" + apiKey + + ", sourceIp=" + sourceIp + + ", cognitoAuthenticationType=" + cognitoAuthenticationType + + ", cognitoAuthenticationProvider=" + cognitoAuthenticationProvider + + ", userArn=" + userArn + + ", userAgent=" + userAgent + + ", user=" + user + + ", accessKey=" + accessKey + + "}"; + } + } + + public static class RequestContext implements Serializable, Cloneable { + + private static final long serialVersionUID = -6641935365992304860L; + + private String accountId; + private String resourceId; + private String stage; + private String requestId; + private RequestIdentity identity; + private String ResourcePath; + private Map authorizer; + private String httpMethod; + private String apiId; + private long connectedAt; + private String connectionId; + private String domainName; + private String error; + private String eventType; + private String extendedRequestId; + private String integrationLatency; + private String messageDirection; + private String messageId; + private String requestTime; + private long requestTimeEpoch; + private String routeKey; + private String status; + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getStage() { + return stage; + } + + public void setStage(String stage) { + this.stage = stage; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public RequestIdentity getIdentity() { + return identity; + } + + public void setIdentity(RequestIdentity identity) { + this.identity = identity; + } + + public String getResourcePath() { + return ResourcePath; + } + + public void setResourcePath(String ResourcePath) { + this.ResourcePath = ResourcePath; + } + + public Map getAuthorizer() { + return authorizer; + } + + public void setAuthorizer(Map authorizer) { + this.authorizer = authorizer; + } + + public String getHttpMethod() { + return httpMethod; + } + + public void setHttpMethod(String httpMethod) { + this.httpMethod = httpMethod; + } + + public String getApiId() { + return apiId; + } + + public void setApiId(String apiId) { + this.apiId = apiId; + } + + public long getConnectedAt() { + return connectedAt; + } + + public void setConnectedAt(long connectedAt) { + this.connectedAt = connectedAt; + } + + public String getConnectionId() { + return connectionId; + } + + public void setConnectionId(String connectionId) { + this.connectionId = connectionId; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public String getExtendedRequestId() { + return extendedRequestId; + } + + public void setExtendedRequestId(String extendedRequestId) { + this.extendedRequestId = extendedRequestId; + } + + public String getIntegrationLatency() { + return integrationLatency; + } + + public void setIntegrationLatency(String integrationLatency) { + this.integrationLatency = integrationLatency; + } + + public String getMessageDirection() { + return messageDirection; + } + + public void setMessageDirection(String messageDirection) { + this.messageDirection = messageDirection; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getRequestTime() { + return requestTime; + } + + public void setRequestTime(String requestTime) { + this.requestTime = requestTime; + } + + public long getRequestTimeEpoch() { + return requestTimeEpoch; + } + + public void setRequestTimeEpoch(long requestTimeEpoch) { + this.requestTimeEpoch = requestTimeEpoch; + } + + public String getRouteKey() { + return routeKey; + } + + public void setRouteKey(String routeKey) { + this.routeKey = routeKey; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 59 * hash + (this.accountId != null ? this.accountId.hashCode() : 0); + hash = 59 * hash + (this.resourceId != null ? this.resourceId.hashCode() : 0); + hash = 59 * hash + (this.stage != null ? this.stage.hashCode() : 0); + hash = 59 * hash + (this.requestId != null ? this.requestId.hashCode() : 0); + hash = 59 * hash + (this.identity != null ? this.identity.hashCode() : 0); + hash = 59 * hash + (this.ResourcePath != null ? this.ResourcePath.hashCode() : 0); + hash = 59 * hash + (this.authorizer != null ? this.authorizer.hashCode() : 0); + hash = 59 * hash + (this.httpMethod != null ? this.httpMethod.hashCode() : 0); + hash = 59 * hash + (this.apiId != null ? this.apiId.hashCode() : 0); + hash = 59 * hash + (int) (this.connectedAt ^ (this.connectedAt >>> 32)); + hash = 59 * hash + (this.connectionId != null ? this.connectionId.hashCode() : 0); + hash = 59 * hash + (this.domainName != null ? this.domainName.hashCode() : 0); + hash = 59 * hash + (this.error != null ? this.error.hashCode() : 0); + hash = 59 * hash + (this.eventType != null ? this.eventType.hashCode() : 0); + hash = 59 * hash + (this.extendedRequestId != null ? this.extendedRequestId.hashCode() : 0); + hash = 59 * hash + (this.integrationLatency != null ? this.integrationLatency.hashCode() : 0); + hash = 59 * hash + (this.messageDirection != null ? this.messageDirection.hashCode() : 0); + hash = 59 * hash + (this.messageId != null ? this.messageId.hashCode() : 0); + hash = 59 * hash + (this.requestTime != null ? this.requestTime.hashCode() : 0); + hash = 59 * hash + (int) (this.requestTimeEpoch ^ (this.requestTimeEpoch >>> 32)); + hash = 59 * hash + (this.routeKey != null ? this.routeKey.hashCode() : 0); + hash = 59 * hash + (this.status != null ? this.status.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return "{accountId=" + accountId + + ", resourceId=" + resourceId + + ", stage=" + stage + + ", requestId=" + requestId + + ", identity=" + identity + + ", ResourcePath=" + ResourcePath + + ", authorizer=" + authorizer + + ", httpMethod=" + httpMethod + + ", apiId=" + apiId + + ", connectedAt=" + connectedAt + + ", connectionId=" + connectionId + + ", domainName=" + domainName + + ", error=" + error + + ", eventType=" + eventType + + ", extendedRequestId=" + extendedRequestId + + ", integrationLatency=" + integrationLatency + + ", messageDirection=" + messageDirection + + ", messageId=" + messageId + + ", requestTime=" + requestTime + + ", requestTimeEpoch=" + requestTimeEpoch + + ", routeKey=" + routeKey + + ", status=" + status + + "}"; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final RequestContext other = (RequestContext) obj; + if (this.connectedAt != other.connectedAt) { + return false; + } + if (this.requestTimeEpoch != other.requestTimeEpoch) { + return false; + } + if ((this.accountId == null) ? (other.accountId != null) : !this.accountId.equals(other.accountId)) { + return false; + } + if ((this.resourceId == null) ? (other.resourceId != null) : !this.resourceId.equals(other.resourceId)) { + return false; + } + if ((this.stage == null) ? (other.stage != null) : !this.stage.equals(other.stage)) { + return false; + } + if ((this.requestId == null) ? (other.requestId != null) : !this.requestId.equals(other.requestId)) { + return false; + } + if ((this.ResourcePath == null) ? (other.ResourcePath != null) : !this.ResourcePath.equals(other.ResourcePath)) { + return false; + } + if ((this.authorizer == null) ? (other.authorizer != null) : !this.authorizer.equals(other.authorizer)) { + return false; + } + if ((this.httpMethod == null) ? (other.httpMethod != null) : !this.httpMethod.equals(other.httpMethod)) { + return false; + } + if ((this.apiId == null) ? (other.apiId != null) : !this.apiId.equals(other.apiId)) { + return false; + } + if ((this.connectionId == null) ? (other.connectionId != null) : !this.connectionId.equals(other.connectionId)) { + return false; + } + if ((this.domainName == null) ? (other.domainName != null) : !this.domainName.equals(other.domainName)) { + return false; + } + if ((this.error == null) ? (other.error != null) : !this.error.equals(other.error)) { + return false; + } + if ((this.eventType == null) ? (other.eventType != null) : !this.eventType.equals(other.eventType)) { + return false; + } + if ((this.extendedRequestId == null) ? (other.extendedRequestId != null) : !this.extendedRequestId.equals(other.extendedRequestId)) { + return false; + } + if ((this.integrationLatency == null) ? (other.integrationLatency != null) : !this.integrationLatency.equals(other.integrationLatency)) { + return false; + } + if ((this.messageDirection == null) ? (other.messageDirection != null) : !this.messageDirection.equals(other.messageDirection)) { + return false; + } + if ((this.messageId == null) ? (other.messageId != null) : !this.messageId.equals(other.messageId)) { + return false; + } + if ((this.requestTime == null) ? (other.requestTime != null) : !this.requestTime.equals(other.requestTime)) { + return false; + } + if ((this.routeKey == null) ? (other.routeKey != null) : !this.routeKey.equals(other.routeKey)) { + return false; + } + if ((this.status == null) ? (other.status != null) : !this.status.equals(other.status)) { + return false; + } + if (this.identity != other.identity && (this.identity == null || !this.identity.equals(other.identity))) { + return false; + } + return true; + } + + } + + private String resource; + private String path; + private String httpMethod; + private Map headers; + private Map> multiValueHeaders; + private Map queryStringParameters; + private Map> multiValueQueryStringParameters; + private Map pathParameters; + private Map stageVariables; + private RequestContext requestContext; + private String body; + private boolean isBase64Encoded = false; + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getHttpMethod() { + return httpMethod; + } + + public void setHttpMethod(String httpMethod) { + this.httpMethod = httpMethod; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public Map> getMultiValueHeaders() { + return multiValueHeaders; + } + + public void setMultiValueHeaders(Map> multiValueHeaders) { + this.multiValueHeaders = multiValueHeaders; + } + + public Map getQueryStringParameters() { + return queryStringParameters; + } + + public void setQueryStringParameters(Map queryStringParameters) { + this.queryStringParameters = queryStringParameters; + } + + public Map> getMultiValueQueryStringParameters() { + return multiValueQueryStringParameters; + } + + public void setMultiValueQueryStringParameters(Map> multiValueQueryStringParameters) { + this.multiValueQueryStringParameters = multiValueQueryStringParameters; + } + + public Map getPathParameters() { + return pathParameters; + } + + public void setPathParameters(Map pathParameters) { + this.pathParameters = pathParameters; + } + + public Map getStageVariables() { + return stageVariables; + } + + public void setStageVariables(Map stageVariables) { + this.stageVariables = stageVariables; + } + + public RequestContext getRequestContext() { + return requestContext; + } + + public void setRequestContext(RequestContext requestContext) { + this.requestContext = requestContext; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public boolean isIsBase64Encoded() { + return isBase64Encoded; + } + + public void setIsBase64Encoded(boolean isBase64Encoded) { + this.isBase64Encoded = isBase64Encoded; + } + + @Override + public int hashCode() { + int hash = 7; + + hash = 43 * hash + Objects.hashCode(this.requestContext); + hash = 43 * hash + Objects.hashCode(this.body); + hash = 43 * hash + (this.isBase64Encoded ? 1 : 0); + + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + final APIGatewayV2WebSocketEvent other = (APIGatewayV2WebSocketEvent) obj; + + if (this.isBase64Encoded != other.isBase64Encoded) { + return false; + } + + if (!Objects.equals(this.body, other.body)) { + return false; + } + + if (!Objects.equals(this.requestContext, other.requestContext)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + + if (requestContext != null) { + sb.append("requestContext: ").append(requestContext).append(","); + } + + if (body != null) { + sb.append("body: ").append(body).append(","); + } + + sb.append("isBase64Encoded: ").append(isBase64Encoded).append(","); + + sb.append("}"); + + return sb.toString(); + } + +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketResponse.java new file mode 100644 index 00000000..87e4284c --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketResponse.java @@ -0,0 +1,110 @@ +package com.amazonaws.services.lambda.runtime.events; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author Tim Gustafson + */ +public class APIGatewayV2WebSocketResponse implements Serializable, Cloneable { + + private static final long serialVersionUID = -5155789062248356200L; + + private boolean isBase64Encoded = false; + private int statusCode; + private Map headers; + private Map multiValueHeaders; + private String body; + + public boolean isIsBase64Encoded() { + return isBase64Encoded; + } + + public void setIsBase64Encoded(boolean isBase64Encoded) { + this.isBase64Encoded = isBase64Encoded; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public Map getMultiValueHeaders() { + return multiValueHeaders; + } + + public void setMultiValueHeaders(Map multiValueHeaders) { + this.multiValueHeaders = multiValueHeaders; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 71 * hash + (this.isBase64Encoded ? 1 : 0); + hash = 71 * hash + this.statusCode; + hash = 71 * hash + (this.headers != null ? this.headers.hashCode() : 0); + hash = 71 * hash + (this.multiValueHeaders != null ? this.multiValueHeaders.hashCode() : 0); + hash = 71 * hash + (this.body != null ? this.body.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final APIGatewayV2WebSocketResponse other = (APIGatewayV2WebSocketResponse) obj; + if (this.isBase64Encoded != other.isBase64Encoded) { + return false; + } + if (this.statusCode != other.statusCode) { + return false; + } + if ((this.body == null) ? (other.body != null) : !this.body.equals(other.body)) { + return false; + } + if (this.headers != other.headers && (this.headers == null || !this.headers.equals(other.headers))) { + return false; + } + if (this.multiValueHeaders != other.multiValueHeaders && (this.multiValueHeaders == null || !this.multiValueHeaders.equals(other.multiValueHeaders))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "{isBase64Encoded=" + isBase64Encoded + + ", statusCode=" + statusCode + + ", headers=" + headers + + ", multiValueHeaders=" + multiValueHeaders + + ", body=" + body + + "}"; + } + +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ActiveMQEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ActiveMQEvent.java new file mode 100644 index 00000000..46791980 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ActiveMQEvent.java @@ -0,0 +1,65 @@ +/* + * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import java.util.List; + +/** +* Represents an Active MQ event sent to Lambda +* Onboarding Amazon MQ as event source to Lambda +*/ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder(setterPrefix = "with") +public class ActiveMQEvent { + private String eventSource; + private String eventSourceArn; + private List messages; + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder(setterPrefix = "with") + public static class ActiveMQMessage { + private String messageID; + private String messageType; + private long timestamp; + private int deliveryMode; + private String correlationID; + private String replyTo; + private Destination destination; + private boolean redelivered; + private String type; + private long expiration; + private int priority; + /** Message data sent to Active MQ broker encooded in Base 64 **/ + private String data; + private long brokerInTime; + private long brokerOutTime; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder(setterPrefix = "with") + public static class Destination { + /** Queue Name **/ + private String physicalName; + } +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java new file mode 100644 index 00000000..e7b33117 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerRequestEvent.java @@ -0,0 +1,48 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * Class to represent the request event from Application Load Balancer. + * + * @see Using AWS Lambda with an Application Load Balancer + * + * @author msailes + */ + +@NoArgsConstructor +@Data +public class ApplicationLoadBalancerRequestEvent implements Serializable, Cloneable { + + @NoArgsConstructor + @Data + public static class Elb implements Serializable, Cloneable { + + private String targetGroupArn; + + } + + @NoArgsConstructor + @Data + public static class RequestContext implements Serializable, Cloneable { + + private Elb elb; + + } + + private RequestContext requestContext; + private String httpMethod; + private String path; + private Map queryStringParameters; + private Map> multiValueQueryStringParameters; + private Map headers; + private Map> multiValueHeaders; + private String body; + private boolean isBase64Encoded; + +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerResponseEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerResponseEvent.java new file mode 100644 index 00000000..135de143 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ApplicationLoadBalancerResponseEvent.java @@ -0,0 +1,29 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * Class to represent the response event to Application Load Balancer. + * + * @see Using AWS Lambda with an Application Load Balancer + * + * @author msailes + */ + +@NoArgsConstructor +@Data +public class ApplicationLoadBalancerResponseEvent implements Serializable, Cloneable { + + private int statusCode; + private String statusDescription; + private boolean isBase64Encoded; + private Map headers; + private Map> multiValueHeaders; + private String body; + +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CloudFormationCustomResourceEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CloudFormationCustomResourceEvent.java new file mode 100644 index 00000000..37c00a90 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CloudFormationCustomResourceEvent.java @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Map; + +/** + * Class to represent the custom resource request event from CloudFormation. + * + * CloudFormation invokes your Lambda function asynchronously with this event and includes a callback URL. The function + * is responsible for returning a response to the callback URL that indicates success or failure. + * + * @see Using AWS Lambda with AWS CloudFormation + * + * @author msailes + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class CloudFormationCustomResourceEvent implements Serializable, Cloneable { + + private String requestType; + private String serviceToken; + private String responseUrl; + private String stackId; + private String requestId; + private String logicalResourceId; + private String physicalResourceId; + private String resourceType; + private Map resourceProperties; + private Map oldResourceProperties; +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CodeCommitEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CodeCommitEvent.java index cd12ffdc..d76cba29 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CodeCommitEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CodeCommitEvent.java @@ -290,6 +290,8 @@ public static class Record implements Serializable, Cloneable { private String awsRegion; + private String customData; + private Integer eventTotalParts; /** @@ -596,6 +598,27 @@ public Record withEventTotalParts(Integer eventTotalParts) { return this; } + /** + * + * @return custom data + */ + public String getCustomData(){ return this.customData;} + + /** + * + * @param customData event custom data + */ + public void setCustomData(String customData) { this.customData = customData;} + + /** + * @param customData event + * @return Record + */ + public Record withCustomData(String customData) { + setCustomData(customData); + return this; + } + /** * Returns a string representation of this object; useful for testing and debugging. * @@ -631,6 +654,8 @@ public String toString() { sb.append("eventSource: ").append(getEventSource()).append(","); if (getAwsRegion() != null) sb.append("awsRegion: ").append(getAwsRegion()).append(","); + if (getCustomData() != null) + sb.append("customData: ").append(getCustomData()).append(","); if (getEventTotalParts() != null) sb.append("eventTotalParts: ").append(getEventTotalParts()); sb.append("}"); @@ -699,6 +724,10 @@ public boolean equals(Object obj) { return false; if (other.getEventTotalParts() != null && other.getEventTotalParts().equals(this.getEventTotalParts()) == false) return false; + if (other.getCustomData() == null ^ this.getCustomData() == null) + return false; + if (other.getCustomData() != null && other.getCustomData().equals(this.getCustomData()) == false) + return false; return true; } @@ -720,6 +749,7 @@ public int hashCode() { hashCode = prime * hashCode + ((getEventSource() == null) ? 0 : getEventSource().hashCode()); hashCode = prime * hashCode + ((getAwsRegion() == null) ? 0 : getAwsRegion().hashCode()); hashCode = prime * hashCode + ((getEventTotalParts() == null) ? 0 : getEventTotalParts().hashCode()); + hashCode = prime * hashCode + ((getCustomData() == null) ? 0 : getCustomData().hashCode()); return hashCode; } diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CognitoEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CognitoEvent.java index d250dc17..452d3d6f 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CognitoEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/CognitoEvent.java @@ -18,7 +18,7 @@ /** * - * Represents an Amazon Congnito event sent to Lambda Functions + * Represents an Amazon Cognito event sent to Lambda Functions * */ public class CognitoEvent implements Serializable, Cloneable { diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConfigEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConfigEvent.java index 303f94fe..b2bb9b00 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConfigEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConfigEvent.java @@ -114,7 +114,7 @@ public void setRuleParameters(String ruleParameters) { } /** - * @param ruleParameters String with rule paramters + * @param ruleParameters String with rule parameters * @return ConfigEvent */ public ConfigEvent withRuleParameters(String ruleParameters) { diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConnectEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConnectEvent.java new file mode 100644 index 00000000..38547ac2 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ConnectEvent.java @@ -0,0 +1,83 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Map; + +/** + * Class to represent an Amazon Connect contact flow event. + * + * @see parameters; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class ContactData implements Serializable, Cloneable { + private Map attributes; + private String channel; + private String contactId; + private CustomerEndpoint customerEndpoint; + private String initialContactId; + private String initiationMethod; + private String instanceArn; + private String previousContactId; + private String queue; + private SystemEndpoint systemEndpoint; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class CustomerEndpoint implements Serializable, Cloneable { + private String address; + private String type; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class SystemEndpoint implements Serializable, Cloneable { + private String address; + private String type; + } +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/DynamodbEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/DynamodbEvent.java index 6853e381..353f587f 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/DynamodbEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/DynamodbEvent.java @@ -1,9 +1,17 @@ -/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ - +/* + * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ package com.amazonaws.services.lambda.runtime.events; -import com.amazonaws.services.dynamodbv2.model.Record; - import java.io.Serializable; import java.util.List; @@ -19,7 +27,7 @@ public class DynamodbEvent implements Serializable, Cloneable { /** * The unit of data of an Amazon DynamoDB event */ - public static class DynamodbStreamRecord extends Record { + public static class DynamodbStreamRecord extends com.amazonaws.services.lambda.runtime.events.models.dynamodb.Record { private static final long serialVersionUID = 3638381544604354963L; @@ -52,7 +60,7 @@ public void setEventSourceARN(String eventSourceARN) { * * @return A string representation of this object. * - * @see java.lang.Object#toString() + * @see Object#toString() */ @Override public String toString() { diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KafkaEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KafkaEvent.java new file mode 100644 index 00000000..ed5c2ac8 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KafkaEvent.java @@ -0,0 +1,60 @@ +/* + * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import java.util.List; +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder(setterPrefix = "with") +/** Represents a Kafka Event. **/ +public class KafkaEvent { + private Map> records; + private String eventSource; + private String eventSourceArn; + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder(setterPrefix = "with") + public static class KafkaEventRecord { + private String topic; + private int partition; + private long offset; + private long timestamp; + private String timestampType; + private String key; + private String value; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder(setterPrefix = "with") + public static class TopicPartition { + private String topic; + private int partition; + + @Override + public String toString() { + //Kafka also uses '-' for toString() + return topic + "-" + partition; + } + } +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KinesisEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KinesisEvent.java index 6d1e5300..d3c44e5b 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KinesisEvent.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/KinesisEvent.java @@ -1,6 +1,17 @@ -/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ - +/* + * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ package com.amazonaws.services.lambda.runtime.events; + import java.io.Serializable; import java.util.List; @@ -16,7 +27,7 @@ public class KinesisEvent implements Serializable, Cloneable { /** * The unit of data of an Amazon Kinesis stream */ - public static class Record extends com.amazonaws.services.kinesis.model.Record { + public static class Record extends com.amazonaws.services.lambda.runtime.events.models.kinesis.Record { private static final long serialVersionUID = 7856672931457425976L; @@ -49,7 +60,7 @@ public void setKinesisSchemaVersion(String kinesisSchemaVersion) { * * @return A string representation of this object. * - * @see java.lang.Object#toString() + * @see Object#toString() */ @Override public String toString() { @@ -109,7 +120,7 @@ public boolean equals(Object obj) { } /* (non-Javadoc) - * @see com.amazonaws.services.kinesis.model.Record#hashCode() + * @see com.amazonaws.services.lambda.runtime.events.models.kinesis.Record#hashCode() */ @Override public int hashCode() { @@ -288,7 +299,7 @@ public void setAwsRegion(String awsRegion) { * * @return A string representation of this object. * - * @see java.lang.Object#toString() + * @see Object#toString() */ @Override public String toString() { @@ -413,7 +424,7 @@ public void setRecords(List records) { * * @return A string representation of this object. * - * @see java.lang.Object#toString() + * @see Object#toString() */ @Override public String toString() { diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaDestinationEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaDestinationEvent.java new file mode 100644 index 00000000..eaa4611f --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/LambdaDestinationEvent.java @@ -0,0 +1,55 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.joda.time.DateTime; + +import java.io.Serializable; +import java.util.Map; + +/** + * Class to represent an invocation record for a Lambda event. + * + * @see requestPayload; + private Object responseContext; + private Object responsePayload; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class RequestContext implements Serializable, Cloneable { + private String requestId; + private String functionArn; + private String condition; + private int approximateInvokeCount; + } +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchEvent.java new file mode 100644 index 00000000..a3e8d682 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchEvent.java @@ -0,0 +1,48 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Event to represent the payload which is sent to Lambda by S3 Batch to perform a custom + * action. + * + * https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class S3BatchEvent { + + private String invocationSchemaVersion; + private String invocationId; + private Job job; + private List tasks; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Job { + + private String id; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Task { + + private String taskId; + private String s3Key; + private String s3VersionId; + private String s3BucketArn; + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java new file mode 100644 index 00000000..4fdd1273 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java @@ -0,0 +1,65 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Event to represent the response which should be returned as part of a S3 Batch custom + * action. + * + * https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class S3BatchResponse { + + private String invocationSchemaVersion; + private ResultCode treatMissingKeysAs; + private String invocationId; + private List results; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Result { + + private String taskId; + private ResultCode resultCode; + private String resultString; + } + + public enum ResultCode { + + /** + * The task completed normally. If you requested a job completion report, + * the task's result string is included in the report. + */ + Succeeded, + /** + * The task suffered a temporary failure and will be redriven before the job + * completes. The result string is ignored. If this is the final redrive, + * the error message is included in the final report. + */ + TemporaryFailure, + /** + * The task suffered a permanent failure. If you requested a job-completion + * report, the task is marked as Failed and includes the error message + * string. Result strings from failed tasks are ignored. + */ + PermanentFailure + } + + public static S3BatchResponseBuilder fromS3BatchEvent(S3BatchEvent s3BatchEvent) { + return S3BatchResponse.builder() + .withInvocationId(s3BatchEvent.getInvocationId()) + .withInvocationSchemaVersion(s3BatchEvent.getInvocationSchemaVersion()); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3Event.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3Event.java index 4ceeb5dd..a51acf7c 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3Event.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3Event.java @@ -1,10 +1,21 @@ -/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ - +/* + * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ package com.amazonaws.services.lambda.runtime.events; -import com.amazonaws.services.s3.event.S3EventNotification; +import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; /** @@ -15,11 +26,19 @@ public class S3Event extends S3EventNotification implements Serializable, Clonea private static final long serialVersionUID = -8094860465750962044L; + /** + * default constructor + * (Not available in v1) + */ + public S3Event() { + super(new ArrayList()); + } + /** * Create a new instance of S3Event * @param records A list of S3 event notification records */ - public S3Event(List records) { + public S3Event(List records) { super(records); } diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SecretsManagerRotationEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SecretsManagerRotationEvent.java new file mode 100644 index 00000000..4634c515 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SecretsManagerRotationEvent.java @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Class to represent the events which are sent during a Secrets Manager rotation process. + * + * @see Rotating secrets lambda function overview + * + * @author msailes + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class SecretsManagerRotationEvent { + + private String step; + private String secretId; + private String clientRequestToken; + +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SimpleIAMPolicyResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SimpleIAMPolicyResponse.java new file mode 100644 index 00000000..030a1468 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SimpleIAMPolicyResponse.java @@ -0,0 +1,23 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * The simplified IAM Policy response object as described in https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html + * + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class SimpleIAMPolicyResponse { + + private boolean isAuthorized; + private Map context; +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/AttributeValue.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/AttributeValue.java new file mode 100644 index 00000000..555b42f8 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/AttributeValue.java @@ -0,0 +1,1111 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.dynamodb; + +import java.io.Serializable; + +/** + *

+ * Represents the data for an attribute. + *

+ *

+ * Each attribute value is described as a name-value pair. The name is the data type, and the value is the data itself. + *

+ *

+ * For more information, see Data Types in the Amazon DynamoDB Developer Guide. + *

+ * + * @see AWS API + * Documentation + */ +public class AttributeValue implements Serializable, Cloneable { + + /** + *

+ * An attribute of type String. For example: + *

+ *

+ * "S": "Hello" + *

+ */ + private String s; + /** + *

+ * An attribute of type Number. For example: + *

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ */ + private String n; + /** + *

+ * An attribute of type Binary. For example: + *

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + *

+ */ + private java.nio.ByteBuffer b; + /** + *

+ * An attribute of type String Set. For example: + *

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + *

+ */ + private java.util.List sS; + /** + *

+ * An attribute of type Number Set. For example: + *

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ */ + private java.util.List nS; + /** + *

+ * An attribute of type Binary Set. For example: + *

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + *

+ */ + private java.util.List bS; + /** + *

+ * An attribute of type Map. For example: + *

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + *

+ */ + private java.util.Map m; + /** + *

+ * An attribute of type List. For example: + *

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + *

+ */ + private java.util.List l; + /** + *

+ * An attribute of type Null. For example: + *

+ *

+ * "NULL": true + *

+ */ + private Boolean nULLValue; + /** + *

+ * An attribute of type Boolean. For example: + *

+ *

+ * "BOOL": true + *

+ */ + private Boolean bOOL; + + /** + * Default constructor for DynamodbAttributeValue object. Callers should use the setter or fluent setter (with...) methods + * to initialize the object after creating it. + */ + public AttributeValue() { + } + + /** + * Constructs a new DynamodbAttributeValue object. Callers should use the setter or fluent setter (with...) methods to + * initialize any additional object members. + * + * @param s + * An attribute of type String. For example:

+ *

+ * "S": "Hello" + */ + public AttributeValue(String s) { + setS(s); + } + + /** + * Constructs a new DynamodbAttributeValue object. Callers should use the setter or fluent setter (with...) methods to + * initialize any additional object members. + * + * @param sS + * An attribute of type String Set. For example:

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + */ + public AttributeValue(java.util.List sS) { + setSS(sS); + } + + /** + *

+ * An attribute of type String. For example: + *

+ *

+ * "S": "Hello" + *

+ * + * @param s + * An attribute of type String. For example:

+ *

+ * "S": "Hello" + */ + + public void setS(String s) { + this.s = s; + } + + /** + *

+ * An attribute of type String. For example: + *

+ *

+ * "S": "Hello" + *

+ * + * @return An attribute of type String. For example:

+ *

+ * "S": "Hello" + */ + + public String getS() { + return this.s; + } + + /** + *

+ * An attribute of type String. For example: + *

+ *

+ * "S": "Hello" + *

+ * + * @param s + * An attribute of type String. For example:

+ *

+ * "S": "Hello" + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withS(String s) { + setS(s); + return this; + } + + /** + *

+ * An attribute of type Number. For example: + *

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ * + * @param n + * An attribute of type Number. For example:

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + */ + + public void setN(String n) { + this.n = n; + } + + /** + *

+ * An attribute of type Number. For example: + *

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ * + * @return An attribute of type Number. For example:

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages + * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + */ + + public String getN() { + return this.n; + } + + /** + *

+ * An attribute of type Number. For example: + *

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ * + * @param n + * An attribute of type Number. For example:

+ *

+ * "N": "123.45" + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withN(String n) { + setN(n); + return this; + } + + /** + *

+ * An attribute of type Binary. For example: + *

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + *

+ *

+ * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. + * Users of the SDK should not perform Base64 encoding on this field. + *

+ *

+ * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will + * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or + * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future + * major version of the SDK. + *

+ * + * @param b + * An attribute of type Binary. For example:

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + */ + + public void setB(java.nio.ByteBuffer b) { + this.b = b; + } + + /** + *

+ * An attribute of type Binary. For example: + *

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + *

+ *

+ * {@code ByteBuffer}s are stateful. Calling their {@code get} methods changes their {@code position}. We recommend + * using {@link java.nio.ByteBuffer#asReadOnlyBuffer()} to create a read-only view of the buffer with an independent + * {@code position}, and calling {@code get} methods on this rather than directly on the returned {@code ByteBuffer}. + * Doing so will ensure that anyone else using the {@code ByteBuffer} will not be affected by changes to the + * {@code position}. + *

+ * + * @return An attribute of type Binary. For example:

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + */ + + public java.nio.ByteBuffer getB() { + return this.b; + } + + /** + *

+ * An attribute of type Binary. For example: + *

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + *

+ *

+ * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. + * Users of the SDK should not perform Base64 encoding on this field. + *

+ *

+ * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will + * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or + * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future + * major version of the SDK. + *

+ * + * @param b + * An attribute of type Binary. For example:

+ *

+ * "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withB(java.nio.ByteBuffer b) { + setB(b); + return this; + } + + /** + *

+ * An attribute of type String Set. For example: + *

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + *

+ * + * @return An attribute of type String Set. For example:

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + */ + + public java.util.List getSS() { + return sS; + } + + /** + *

+ * An attribute of type String Set. For example: + *

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + *

+ * + * @param sS + * An attribute of type String Set. For example:

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + */ + + public void setSS(java.util.Collection sS) { + if (sS == null) { + this.sS = null; + return; + } + + this.sS = new java.util.ArrayList(sS); + } + + /** + *

+ * An attribute of type String Set. For example: + *

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + *

+ *

+ * NOTE: This method appends the values to the existing list (if any). Use + * {@link #setSS(java.util.Collection)} or {@link #withSS(java.util.Collection)} if you want to override the + * existing values. + *

+ * + * @param sS + * An attribute of type String Set. For example:

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withSS(String... sS) { + if (this.sS == null) { + setSS(new java.util.ArrayList(sS.length)); + } + for (String ele : sS) { + this.sS.add(ele); + } + return this; + } + + /** + *

+ * An attribute of type String Set. For example: + *

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + *

+ * + * @param sS + * An attribute of type String Set. For example:

+ *

+ * "SS": ["Giraffe", "Hippo" ,"Zebra"] + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withSS(java.util.Collection sS) { + setSS(sS); + return this; + } + + /** + *

+ * An attribute of type Number Set. For example: + *

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ * + * @return An attribute of type Number Set. For example:

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages + * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + */ + + public java.util.List getNS() { + return nS; + } + + /** + *

+ * An attribute of type Number Set. For example: + *

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ * + * @param nS + * An attribute of type Number Set. For example:

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + */ + + public void setNS(java.util.Collection nS) { + if (nS == null) { + this.nS = null; + return; + } + + this.nS = new java.util.ArrayList(nS); + } + + /** + *

+ * An attribute of type Number Set. For example: + *

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ *

+ * NOTE: This method appends the values to the existing list (if any). Use + * {@link #setNS(java.util.Collection)} or {@link #withNS(java.util.Collection)} if you want to override the + * existing values. + *

+ * + * @param nS + * An attribute of type Number Set. For example:

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withNS(String... nS) { + if (this.nS == null) { + setNS(new java.util.ArrayList(nS.length)); + } + for (String ele : nS) { + this.nS.add(ele); + } + return this; + } + + /** + *

+ * An attribute of type Number Set. For example: + *

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + *

+ * + * @param nS + * An attribute of type Number Set. For example:

+ *

+ * "NS": ["42.2", "-19", "7.5", "3.14"] + *

+ *

+ * Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and + * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withNS(java.util.Collection nS) { + setNS(nS); + return this; + } + + /** + *

+ * An attribute of type Binary Set. For example: + *

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + *

+ * + * @return An attribute of type Binary Set. For example:

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + */ + + public java.util.List getBS() { + return bS; + } + + /** + *

+ * An attribute of type Binary Set. For example: + *

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + *

+ * + * @param bS + * An attribute of type Binary Set. For example:

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + */ + + public void setBS(java.util.Collection bS) { + if (bS == null) { + this.bS = null; + return; + } + + this.bS = new java.util.ArrayList(bS); + } + + /** + *

+ * An attribute of type Binary Set. For example: + *

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + *

+ *

+ * NOTE: This method appends the values to the existing list (if any). Use + * {@link #setBS(java.util.Collection)} or {@link #withBS(java.util.Collection)} if you want to override the + * existing values. + *

+ * + * @param bS + * An attribute of type Binary Set. For example:

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withBS(java.nio.ByteBuffer... bS) { + if (this.bS == null) { + setBS(new java.util.ArrayList(bS.length)); + } + for (java.nio.ByteBuffer ele : bS) { + this.bS.add(ele); + } + return this; + } + + /** + *

+ * An attribute of type Binary Set. For example: + *

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + *

+ * + * @param bS + * An attribute of type Binary Set. For example:

+ *

+ * "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withBS(java.util.Collection bS) { + setBS(bS); + return this; + } + + /** + *

+ * An attribute of type Map. For example: + *

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + *

+ * + * @return An attribute of type Map. For example:

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + */ + + public java.util.Map getM() { + return m; + } + + /** + *

+ * An attribute of type Map. For example: + *

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + *

+ * + * @param m + * An attribute of type Map. For example:

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + */ + + public void setM(java.util.Map m) { + this.m = m; + } + + /** + *

+ * An attribute of type Map. For example: + *

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + *

+ * + * @param m + * An attribute of type Map. For example:

+ *

+ * "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withM(java.util.Map m) { + setM(m); + return this; + } + + public AttributeValue addMEntry(String key, AttributeValue value) { + if (null == this.m) { + this.m = new java.util.HashMap(); + } + if (this.m.containsKey(key)) + throw new IllegalArgumentException("Duplicated keys (" + key.toString() + ") are provided."); + this.m.put(key, value); + return this; + } + + /** + * Removes all the entries added into M. + * + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue clearMEntries() { + this.m = null; + return this; + } + + /** + *

+ * An attribute of type List. For example: + *

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + *

+ * + * @return An attribute of type List. For example:

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + */ + + public java.util.List getL() { + return l; + } + + /** + *

+ * An attribute of type List. For example: + *

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + *

+ * + * @param l + * An attribute of type List. For example:

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + */ + + public void setL(java.util.Collection l) { + if (l == null) { + this.l = null; + return; + } + + this.l = new java.util.ArrayList(l); + } + + /** + *

+ * An attribute of type List. For example: + *

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + *

+ *

+ * NOTE: This method appends the values to the existing list (if any). Use + * {@link #setL(java.util.Collection)} or {@link #withL(java.util.Collection)} if you want to override the existing + * values. + *

+ * + * @param l + * An attribute of type List. For example:

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withL(AttributeValue... l) { + if (this.l == null) { + setL(new java.util.ArrayList(l.length)); + } + for (AttributeValue ele : l) { + this.l.add(ele); + } + return this; + } + + /** + *

+ * An attribute of type List. For example: + *

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + *

+ * + * @param l + * An attribute of type List. For example:

+ *

+ * "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N", "3.14159"}] + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withL(java.util.Collection l) { + setL(l); + return this; + } + + /** + *

+ * An attribute of type Null. For example: + *

+ *

+ * "NULL": true + *

+ * + * @param nULLValue + * An attribute of type Null. For example:

+ *

+ * "NULL": true + */ + + public void setNULL(Boolean nULLValue) { + this.nULLValue = nULLValue; + } + + /** + *

+ * An attribute of type Null. For example: + *

+ *

+ * "NULL": true + *

+ * + * @return An attribute of type Null. For example:

+ *

+ * "NULL": true + */ + + public Boolean getNULL() { + return this.nULLValue; + } + + /** + *

+ * An attribute of type Null. For example: + *

+ *

+ * "NULL": true + *

+ * + * @param nULLValue + * An attribute of type Null. For example:

+ *

+ * "NULL": true + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withNULL(Boolean nULLValue) { + setNULL(nULLValue); + return this; + } + + /** + *

+ * An attribute of type Null. For example: + *

+ *

+ * "NULL": true + *

+ * + * @return An attribute of type Null. For example:

+ *

+ * "NULL": true + */ + + public Boolean isNULL() { + return this.nULLValue; + } + + /** + *

+ * An attribute of type Boolean. For example: + *

+ *

+ * "BOOL": true + *

+ * + * @param bOOL + * An attribute of type Boolean. For example:

+ *

+ * "BOOL": true + */ + + public void setBOOL(Boolean bOOL) { + this.bOOL = bOOL; + } + + /** + *

+ * An attribute of type Boolean. For example: + *

+ *

+ * "BOOL": true + *

+ * + * @return An attribute of type Boolean. For example:

+ *

+ * "BOOL": true + */ + + public Boolean getBOOL() { + return this.bOOL; + } + + /** + *

+ * An attribute of type Boolean. For example: + *

+ *

+ * "BOOL": true + *

+ * + * @param bOOL + * An attribute of type Boolean. For example:

+ *

+ * "BOOL": true + * @return Returns a reference to this object so that method calls can be chained together. + */ + + public AttributeValue withBOOL(Boolean bOOL) { + setBOOL(bOOL); + return this; + } + + /** + *

+ * An attribute of type Boolean. For example: + *

+ *

+ * "BOOL": true + *

+ * + * @return An attribute of type Boolean. For example:

+ *

+ * "BOOL": true + */ + + public Boolean isBOOL() { + return this.bOOL; + } + + /** + * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be + * redacted from this string using a placeholder value. + * + * @return A string representation of this object. + * + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getS() != null) + sb.append("S: ").append(getS()).append(","); + if (getN() != null) + sb.append("N: ").append(getN()).append(","); + if (getB() != null) + sb.append("B: ").append(getB()).append(","); + if (getSS() != null) + sb.append("SS: ").append(getSS()).append(","); + if (getNS() != null) + sb.append("NS: ").append(getNS()).append(","); + if (getBS() != null) + sb.append("BS: ").append(getBS()).append(","); + if (getM() != null) + sb.append("M: ").append(getM()).append(","); + if (getL() != null) + sb.append("L: ").append(getL()).append(","); + if (getNULL() != null) + sb.append("NULL: ").append(getNULL()).append(","); + if (getBOOL() != null) + sb.append("BOOL: ").append(getBOOL()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof AttributeValue == false) + return false; + AttributeValue other = (AttributeValue) obj; + if (other.getS() == null ^ this.getS() == null) + return false; + if (other.getS() != null && other.getS().equals(this.getS()) == false) + return false; + if (other.getN() == null ^ this.getN() == null) + return false; + if (other.getN() != null && other.getN().equals(this.getN()) == false) + return false; + if (other.getB() == null ^ this.getB() == null) + return false; + if (other.getB() != null && other.getB().equals(this.getB()) == false) + return false; + if (other.getSS() == null ^ this.getSS() == null) + return false; + if (other.getSS() != null && other.getSS().equals(this.getSS()) == false) + return false; + if (other.getNS() == null ^ this.getNS() == null) + return false; + if (other.getNS() != null && other.getNS().equals(this.getNS()) == false) + return false; + if (other.getBS() == null ^ this.getBS() == null) + return false; + if (other.getBS() != null && other.getBS().equals(this.getBS()) == false) + return false; + if (other.getM() == null ^ this.getM() == null) + return false; + if (other.getM() != null && other.getM().equals(this.getM()) == false) + return false; + if (other.getL() == null ^ this.getL() == null) + return false; + if (other.getL() != null && other.getL().equals(this.getL()) == false) + return false; + if (other.getNULL() == null ^ this.getNULL() == null) + return false; + if (other.getNULL() != null && other.getNULL().equals(this.getNULL()) == false) + return false; + if (other.getBOOL() == null ^ this.getBOOL() == null) + return false; + if (other.getBOOL() != null && other.getBOOL().equals(this.getBOOL()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + ((getS() == null) ? 0 : getS().hashCode()); + hashCode = prime * hashCode + ((getN() == null) ? 0 : getN().hashCode()); + hashCode = prime * hashCode + ((getB() == null) ? 0 : getB().hashCode()); + hashCode = prime * hashCode + ((getSS() == null) ? 0 : getSS().hashCode()); + hashCode = prime * hashCode + ((getNS() == null) ? 0 : getNS().hashCode()); + hashCode = prime * hashCode + ((getBS() == null) ? 0 : getBS().hashCode()); + hashCode = prime * hashCode + ((getM() == null) ? 0 : getM().hashCode()); + hashCode = prime * hashCode + ((getL() == null) ? 0 : getL().hashCode()); + hashCode = prime * hashCode + ((getNULL() == null) ? 0 : getNULL().hashCode()); + hashCode = prime * hashCode + ((getBOOL() == null) ? 0 : getBOOL().hashCode()); + return hashCode; + } + + @Override + public AttributeValue clone() { + try { + return (AttributeValue) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() even though we're Cloneable!", e); + } + } + +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Identity.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Identity.java new file mode 100644 index 00000000..12b2fbba --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Identity.java @@ -0,0 +1,182 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.dynamodb; + +import java.io.Serializable; + +/** + *

+ * Contains details about the type of identity that made the request. + *

+ * + * @see AWS API + * Documentation + */ +public class Identity implements Serializable, Cloneable { + + /** + *

+ * A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + *

+ */ + private String principalId; + + /** + *

+ * The type of the identity. For Time To Live, the type is "Service". + *

+ */ + private String type; + + /** + *

+ * A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + *

+ * + * @param principalId + * A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + */ + public void setPrincipalId(String principalId) { + this.principalId = principalId; + } + + /** + *

+ * A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + *

+ * + * @return A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + */ + public String getPrincipalId() { + return this.principalId; + } + + /** + *

+ * A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + *

+ * + * @param principalId + * A unique identifier for the entity that made the call. For Time To Live, the principalId is + * "dynamodb.amazonaws.com". + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Identity withPrincipalId(String principalId) { + setPrincipalId(principalId); + return this; + } + + /** + *

+ * The type of the identity. For Time To Live, the type is "Service". + *

+ * + * @param type + * The type of the identity. For Time To Live, the type is "Service". + */ + public void setType(String type) { + this.type = type; + } + + /** + *

+ * The type of the identity. For Time To Live, the type is "Service". + *

+ * + * @return The type of the identity. For Time To Live, the type is "Service". + */ + public String getType() { + return this.type; + } + + /** + *

+ * The type of the identity. For Time To Live, the type is "Service". + *

+ * + * @param type + * The type of the identity. For Time To Live, the type is "Service". + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Identity withType(String type) { + setType(type); + return this; + } + + /** + * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be + * redacted from this string using a placeholder value. + * + * @return A string representation of this object. + * + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getPrincipalId() != null) + sb.append("PrincipalId: ").append(getPrincipalId()).append(","); + if (getType() != null) + sb.append("Type: ").append(getType()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof Identity == false) + return false; + Identity other = (Identity) obj; + if (other.getPrincipalId() == null ^ this.getPrincipalId() == null) + return false; + if (other.getPrincipalId() != null && other.getPrincipalId().equals(this.getPrincipalId()) == false) + return false; + if (other.getType() == null ^ this.getType() == null) + return false; + if (other.getType() != null && other.getType().equals(this.getType()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + ((getPrincipalId() == null) ? 0 : getPrincipalId().hashCode()); + hashCode = prime * hashCode + ((getType() == null) ? 0 : getType().hashCode()); + return hashCode; + } + + @Override + public Identity clone() { + try { + return (Identity) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e); + } + } + +} diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/OperationType.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/OperationType.java new file mode 100644 index 00000000..8d5574ee --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/OperationType.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.dynamodb; + +public enum OperationType { + + INSERT("INSERT"), + MODIFY("MODIFY"), + REMOVE("REMOVE"); + + private String value; + + private OperationType(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + /** + * Use this in place of valueOf. + * + * @param value + * real value + * @return OperationType corresponding to the value + * + * @throws IllegalArgumentException + * If the specified value does not map to one of the known values in this enum. + */ + public static OperationType fromValue(String value) { + if (value == null || "".equals(value)) { + throw new IllegalArgumentException("Value cannot be null or empty!"); + } + + for (OperationType enumEntry : OperationType.values()) { + if (enumEntry.toString().equals(value)) { + return enumEntry; + } + } + throw new IllegalArgumentException("Cannot create enum from " + value + " value!"); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Record.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Record.java new file mode 100644 index 00000000..81065811 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Record.java @@ -0,0 +1,801 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.dynamodb; + +import java.io.Serializable; + +/** + *

+ * A description of a unique event within a stream. + *

+ * + * @see AWS API + * Documentation + */ +public class Record implements Serializable, Cloneable { + + /** + *

+ * A globally unique identifier for the event that was recorded in this stream record. + *

+ */ + private String eventID; + /** + *

+ * The type of data modification that was performed on the DynamoDB table: + *

+ *
    + *
  • + *

    + * INSERT - a new item was added to the table. + *

    + *
  • + *
  • + *

    + * MODIFY - one or more of an existing item's attributes were modified. + *

    + *
  • + *
  • + *

    + * REMOVE - the item was deleted from the table + *

    + *
  • + *
+ */ + private String eventName; + /** + *

+ * The version number of the stream record format. This number is updated whenever the structure of + * Record is modified. + *

+ *

+ * Client applications must not assume that eventVersion will remain at a particular value, as this + * number is subject to change at any time. In general, eventVersion will only increase as the + * low-level DynamoDB Streams API evolves. + *

+ */ + private String eventVersion; + /** + *

+ * The AWS service from which the stream record originated. For DynamoDB Streams, this is aws:dynamodb. + *

+ */ + private String eventSource; + /** + *

+ * The region in which the GetRecords request was received. + *

+ */ + private String awsRegion; + /** + *

+ * The main body of the stream record, containing all of the DynamoDB-specific fields. + *

+ */ + private StreamRecord dynamodb; + /** + *

+ * Items that are deleted by the Time to Live process after expiration have the following fields: + *

+ *
    + *
  • + *

    + * Records[].userIdentity.type + *

    + *

    + * "Service" + *

    + *
  • + *
  • + *

    + * Records[].userIdentity.principalId + *

    + *

    + * "dynamodb.amazonaws.com" + *

    + *
  • + *
+ */ + private Identity userIdentity; + + /** + *

+ * A globally unique identifier for the event that was recorded in this stream record. + *

+ * + * @param eventID + * A globally unique identifier for the event that was recorded in this stream record. + */ + public void setEventID(String eventID) { + this.eventID = eventID; + } + + /** + *

+ * A globally unique identifier for the event that was recorded in this stream record. + *

+ * + * @return A globally unique identifier for the event that was recorded in this stream record. + */ + public String getEventID() { + return this.eventID; + } + + /** + *

+ * A globally unique identifier for the event that was recorded in this stream record. + *

+ * + * @param eventID + * A globally unique identifier for the event that was recorded in this stream record. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withEventID(String eventID) { + setEventID(eventID); + return this; + } + + /** + *

+ * The type of data modification that was performed on the DynamoDB table: + *

+ *
    + *
  • + *

    + * INSERT - a new item was added to the table. + *

    + *
  • + *
  • + *

    + * MODIFY - one or more of an existing item's attributes were modified. + *

    + *
  • + *
  • + *

    + * REMOVE - the item was deleted from the table + *

    + *
  • + *
+ * + * @param eventName + * The type of data modification that was performed on the DynamoDB table:

+ *
    + *
  • + *

    + * INSERT - a new item was added to the table. + *

    + *
  • + *
  • + *

    + * MODIFY - one or more of an existing item's attributes were modified. + *

    + *
  • + *
  • + *

    + * REMOVE - the item was deleted from the table + *

    + *
  • + * @see OperationType + */ + public void setEventName(String eventName) { + this.eventName = eventName; + } + + /** + *

    + * The type of data modification that was performed on the DynamoDB table: + *

    + *
      + *
    • + *

      + * INSERT - a new item was added to the table. + *

      + *
    • + *
    • + *

      + * MODIFY - one or more of an existing item's attributes were modified. + *

      + *
    • + *
    • + *

      + * REMOVE - the item was deleted from the table + *

      + *
    • + *
    + * + * @return The type of data modification that was performed on the DynamoDB table:

    + *
      + *
    • + *

      + * INSERT - a new item was added to the table. + *

      + *
    • + *
    • + *

      + * MODIFY - one or more of an existing item's attributes were modified. + *

      + *
    • + *
    • + *

      + * REMOVE - the item was deleted from the table + *

      + *
    • + * @see OperationType + */ + public String getEventName() { + return this.eventName; + } + + /** + *

      + * The type of data modification that was performed on the DynamoDB table: + *

      + *
        + *
      • + *

        + * INSERT - a new item was added to the table. + *

        + *
      • + *
      • + *

        + * MODIFY - one or more of an existing item's attributes were modified. + *

        + *
      • + *
      • + *

        + * REMOVE - the item was deleted from the table + *

        + *
      • + *
      + * + * @param eventName + * The type of data modification that was performed on the DynamoDB table:

      + *
        + *
      • + *

        + * INSERT - a new item was added to the table. + *

        + *
      • + *
      • + *

        + * MODIFY - one or more of an existing item's attributes were modified. + *

        + *
      • + *
      • + *

        + * REMOVE - the item was deleted from the table + *

        + *
      • + * @return Returns a reference to this object so that method calls can be chained together. + * @see OperationType + */ + public Record withEventName(String eventName) { + setEventName(eventName); + return this; + } + + /** + *

        + * The type of data modification that was performed on the DynamoDB table: + *

        + *
          + *
        • + *

          + * INSERT - a new item was added to the table. + *

          + *
        • + *
        • + *

          + * MODIFY - one or more of an existing item's attributes were modified. + *

          + *
        • + *
        • + *

          + * REMOVE - the item was deleted from the table + *

          + *
        • + *
        + * + * @param eventName + * The type of data modification that was performed on the DynamoDB table:

        + *
          + *
        • + *

          + * INSERT - a new item was added to the table. + *

          + *
        • + *
        • + *

          + * MODIFY - one or more of an existing item's attributes were modified. + *

          + *
        • + *
        • + *

          + * REMOVE - the item was deleted from the table + *

          + *
        • + * @see OperationType + */ + public void setEventName(OperationType eventName) { + this.eventName = eventName.toString(); + } + + /** + *

          + * The type of data modification that was performed on the DynamoDB table: + *

          + *
            + *
          • + *

            + * INSERT - a new item was added to the table. + *

            + *
          • + *
          • + *

            + * MODIFY - one or more of an existing item's attributes were modified. + *

            + *
          • + *
          • + *

            + * REMOVE - the item was deleted from the table + *

            + *
          • + *
          + * + * @param eventName + * The type of data modification that was performed on the DynamoDB table:

          + *
            + *
          • + *

            + * INSERT - a new item was added to the table. + *

            + *
          • + *
          • + *

            + * MODIFY - one or more of an existing item's attributes were modified. + *

            + *
          • + *
          • + *

            + * REMOVE - the item was deleted from the table + *

            + *
          • + * @return Returns a reference to this object so that method calls can be chained together. + * @see OperationType + */ + public Record withEventName(OperationType eventName) { + setEventName(eventName); + return this; + } + + /** + *

            + * The version number of the stream record format. This number is updated whenever the structure of + * Record is modified. + *

            + *

            + * Client applications must not assume that eventVersion will remain at a particular value, as this + * number is subject to change at any time. In general, eventVersion will only increase as the + * low-level DynamoDB Streams API evolves. + *

            + * + * @param eventVersion + * The version number of the stream record format. This number is updated whenever the structure of + * Record is modified.

            + *

            + * Client applications must not assume that eventVersion will remain at a particular value, as + * this number is subject to change at any time. In general, eventVersion will only increase as + * the low-level DynamoDB Streams API evolves. + */ + public void setEventVersion(String eventVersion) { + this.eventVersion = eventVersion; + } + + /** + *

            + * The version number of the stream record format. This number is updated whenever the structure of + * Record is modified. + *

            + *

            + * Client applications must not assume that eventVersion will remain at a particular value, as this + * number is subject to change at any time. In general, eventVersion will only increase as the + * low-level DynamoDB Streams API evolves. + *

            + * + * @return The version number of the stream record format. This number is updated whenever the structure of + * Record is modified.

            + *

            + * Client applications must not assume that eventVersion will remain at a particular value, as + * this number is subject to change at any time. In general, eventVersion will only increase as + * the low-level DynamoDB Streams API evolves. + */ + public String getEventVersion() { + return this.eventVersion; + } + + /** + *

            + * The version number of the stream record format. This number is updated whenever the structure of + * Record is modified. + *

            + *

            + * Client applications must not assume that eventVersion will remain at a particular value, as this + * number is subject to change at any time. In general, eventVersion will only increase as the + * low-level DynamoDB Streams API evolves. + *

            + * + * @param eventVersion + * The version number of the stream record format. This number is updated whenever the structure of + * Record is modified.

            + *

            + * Client applications must not assume that eventVersion will remain at a particular value, as + * this number is subject to change at any time. In general, eventVersion will only increase as + * the low-level DynamoDB Streams API evolves. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withEventVersion(String eventVersion) { + setEventVersion(eventVersion); + return this; + } + + /** + *

            + * The AWS service from which the stream record originated. For DynamoDB Streams, this is aws:dynamodb. + *

            + * + * @param eventSource + * The AWS service from which the stream record originated. For DynamoDB Streams, this is + * aws:dynamodb. + */ + public void setEventSource(String eventSource) { + this.eventSource = eventSource; + } + + /** + *

            + * The AWS service from which the stream record originated. For DynamoDB Streams, this is aws:dynamodb. + *

            + * + * @return The AWS service from which the stream record originated. For DynamoDB Streams, this is + * aws:dynamodb. + */ + public String getEventSource() { + return this.eventSource; + } + + /** + *

            + * The AWS service from which the stream record originated. For DynamoDB Streams, this is aws:dynamodb. + *

            + * + * @param eventSource + * The AWS service from which the stream record originated. For DynamoDB Streams, this is + * aws:dynamodb. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withEventSource(String eventSource) { + setEventSource(eventSource); + return this; + } + + /** + *

            + * The region in which the GetRecords request was received. + *

            + * + * @param awsRegion + * The region in which the GetRecords request was received. + */ + public void setAwsRegion(String awsRegion) { + this.awsRegion = awsRegion; + } + + /** + *

            + * The region in which the GetRecords request was received. + *

            + * + * @return The region in which the GetRecords request was received. + */ + public String getAwsRegion() { + return this.awsRegion; + } + + /** + *

            + * The region in which the GetRecords request was received. + *

            + * + * @param awsRegion + * The region in which the GetRecords request was received. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withAwsRegion(String awsRegion) { + setAwsRegion(awsRegion); + return this; + } + + /** + *

            + * The main body of the stream record, containing all of the DynamoDB-specific fields. + *

            + * + * @param dynamodb + * The main body of the stream record, containing all of the DynamoDB-specific fields. + */ + public void setDynamodb(StreamRecord dynamodb) { + this.dynamodb = dynamodb; + } + + /** + *

            + * The main body of the stream record, containing all of the DynamoDB-specific fields. + *

            + * + * @return The main body of the stream record, containing all of the DynamoDB-specific fields. + */ + public StreamRecord getDynamodb() { + return this.dynamodb; + } + + /** + *

            + * The main body of the stream record, containing all of the DynamoDB-specific fields. + *

            + * + * @param dynamodb + * The main body of the stream record, containing all of the DynamoDB-specific fields. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withDynamodb(StreamRecord dynamodb) { + setDynamodb(dynamodb); + return this; + } + + /** + *

            + * Items that are deleted by the Time to Live process after expiration have the following fields: + *

            + *
              + *
            • + *

              + * Records[].userIdentity.type + *

              + *

              + * "Service" + *

              + *
            • + *
            • + *

              + * Records[].userIdentity.principalId + *

              + *

              + * "dynamodb.amazonaws.com" + *

              + *
            • + *
            + * + * @param userIdentity + * Items that are deleted by the Time to Live process after expiration have the following fields:

            + *
              + *
            • + *

              + * Records[].userIdentity.type + *

              + *

              + * "Service" + *

              + *
            • + *
            • + *

              + * Records[].userIdentity.principalId + *

              + *

              + * "dynamodb.amazonaws.com" + *

              + *
            • + */ + public void setUserIdentity(Identity userIdentity) { + this.userIdentity = userIdentity; + } + + /** + *

              + * Items that are deleted by the Time to Live process after expiration have the following fields: + *

              + *
                + *
              • + *

                + * Records[].userIdentity.type + *

                + *

                + * "Service" + *

                + *
              • + *
              • + *

                + * Records[].userIdentity.principalId + *

                + *

                + * "dynamodb.amazonaws.com" + *

                + *
              • + *
              + * + * @return Items that are deleted by the Time to Live process after expiration have the following fields:

              + *
                + *
              • + *

                + * Records[].userIdentity.type + *

                + *

                + * "Service" + *

                + *
              • + *
              • + *

                + * Records[].userIdentity.principalId + *

                + *

                + * "dynamodb.amazonaws.com" + *

                + *
              • + */ + public Identity getUserIdentity() { + return this.userIdentity; + } + + /** + *

                + * Items that are deleted by the Time to Live process after expiration have the following fields: + *

                + *
                  + *
                • + *

                  + * Records[].userIdentity.type + *

                  + *

                  + * "Service" + *

                  + *
                • + *
                • + *

                  + * Records[].userIdentity.principalId + *

                  + *

                  + * "dynamodb.amazonaws.com" + *

                  + *
                • + *
                + * + * @param userIdentity + * Items that are deleted by the Time to Live process after expiration have the following fields:

                + *
                  + *
                • + *

                  + * Records[].userIdentity.type + *

                  + *

                  + * "Service" + *

                  + *
                • + *
                • + *

                  + * Records[].userIdentity.principalId + *

                  + *

                  + * "dynamodb.amazonaws.com" + *

                  + *
                • + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withUserIdentity(Identity userIdentity) { + setUserIdentity(userIdentity); + return this; + } + + /** + * Returns a string representation of this object; useful for testing and debugging. + * + * @return A string representation of this object. + * + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getEventID() != null) + sb.append("EventID: ").append(getEventID()).append(","); + if (getEventName() != null) + sb.append("EventName: ").append(getEventName()).append(","); + if (getEventVersion() != null) + sb.append("EventVersion: ").append(getEventVersion()).append(","); + if (getEventSource() != null) + sb.append("EventSource: ").append(getEventSource()).append(","); + if (getAwsRegion() != null) + sb.append("AwsRegion: ").append(getAwsRegion()).append(","); + if (getDynamodb() != null) + sb.append("Dynamodb: ").append(getDynamodb()).append(","); + if (getUserIdentity() != null) + sb.append("UserIdentity: ").append(getUserIdentity()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof Record == false) + return false; + Record other = (Record) obj; + if (other.getEventID() == null ^ this.getEventID() == null) + return false; + if (other.getEventID() != null && other.getEventID().equals(this.getEventID()) == false) + return false; + if (other.getEventName() == null ^ this.getEventName() == null) + return false; + if (other.getEventName() != null && other.getEventName().equals(this.getEventName()) == false) + return false; + if (other.getEventVersion() == null ^ this.getEventVersion() == null) + return false; + if (other.getEventVersion() != null && other.getEventVersion().equals(this.getEventVersion()) == false) + return false; + if (other.getEventSource() == null ^ this.getEventSource() == null) + return false; + if (other.getEventSource() != null && other.getEventSource().equals(this.getEventSource()) == false) + return false; + if (other.getAwsRegion() == null ^ this.getAwsRegion() == null) + return false; + if (other.getAwsRegion() != null && other.getAwsRegion().equals(this.getAwsRegion()) == false) + return false; + if (other.getDynamodb() == null ^ this.getDynamodb() == null) + return false; + if (other.getDynamodb() != null && other.getDynamodb().equals(this.getDynamodb()) == false) + return false; + if (other.getUserIdentity() == null ^ this.getUserIdentity() == null) + return false; + if (other.getUserIdentity() != null && other.getUserIdentity().equals(this.getUserIdentity()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + ((getEventID() == null) ? 0 : getEventID().hashCode()); + hashCode = prime * hashCode + ((getEventName() == null) ? 0 : getEventName().hashCode()); + hashCode = prime * hashCode + ((getEventVersion() == null) ? 0 : getEventVersion().hashCode()); + hashCode = prime * hashCode + ((getEventSource() == null) ? 0 : getEventSource().hashCode()); + hashCode = prime * hashCode + ((getAwsRegion() == null) ? 0 : getAwsRegion().hashCode()); + hashCode = prime * hashCode + ((getDynamodb() == null) ? 0 : getDynamodb().hashCode()); + hashCode = prime * hashCode + ((getUserIdentity() == null) ? 0 : getUserIdentity().hashCode()); + return hashCode; + } + + @Override + public Record clone() { + try { + return (Record) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e); + } + } + +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamRecord.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamRecord.java new file mode 100644 index 00000000..0e41c0de --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamRecord.java @@ -0,0 +1,645 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.dynamodb; + +import java.io.Serializable; + +/** + *

                  + * A description of a single data modification that was performed on an item in a DynamoDB table. + *

                  + * + * @see AWS API + * Documentation + */ +public class StreamRecord implements Serializable, Cloneable { + + /** + *

                  + * The approximate date and time when the stream record was created, in UNIX epoch time format. + *

                  + */ + private java.util.Date approximateCreationDateTime; + /** + *

                  + * The primary key attribute(s) for the DynamoDB item that was modified. + *

                  + */ + private java.util.Map keys; + /** + *

                  + * The item in the DynamoDB table as it appeared after it was modified. + *

                  + */ + private java.util.Map newImage; + /** + *

                  + * The item in the DynamoDB table as it appeared before it was modified. + *

                  + */ + private java.util.Map oldImage; + /** + *

                  + * The sequence number of the stream record. + *

                  + */ + private String sequenceNumber; + /** + *

                  + * The size of the stream record, in bytes. + *

                  + */ + private Long sizeBytes; + /** + *

                  + * The type of data from the modified DynamoDB item that was captured in this stream record: + *

                  + *
                    + *
                  • + *

                    + * KEYS_ONLY - only the key attributes of the modified item. + *

                    + *
                  • + *
                  • + *

                    + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                    + *
                  • + *
                  • + *

                    + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                    + *
                  • + *
                  • + *

                    + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                    + *
                  • + *
                  + */ + private String streamViewType; + + /** + *

                  + * The approximate date and time when the stream record was created, in UNIX epoch time format. + *

                  + * + * @param approximateCreationDateTime + * The approximate date and time when the stream record was created, in UNIX epoch time format. + */ + public void setApproximateCreationDateTime(java.util.Date approximateCreationDateTime) { + this.approximateCreationDateTime = approximateCreationDateTime; + } + + /** + *

                  + * The approximate date and time when the stream record was created, in UNIX epoch time format. + *

                  + * + * @return The approximate date and time when the stream record was created, in UNIX epoch time format. + */ + public java.util.Date getApproximateCreationDateTime() { + return this.approximateCreationDateTime; + } + + /** + *

                  + * The approximate date and time when the stream record was created, in UNIX epoch time format. + *

                  + * + * @param approximateCreationDateTime + * The approximate date and time when the stream record was created, in UNIX epoch time format. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord withApproximateCreationDateTime(java.util.Date approximateCreationDateTime) { + setApproximateCreationDateTime(approximateCreationDateTime); + return this; + } + + /** + *

                  + * The primary key attribute(s) for the DynamoDB item that was modified. + *

                  + * + * @return The primary key attribute(s) for the DynamoDB item that was modified. + */ + public java.util.Map getKeys() { + return keys; + } + + /** + *

                  + * The primary key attribute(s) for the DynamoDB item that was modified. + *

                  + * + * @param keys + * The primary key attribute(s) for the DynamoDB item that was modified. + */ + public void setKeys(java.util.Map keys) { + this.keys = keys; + } + + /** + *

                  + * The primary key attribute(s) for the DynamoDB item that was modified. + *

                  + * + * @param keys + * The primary key attribute(s) for the DynamoDB item that was modified. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord withKeys(java.util.Map keys) { + setKeys(keys); + return this; + } + + public StreamRecord addKeysEntry(String key, AttributeValue value) { + if (null == this.keys) { + this.keys = new java.util.HashMap(); + } + if (this.keys.containsKey(key)) + throw new IllegalArgumentException("Duplicated keys (" + key.toString() + ") are provided."); + this.keys.put(key, value); + return this; + } + + /** + * Removes all the entries added into Keys. + * + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord clearKeysEntries() { + this.keys = null; + return this; + } + + /** + *

                  + * The item in the DynamoDB table as it appeared after it was modified. + *

                  + * + * @return The item in the DynamoDB table as it appeared after it was modified. + */ + public java.util.Map getNewImage() { + return newImage; + } + + /** + *

                  + * The item in the DynamoDB table as it appeared after it was modified. + *

                  + * + * @param newImage + * The item in the DynamoDB table as it appeared after it was modified. + */ + public void setNewImage(java.util.Map newImage) { + this.newImage = newImage; + } + + /** + *

                  + * The item in the DynamoDB table as it appeared after it was modified. + *

                  + * + * @param newImage + * The item in the DynamoDB table as it appeared after it was modified. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord withNewImage(java.util.Map newImage) { + setNewImage(newImage); + return this; + } + + public StreamRecord addNewImageEntry(String key, AttributeValue value) { + if (null == this.newImage) { + this.newImage = new java.util.HashMap(); + } + if (this.newImage.containsKey(key)) + throw new IllegalArgumentException("Duplicated keys (" + key.toString() + ") are provided."); + this.newImage.put(key, value); + return this; + } + + /** + * Removes all the entries added into NewImage. + * + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord clearNewImageEntries() { + this.newImage = null; + return this; + } + + /** + *

                  + * The item in the DynamoDB table as it appeared before it was modified. + *

                  + * + * @return The item in the DynamoDB table as it appeared before it was modified. + */ + public java.util.Map getOldImage() { + return oldImage; + } + + /** + *

                  + * The item in the DynamoDB table as it appeared before it was modified. + *

                  + * + * @param oldImage + * The item in the DynamoDB table as it appeared before it was modified. + */ + public void setOldImage(java.util.Map oldImage) { + this.oldImage = oldImage; + } + + /** + *

                  + * The item in the DynamoDB table as it appeared before it was modified. + *

                  + * + * @param oldImage + * The item in the DynamoDB table as it appeared before it was modified. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord withOldImage(java.util.Map oldImage) { + setOldImage(oldImage); + return this; + } + + public StreamRecord addOldImageEntry(String key, AttributeValue value) { + if (null == this.oldImage) { + this.oldImage = new java.util.HashMap(); + } + if (this.oldImage.containsKey(key)) + throw new IllegalArgumentException("Duplicated keys (" + key.toString() + ") are provided."); + this.oldImage.put(key, value); + return this; + } + + /** + * Removes all the entries added into OldImage. + * + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord clearOldImageEntries() { + this.oldImage = null; + return this; + } + + /** + *

                  + * The sequence number of the stream record. + *

                  + * + * @param sequenceNumber + * The sequence number of the stream record. + */ + public void setSequenceNumber(String sequenceNumber) { + this.sequenceNumber = sequenceNumber; + } + + /** + *

                  + * The sequence number of the stream record. + *

                  + * + * @return The sequence number of the stream record. + */ + public String getSequenceNumber() { + return this.sequenceNumber; + } + + /** + *

                  + * The sequence number of the stream record. + *

                  + * + * @param sequenceNumber + * The sequence number of the stream record. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord withSequenceNumber(String sequenceNumber) { + setSequenceNumber(sequenceNumber); + return this; + } + + /** + *

                  + * The size of the stream record, in bytes. + *

                  + * + * @param sizeBytes + * The size of the stream record, in bytes. + */ + public void setSizeBytes(Long sizeBytes) { + this.sizeBytes = sizeBytes; + } + + /** + *

                  + * The size of the stream record, in bytes. + *

                  + * + * @return The size of the stream record, in bytes. + */ + public Long getSizeBytes() { + return this.sizeBytes; + } + + /** + *

                  + * The size of the stream record, in bytes. + *

                  + * + * @param sizeBytes + * The size of the stream record, in bytes. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public StreamRecord withSizeBytes(Long sizeBytes) { + setSizeBytes(sizeBytes); + return this; + } + + /** + *

                  + * The type of data from the modified DynamoDB item that was captured in this stream record: + *

                  + *
                    + *
                  • + *

                    + * KEYS_ONLY - only the key attributes of the modified item. + *

                    + *
                  • + *
                  • + *

                    + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                    + *
                  • + *
                  • + *

                    + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                    + *
                  • + *
                  • + *

                    + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                    + *
                  • + *
                  + * + * @return The type of data from the modified DynamoDB item that was captured in this stream record:

                  + *
                    + *
                  • + *

                    + * KEYS_ONLY - only the key attributes of the modified item. + *

                    + *
                  • + *
                  • + *

                    + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                    + *
                  • + *
                  • + *

                    + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                    + *
                  • + *
                  • + *

                    + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                    + *
                  • + * @see StreamViewType + */ + public String getStreamViewType() { + return this.streamViewType; + } + + /** + *

                    + * The type of data from the modified DynamoDB item that was captured in this stream record: + *

                    + *
                      + *
                    • + *

                      + * KEYS_ONLY - only the key attributes of the modified item. + *

                      + *
                    • + *
                    • + *

                      + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                      + *
                    • + *
                    • + *

                      + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                      + *
                    • + *
                    • + *

                      + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                      + *
                    • + *
                    + * + * @param streamViewType + * The type of data from the modified DynamoDB item that was captured in this stream record:

                    + *
                      + *
                    • + *

                      + * KEYS_ONLY - only the key attributes of the modified item. + *

                      + *
                    • + *
                    • + *

                      + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                      + *
                    • + *
                    • + *

                      + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                      + *
                    • + *
                    • + *

                      + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                      + *
                    • + * @see StreamViewType + */ + public void setStreamViewType(StreamViewType streamViewType) { + withStreamViewType(streamViewType); + } + + /** + *

                      + * The type of data from the modified DynamoDB item that was captured in this stream record: + *

                      + *
                        + *
                      • + *

                        + * KEYS_ONLY - only the key attributes of the modified item. + *

                        + *
                      • + *
                      • + *

                        + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                        + *
                      • + *
                      • + *

                        + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                        + *
                      • + *
                      • + *

                        + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                        + *
                      • + *
                      + * + * @param streamViewType + * The type of data from the modified DynamoDB item that was captured in this stream record:

                      + *
                        + *
                      • + *

                        + * KEYS_ONLY - only the key attributes of the modified item. + *

                        + *
                      • + *
                      • + *

                        + * NEW_IMAGE - the entire item, as it appeared after it was modified. + *

                        + *
                      • + *
                      • + *

                        + * OLD_IMAGE - the entire item, as it appeared before it was modified. + *

                        + *
                      • + *
                      • + *

                        + * NEW_AND_OLD_IMAGES - both the new and the old item images of the item. + *

                        + *
                      • + * @return Returns a reference to this object so that method calls can be chained together. + * @see StreamViewType + */ + public StreamRecord withStreamViewType(StreamViewType streamViewType) { + this.streamViewType = streamViewType.toString(); + return this; + } + + /** + * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be + * redacted from this string using a placeholder value. + * + * @return A string representation of this object. + * + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getApproximateCreationDateTime() != null) + sb.append("ApproximateCreationDateTime: ").append(getApproximateCreationDateTime()).append(","); + if (getKeys() != null) + sb.append("Keys: ").append(getKeys()).append(","); + if (getNewImage() != null) + sb.append("NewImage: ").append(getNewImage()).append(","); + if (getOldImage() != null) + sb.append("OldImage: ").append(getOldImage()).append(","); + if (getSequenceNumber() != null) + sb.append("SequenceNumber: ").append(getSequenceNumber()).append(","); + if (getSizeBytes() != null) + sb.append("SizeBytes: ").append(getSizeBytes()).append(","); + if (getStreamViewType() != null) + sb.append("StreamViewType: ").append(getStreamViewType()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof StreamRecord == false) + return false; + StreamRecord other = (StreamRecord) obj; + if (other.getApproximateCreationDateTime() == null ^ this.getApproximateCreationDateTime() == null) + return false; + if (other.getApproximateCreationDateTime() != null && other.getApproximateCreationDateTime().equals(this.getApproximateCreationDateTime()) == false) + return false; + if (other.getKeys() == null ^ this.getKeys() == null) + return false; + if (other.getKeys() != null && other.getKeys().equals(this.getKeys()) == false) + return false; + if (other.getNewImage() == null ^ this.getNewImage() == null) + return false; + if (other.getNewImage() != null && other.getNewImage().equals(this.getNewImage()) == false) + return false; + if (other.getOldImage() == null ^ this.getOldImage() == null) + return false; + if (other.getOldImage() != null && other.getOldImage().equals(this.getOldImage()) == false) + return false; + if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) + return false; + if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) + return false; + if (other.getSizeBytes() == null ^ this.getSizeBytes() == null) + return false; + if (other.getSizeBytes() != null && other.getSizeBytes().equals(this.getSizeBytes()) == false) + return false; + if (other.getStreamViewType() == null ^ this.getStreamViewType() == null) + return false; + if (other.getStreamViewType() != null && other.getStreamViewType().equals(this.getStreamViewType()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + ((getApproximateCreationDateTime() == null) ? 0 : getApproximateCreationDateTime().hashCode()); + hashCode = prime * hashCode + ((getKeys() == null) ? 0 : getKeys().hashCode()); + hashCode = prime * hashCode + ((getNewImage() == null) ? 0 : getNewImage().hashCode()); + hashCode = prime * hashCode + ((getOldImage() == null) ? 0 : getOldImage().hashCode()); + hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); + hashCode = prime * hashCode + ((getSizeBytes() == null) ? 0 : getSizeBytes().hashCode()); + hashCode = prime * hashCode + ((getStreamViewType() == null) ? 0 : getStreamViewType().hashCode()); + return hashCode; + } + + @Override + public StreamRecord clone() { + try { + return (StreamRecord) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e); + } + } + +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamViewType.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamViewType.java new file mode 100644 index 00000000..93cdbc8f --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamViewType.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.dynamodb; + +public enum StreamViewType { + + NEW_IMAGE("NEW_IMAGE"), + OLD_IMAGE("OLD_IMAGE"), + NEW_AND_OLD_IMAGES("NEW_AND_OLD_IMAGES"), + KEYS_ONLY("KEYS_ONLY"); + + private String value; + + StreamViewType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return this.value; + } + + /** + * Use this in place of valueOf. + * + * @param value real value + * @return StreamViewType corresponding to the value + * + * @throws IllegalArgumentException + * If the specified value does not map to one of the known values in this enum. + */ + public static StreamViewType fromValue(String value) { + if (value == null || "".equals(value)) { + throw new IllegalArgumentException("Value cannot be null or empty!"); + } + + for (StreamViewType enumEntry : StreamViewType.values()) { + if (enumEntry.toString().equals(value)) { + return enumEntry; + } + } + + throw new IllegalArgumentException("Cannot create enum from " + value + " value!"); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/EncryptionType.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/EncryptionType.java new file mode 100644 index 00000000..8ffb3e14 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/EncryptionType.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.kinesis; + +public enum EncryptionType { + + NONE("NONE"), + KMS("KMS"); + + private String value; + + private EncryptionType(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + /** + * Use this in place of valueOf. + * + * @param value + * real value + * @return EncryptionType corresponding to the value + * + * @throws IllegalArgumentException + * If the specified value does not map to one of the known values in this enum. + */ + public static EncryptionType fromValue(String value) { + if (value == null || "".equals(value)) { + throw new IllegalArgumentException("Value cannot be null or empty!"); + } + + for (EncryptionType enumEntry : EncryptionType.values()) { + if (enumEntry.toString().equals(value)) { + return enumEntry; + } + } + + throw new IllegalArgumentException("Cannot create enum from " + value + " value!"); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/Record.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/Record.java new file mode 100644 index 00000000..085fe8e5 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/Record.java @@ -0,0 +1,494 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.kinesis; + +import java.io.Serializable; + +/** + *

                        + * The unit of data of the Kinesis data stream, which is composed of a sequence number, a partition key, and a data + * blob. + *

                        + * + * @see AWS API + * Documentation + */ +public class Record implements Serializable, Cloneable { + + /** + *

                        + * The unique identifier of the record within its shard. + *

                        + */ + private String sequenceNumber; + /** + *

                        + * The approximate time that the record was inserted into the stream. + *

                        + */ + private java.util.Date approximateArrivalTimestamp; + /** + *

                        + * The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not inspect, + * interpret, or change the data in the blob in any way. When the data blob (the payload before base64-encoding) is + * added to the partition key size, the total size must not exceed the maximum record size (1 MB). + *

                        + */ + private java.nio.ByteBuffer data; + /** + *

                        + * Identifies which shard in the stream the data record is assigned to. + *

                        + */ + private String partitionKey; + /** + *

                        + * The encryption type used on the record. This parameter can be one of the following values: + *

                        + *
                          + *
                        • + *

                          + * NONE: Do not encrypt the records in the stream. + *

                          + *
                        • + *
                        • + *

                          + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS key. + *

                          + *
                        • + *
                        + */ + private String encryptionType; + + /** + *

                        + * The unique identifier of the record within its shard. + *

                        + * + * @param sequenceNumber + * The unique identifier of the record within its shard. + */ + public void setSequenceNumber(String sequenceNumber) { + this.sequenceNumber = sequenceNumber; + } + + /** + *

                        + * The unique identifier of the record within its shard. + *

                        + * + * @return The unique identifier of the record within its shard. + */ + public String getSequenceNumber() { + return this.sequenceNumber; + } + + /** + *

                        + * The unique identifier of the record within its shard. + *

                        + * + * @param sequenceNumber + * The unique identifier of the record within its shard. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withSequenceNumber(String sequenceNumber) { + setSequenceNumber(sequenceNumber); + return this; + } + + /** + *

                        + * The approximate time that the record was inserted into the stream. + *

                        + * + * @param approximateArrivalTimestamp + * The approximate time that the record was inserted into the stream. + */ + public void setApproximateArrivalTimestamp(java.util.Date approximateArrivalTimestamp) { + this.approximateArrivalTimestamp = approximateArrivalTimestamp; + } + + /** + *

                        + * The approximate time that the record was inserted into the stream. + *

                        + * + * @return The approximate time that the record was inserted into the stream. + */ + public java.util.Date getApproximateArrivalTimestamp() { + return this.approximateArrivalTimestamp; + } + + /** + *

                        + * The approximate time that the record was inserted into the stream. + *

                        + * + * @param approximateArrivalTimestamp + * The approximate time that the record was inserted into the stream. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withApproximateArrivalTimestamp(java.util.Date approximateArrivalTimestamp) { + setApproximateArrivalTimestamp(approximateArrivalTimestamp); + return this; + } + + /** + *

                        + * The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not inspect, + * interpret, or change the data in the blob in any way. When the data blob (the payload before base64-encoding) is + * added to the partition key size, the total size must not exceed the maximum record size (1 MB). + *

                        + *

                        + * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. + * Users of the SDK should not perform Base64 encoding on this field. + *

                        + *

                        + * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will + * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or + * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future + * major version of the SDK. + *

                        + * + * @param data + * The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not + * inspect, interpret, or change the data in the blob in any way. When the data blob (the payload before + * base64-encoding) is added to the partition key size, the total size must not exceed the maximum record + * size (1 MB). + */ + public void setData(java.nio.ByteBuffer data) { + this.data = data; + } + + /** + *

                        + * The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not inspect, + * interpret, or change the data in the blob in any way. When the data blob (the payload before base64-encoding) is + * added to the partition key size, the total size must not exceed the maximum record size (1 MB). + *

                        + *

                        + * {@code ByteBuffer}s are stateful. Calling their {@code get} methods changes their {@code position}. We recommend + * using {@link java.nio.ByteBuffer#asReadOnlyBuffer()} to create a read-only view of the buffer with an independent + * {@code position}, and calling {@code get} methods on this rather than directly on the returned {@code ByteBuffer}. + * Doing so will ensure that anyone else using the {@code ByteBuffer} will not be affected by changes to the + * {@code position}. + *

                        + * + * @return The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not + * inspect, interpret, or change the data in the blob in any way. When the data blob (the payload before + * base64-encoding) is added to the partition key size, the total size must not exceed the maximum record + * size (1 MB). + */ + public java.nio.ByteBuffer getData() { + return this.data; + } + + /** + *

                        + * The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not inspect, + * interpret, or change the data in the blob in any way. When the data blob (the payload before base64-encoding) is + * added to the partition key size, the total size must not exceed the maximum record size (1 MB). + *

                        + *

                        + * The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. + * Users of the SDK should not perform Base64 encoding on this field. + *

                        + *

                        + * Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will + * be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or + * ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future + * major version of the SDK. + *

                        + * + * @param data + * The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not + * inspect, interpret, or change the data in the blob in any way. When the data blob (the payload before + * base64-encoding) is added to the partition key size, the total size must not exceed the maximum record + * size (1 MB). + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withData(java.nio.ByteBuffer data) { + setData(data); + return this; + } + + /** + *

                        + * Identifies which shard in the stream the data record is assigned to. + *

                        + * + * @param partitionKey + * Identifies which shard in the stream the data record is assigned to. + */ + public void setPartitionKey(String partitionKey) { + this.partitionKey = partitionKey; + } + + /** + *

                        + * Identifies which shard in the stream the data record is assigned to. + *

                        + * + * @return Identifies which shard in the stream the data record is assigned to. + */ + public String getPartitionKey() { + return this.partitionKey; + } + + /** + *

                        + * Identifies which shard in the stream the data record is assigned to. + *

                        + * + * @param partitionKey + * Identifies which shard in the stream the data record is assigned to. + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Record withPartitionKey(String partitionKey) { + setPartitionKey(partitionKey); + return this; + } + + /** + *

                        + * The encryption type used on the record. This parameter can be one of the following values: + *

                        + *
                          + *
                        • + *

                          + * NONE: Do not encrypt the records in the stream. + *

                          + *
                        • + *
                        • + *

                          + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS key. + *

                          + *
                        • + *
                        + * + * @param encryptionType + * The encryption type used on the record. This parameter can be one of the following values:

                        + *
                          + *
                        • + *

                          + * NONE: Do not encrypt the records in the stream. + *

                          + *
                        • + *
                        • + *

                          + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS + * key. + *

                          + *
                        • + * @see EncryptionType + */ + public void setEncryptionType(String encryptionType) { + this.encryptionType = encryptionType; + } + + /** + *

                          + * The encryption type used on the record. This parameter can be one of the following values: + *

                          + *
                            + *
                          • + *

                            + * NONE: Do not encrypt the records in the stream. + *

                            + *
                          • + *
                          • + *

                            + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS key. + *

                            + *
                          • + *
                          + * + * @return The encryption type used on the record. This parameter can be one of the following values:

                          + *
                            + *
                          • + *

                            + * NONE: Do not encrypt the records in the stream. + *

                            + *
                          • + *
                          • + *

                            + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS + * KMS key. + *

                            + *
                          • + * @see EncryptionType + */ + public String getEncryptionType() { + return this.encryptionType; + } + + /** + *

                            + * The encryption type used on the record. This parameter can be one of the following values: + *

                            + *
                              + *
                            • + *

                              + * NONE: Do not encrypt the records in the stream. + *

                              + *
                            • + *
                            • + *

                              + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS key. + *

                              + *
                            • + *
                            + * + * @param encryptionType + * The encryption type used on the record. This parameter can be one of the following values:

                            + *
                              + *
                            • + *

                              + * NONE: Do not encrypt the records in the stream. + *

                              + *
                            • + *
                            • + *

                              + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS + * key. + *

                              + *
                            • + * @return Returns a reference to this object so that method calls can be chained together. + * @see EncryptionType + */ + public Record withEncryptionType(String encryptionType) { + setEncryptionType(encryptionType); + return this; + } + + /** + *

                              + * The encryption type used on the record. This parameter can be one of the following values: + *

                              + *
                                + *
                              • + *

                                + * NONE: Do not encrypt the records in the stream. + *

                                + *
                              • + *
                              • + *

                                + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS key. + *

                                + *
                              • + *
                              + * + * @param encryptionType + * The encryption type used on the record. This parameter can be one of the following values:

                              + *
                                + *
                              • + *

                                + * NONE: Do not encrypt the records in the stream. + *

                                + *
                              • + *
                              • + *

                                + * KMS: Use server-side encryption on the records in the stream using a customer-managed AWS KMS + * key. + *

                                + *
                              • + * @return Returns a reference to this object so that method calls can be chained together. + * @see EncryptionType + */ + public Record withEncryptionType(EncryptionType encryptionType) { + this.encryptionType = encryptionType.toString(); + return this; + } + + /** + * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be + * redacted from this string using a placeholder value. + * + * @return A string representation of this object. + * + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getSequenceNumber() != null) + sb.append("SequenceNumber: ").append(getSequenceNumber()).append(","); + if (getApproximateArrivalTimestamp() != null) + sb.append("ApproximateArrivalTimestamp: ").append(getApproximateArrivalTimestamp()).append(","); + if (getData() != null) + sb.append("Data: ").append(getData()).append(","); + if (getPartitionKey() != null) + sb.append("PartitionKey: ").append(getPartitionKey()).append(","); + if (getEncryptionType() != null) + sb.append("EncryptionType: ").append(getEncryptionType()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof Record == false) + return false; + Record other = (Record) obj; + if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) + return false; + if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) + return false; + if (other.getApproximateArrivalTimestamp() == null ^ this.getApproximateArrivalTimestamp() == null) + return false; + if (other.getApproximateArrivalTimestamp() != null && other.getApproximateArrivalTimestamp().equals(this.getApproximateArrivalTimestamp()) == false) + return false; + if (other.getData() == null ^ this.getData() == null) + return false; + if (other.getData() != null && other.getData().equals(this.getData()) == false) + return false; + if (other.getPartitionKey() == null ^ this.getPartitionKey() == null) + return false; + if (other.getPartitionKey() != null && other.getPartitionKey().equals(this.getPartitionKey()) == false) + return false; + if (other.getEncryptionType() == null ^ this.getEncryptionType() == null) + return false; + if (other.getEncryptionType() != null && other.getEncryptionType().equals(this.getEncryptionType()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); + hashCode = prime * hashCode + ((getApproximateArrivalTimestamp() == null) ? 0 : getApproximateArrivalTimestamp().hashCode()); + hashCode = prime * hashCode + ((getData() == null) ? 0 : getData().hashCode()); + hashCode = prime * hashCode + ((getPartitionKey() == null) ? 0 : getPartitionKey().hashCode()); + hashCode = prime * hashCode + ((getEncryptionType() == null) ? 0 : getEncryptionType().hashCode()); + return hashCode; + } + + @Override + public Record clone() { + try { + return (Record) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e); + } + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/s3/S3EventNotification.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/s3/S3EventNotification.java new file mode 100644 index 00000000..5df14ea2 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/s3/S3EventNotification.java @@ -0,0 +1,310 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.s3; + +import org.joda.time.DateTime; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.List; + +/** +* A helper class that represents a strongly typed S3 EventNotification item sent +* to SQS, SNS, or Lambda. +*/ +public class S3EventNotification { + + private final List records; + + public S3EventNotification(List records) { + this.records = records; + } + + /** + * @return the records in this notification + */ + public List getRecords() { + return records; + } + + + public static class UserIdentityEntity { + + private final String principalId; + + public UserIdentityEntity(String principalId) { + this.principalId = principalId; + } + + public String getPrincipalId() { + return principalId; + } + } + + public static class S3BucketEntity { + + private final String name; + private final UserIdentityEntity ownerIdentity; + private final String arn; + + public S3BucketEntity(String name, UserIdentityEntity ownerIdentity, String arn) { + this.name = name; + this.ownerIdentity = ownerIdentity; + this.arn = arn; + } + + public String getName() { + return name; + } + + public UserIdentityEntity getOwnerIdentity() { + return ownerIdentity; + } + + public String getArn() { + return arn; + } + } + + public static class S3ObjectEntity { + + private final String key; + private final Long size; + private final String eTag; + private final String versionId; + private final String sequencer; + + @Deprecated + public S3ObjectEntity( + String key, + Integer size, + String eTag, + String versionId) + { + this.key = key; + this.size = size == null ? null : size.longValue(); + this.eTag = eTag; + this.versionId = versionId; + this.sequencer = null; + } + + @Deprecated + public S3ObjectEntity( + String key, + Long size, + String eTag, + String versionId) + { + this(key, size, eTag, versionId, null); + } + + public S3ObjectEntity(String key, Long size, String eTag, String versionId, String sequencer) { + this.key = key; + this.size = size; + this.eTag = eTag; + this.versionId = versionId; + this.sequencer = sequencer; + } + + public String getKey() { + return key; + } + + /** + * S3 URL encodes the key of the object involved in the event. This is + * a convenience method to automatically URL decode the key. + * @return The URL decoded object key. + */ + public String getUrlDecodedKey() { + return urlDecode(getKey()); + } + + private static final String DEFAULT_ENCODING = "UTF-8"; + + /** + * Decode a string for use in the path of a URL; uses URLDecoder.decode, + * which decodes a string for use in the query portion of a URL. + * + * @param value The value to decode + * @return The decoded value if parameter is not null, otherwise, null is returned. + */ + private static String urlDecode(final String value) { + if (value == null) { + return null; + } + + try { + return URLDecoder.decode(value, DEFAULT_ENCODING); + } catch (UnsupportedEncodingException ex) { + throw new RuntimeException(ex); + } + } + + /** + * @deprecated use {@link #getSizeAsLong()} instead. + */ + @Deprecated + public Integer getSize() { + return size == null ? null : size.intValue(); + } + + public Long getSizeAsLong() { + return size; + } + + public String geteTag() { + return eTag; + } + + public String getVersionId() { + return versionId; + } + + public String getSequencer() { + return sequencer; + } + } + + public static class S3Entity { + + private final String configurationId; + private final S3BucketEntity bucket; + private final S3ObjectEntity object; + private final String s3SchemaVersion; + + public S3Entity(String configurationId, S3BucketEntity bucket, S3ObjectEntity object, String s3SchemaVersion) { + this.configurationId = configurationId; + this.bucket = bucket; + this.object = object; + this.s3SchemaVersion = s3SchemaVersion; + } + + public String getConfigurationId() { + return configurationId; + } + + public S3BucketEntity getBucket() { + return bucket; + } + + public S3ObjectEntity getObject() { + return object; + } + + public String getS3SchemaVersion() { + return s3SchemaVersion; + } + } + + public static class RequestParametersEntity { + + private final String sourceIPAddress; + + public RequestParametersEntity(String sourceIPAddress) { + this.sourceIPAddress = sourceIPAddress; + } + + public String getSourceIPAddress() { + return sourceIPAddress; + } + } + + public static class ResponseElementsEntity { + + private final String xAmzId2; + private final String xAmzRequestId; + + public ResponseElementsEntity(String xAmzId2, String xAmzRequestId) + { + this.xAmzId2 = xAmzId2; + this.xAmzRequestId = xAmzRequestId; + } + + public String getxAmzId2() { + return xAmzId2; + } + + public String getxAmzRequestId() { + return xAmzRequestId; + } + } + + public static class S3EventNotificationRecord { + + private final String awsRegion; + private final String eventName; + private final String eventSource; + private DateTime eventTime; + private final String eventVersion; + private final RequestParametersEntity requestParameters; + private final ResponseElementsEntity responseElements; + private final S3Entity s3; + private final UserIdentityEntity userIdentity; + + public S3EventNotificationRecord(String awsRegion, String eventName, String eventSource, String eventTime, + String eventVersion, RequestParametersEntity requestParameters, + ResponseElementsEntity responseElements, S3Entity s3, + UserIdentityEntity userIdentity) { + this.awsRegion = awsRegion; + this.eventName = eventName; + this.eventSource = eventSource; + + if (eventTime != null) + { + this.eventTime = DateTime.parse(eventTime); + } + + this.eventVersion = eventVersion; + this.requestParameters = requestParameters; + this.responseElements = responseElements; + this.s3 = s3; + this.userIdentity = userIdentity; + } + + public String getAwsRegion() { + return awsRegion; + } + + public String getEventName() { + return eventName; + } + + public String getEventSource() { + return eventSource; + } + + public DateTime getEventTime() { + return eventTime; + } + + public String getEventVersion() { + return eventVersion; + } + + public RequestParametersEntity getRequestParameters() { + return requestParameters; + } + + public ResponseElementsEntity getResponseElements() { + return responseElements; + } + + public S3Entity getS3() { + return s3; + } + + public UserIdentityEntity getUserIdentity() { + return userIdentity; + } + } +} diff --git a/aws-lambda-java-events/src/main/java/lombok.config b/aws-lambda-java-events/src/main/java/lombok.config new file mode 100644 index 00000000..531bad71 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/lombok.config @@ -0,0 +1 @@ +lombok.getter.noIsPrefix = true diff --git a/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java new file mode 100644 index 00000000..8f1662cd --- /dev/null +++ b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java @@ -0,0 +1,36 @@ +package com.amazonaws.services.lambda.runtime.events; + +import org.junit.jupiter.api.Test; + +import java.time.Instant; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class APIGatewayV2CustomAuthorizerEventTest { + + private static final long TIME_EPOCH = 1601306426515L; + private static final String TIME = "28/Sep/2020:15:14:43 +0000"; + + @Test + public void testEpochLongAsAnInstant() { + APIGatewayV2CustomAuthorizerEvent customAuthorizerEvent = APIGatewayV2CustomAuthorizerEvent.builder() + .withRequestContext(APIGatewayV2CustomAuthorizerEvent.RequestContext.builder() + .withTimeEpoch(TIME_EPOCH) + .build()) + .build(); + + assertEquals(Instant.ofEpochMilli(1601306426515L), customAuthorizerEvent.getRequestContext().getTimeEpoch()); + } + + @Test + public void testTimeStringAsDateTime() { + APIGatewayV2CustomAuthorizerEvent customAuthorizerEvent = APIGatewayV2CustomAuthorizerEvent.builder() + .withRequestContext(APIGatewayV2CustomAuthorizerEvent.RequestContext.builder() + .withTime(TIME) + .build()) + .build(); + + assertNotNull(customAuthorizerEvent.getRequestContext().getTime()); + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/HttpUtils.java b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/HttpUtils.java new file mode 100644 index 00000000..d6ff1aa4 --- /dev/null +++ b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/HttpUtils.java @@ -0,0 +1,87 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class HttpUtils { + + private static final String DEFAULT_ENCODING = "UTF-8"; + + /** + * Regex which matches any of the sequences that we need to fix up after + * URLEncoder.encode(). + */ + private static final Pattern ENCODED_CHARACTERS_PATTERN; + static { + StringBuilder pattern = new StringBuilder() + .append(Pattern.quote("+")) + .append("|") + .append(Pattern.quote("*")) + .append("|") + .append(Pattern.quote("%7E")) + .append("|") + .append(Pattern.quote("%2F")); + + ENCODED_CHARACTERS_PATTERN = Pattern.compile(pattern.toString()); + } + + /** + * Encode a string for use in the path of a URL; uses URLEncoder.encode, + * (which encodes a string for use in the query portion of a URL), then + * applies some postfilters to fix things up per the RFC. Can optionally + * handle strings which are meant to encode a path (ie include '/'es + * which should NOT be escaped). + * + * @param value the value to encode + * @param path true if the value is intended to represent a path + * @return the encoded value + */ + public static String urlEncode(final String value, final boolean path) { + if (value == null) { + return ""; + } + + try { + String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); + + Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); + StringBuffer buffer = new StringBuffer(encoded.length()); + + while (matcher.find()) { + String replacement = matcher.group(0); + + if ("+".equals(replacement)) { + replacement = "%20"; + } else if ("*".equals(replacement)) { + replacement = "%2A"; + } else if ("%7E".equals(replacement)) { + replacement = "~"; + } else if (path && "%2F".equals(replacement)) { + replacement = "/"; + } + + matcher.appendReplacement(buffer, replacement); + } + + matcher.appendTail(buffer); + return buffer.toString(); + + } catch (UnsupportedEncodingException ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/models/s3/S3EventNotificationTest.java b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/models/s3/S3EventNotificationTest.java new file mode 100644 index 00000000..8a3cb072 --- /dev/null +++ b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/models/s3/S3EventNotificationTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +package com.amazonaws.services.lambda.runtime.events.models.s3; + +import com.amazonaws.services.lambda.runtime.events.HttpUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +public class S3EventNotificationTest { + + private List KEYS_REQUIRING_URL_ENCODE = Arrays.asList("foo bar.jpg", "foo/bar.csv", "foo<>bar"); + + @Test + public void testGetUrlDecodedKey() { + for (String testKey : KEYS_REQUIRING_URL_ENCODE) { + String urlEncoded = HttpUtils.urlEncode(testKey, false); + S3EventNotification.S3ObjectEntity entity = new S3EventNotification.S3ObjectEntity( + urlEncoded, 1L, "E-Tag", "versionId"); + Assertions.assertEquals(testKey, entity.getUrlDecodedKey()); + } + } +} diff --git a/aws-lambda-java-log4j/src/main/java/com/amazonaws/services/lambda/runtime/log4j/LambdaAppender.java b/aws-lambda-java-log4j/src/main/java/com/amazonaws/services/lambda/runtime/log4j/LambdaAppender.java deleted file mode 100644 index 72b268cb..00000000 --- a/aws-lambda-java-log4j/src/main/java/com/amazonaws/services/lambda/runtime/log4j/LambdaAppender.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.amazonaws.services.lambda.runtime.log4j; - -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.Layout; - -import com.amazonaws.services.lambda.runtime.LambdaRuntime; -import com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal; -import com.amazonaws.services.lambda.runtime.LambdaLogger; - -/** - * LambdaAppender is the custom log4j appender - * to be used in the log4j.properties file. - * You should not be required to use this class directly. - */ -public class LambdaAppender extends AppenderSkeleton { - - LambdaLogger logger = LambdaRuntime.getLogger(); - - public LambdaAppender() { - super(); - LambdaRuntimeInternal.setUseLog4jAppender(true); - } - - @Override - protected void append(LoggingEvent event) { - if(this.layout == null) { - logger.log(event.getLevel() + " " + event.getMessage()); - return; - } - logger.log(this.layout.format(event)); - //prints the Throwable from the log - if(layout.ignoresThrowable()) { - StringBuilder traceString = new StringBuilder(); - String[] s = event.getThrowableStrRep(); - if (s != null) { - int len = s.length; - for(int i = 0; i < len; i++) { - traceString.append(s[i]); - traceString.append(Layout.LINE_SEP); - } - } - logger.log(traceString.toString()); - } - } - - public void close() { - } - - public boolean requiresLayout() { - return true; - } -} diff --git a/aws-lambda-java-log4j2/README.md b/aws-lambda-java-log4j2/README.md index ae32f60a..40ca3c3a 100644 --- a/aws-lambda-java-log4j2/README.md +++ b/aws-lambda-java-log4j2/README.md @@ -10,17 +10,17 @@ Example for Maven pom.xml com.amazonaws aws-lambda-java-log4j2 - 1.0.0 + 1.2.0 org.apache.logging.log4j log4j-core - 2.8.2 + 2.13.2 org.apache.logging.log4j log4j-api - 2.8.2 + 2.13.2 .... @@ -62,13 +62,39 @@ If using maven shade plugin, set the plugin configuration as follows ``` +If you are using the [John Rengelman](https://github.com/johnrengelman/shadow) Gradle shadow plugin, then the plugin configuration is as follows: + +```groovy + +dependencies{ + ... + implementation group: 'com.amazonaws', name: 'aws-lambda-java-log4j2', version: '1.1.0' + implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4jVersion + implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4jVersion +} + +jar { + enabled = false +} +shadowJar { + transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer) +} + +build.dependsOn(shadowJar) + +``` + +If you are using the `sam build` and `sam deploy` commands to deploy your lambda function, then you don't +need to use the shadow jar plugin. The `sam` cli-tool merges itself the `Log4j2Plugins.dat` +files. + ### 2. Configure log4j2 using log4j2.xml file Add the following file `/src/main/resources/log4j2.xml` ```xml - + diff --git a/aws-lambda-java-log4j2/RELEASE.CHANGELOG.md b/aws-lambda-java-log4j2/RELEASE.CHANGELOG.md new file mode 100644 index 00000000..bda071f3 --- /dev/null +++ b/aws-lambda-java-log4j2/RELEASE.CHANGELOG.md @@ -0,0 +1,17 @@ +### May 05, 2020 +`1.2.0`: +- Updated `log4j-core` and `log4j-api` dependencies to `2.13.2` + +### April 28, 2020 +`1.1.1`: +- Added missing XML namespace declarations to `pom.xml` file ([#97](https://github.com/aws/aws-lambda-java-libs/issues/97)) +- Updated `nexusUrl` in `pom.xml` file ([#108](https://github.com/aws/aws-lambda-java-libs/issues/108)) +- Updated `aws-lambda-java-core` to `1.2.1` + +### November 21, 2017 +`1.1.0`: +- Changed `LambdaAppender.append()` to make use of `LambdaLogger` from `com.amazonaws:aws-lambda-java-core:1.2.0` + +### June 29, 2017 +`1.0.0`: +- Initial release of AWS Lambda Log4j2 support \ No newline at end of file diff --git a/aws-lambda-java-log4j2/pom.xml b/aws-lambda-java-log4j2/pom.xml index 42a8c991..c060f8e3 100644 --- a/aws-lambda-java-log4j2/pom.xml +++ b/aws-lambda-java-log4j2/pom.xml @@ -1,14 +1,16 @@ - + 4.0.0 com.amazonaws aws-lambda-java-log4j2 - 1.1.0 + 1.2.0 jar - AWS Lambda Java Log4j 2.8 Libraries + AWS Lambda Java Log4j 2.x Libraries - Support for using log4j 2.8 with AWS Lambda. + Support for using Log4j 2.x with AWS Lambda. https://aws.amazon.com/lambda/ @@ -28,29 +30,37 @@ https://aws.amazon.com/ + + + 1.8 + 1.8 + 2.13.2 + + + + + sonatype-nexus-staging + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + com.amazonaws aws-lambda-java-core - 1.2.0 + 1.2.1 org.apache.logging.log4j log4j-core - 2.8.2 + ${log4j.version} org.apache.logging.log4j log4j-api - 2.8.2 + ${log4j.version} - - - sonatype-nexus-staging - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - @@ -130,7 +140,7 @@ true sonatype-nexus-staging - https://oss.sonatype.org/ + https://aws.oss.sonatype.org/ false