diff --git a/spring-cloud-function-kotlin/pom.xml b/spring-cloud-function-kotlin/pom.xml index dc460afb6..1f42e42a4 100644 --- a/spring-cloud-function-kotlin/pom.xml +++ b/spring-cloud-function-kotlin/pom.xml @@ -20,6 +20,28 @@ org.springframework.cloud spring-cloud-function-context + + org.springframework.cloud + spring-cloud-function-adapter-aws + + + com.amazonaws + aws-lambda-java-events + 3.9.0 + provided + + + com.amazonaws + aws-lambda-java-core + 1.2.1 + provided + + + com.amazonaws + aws-lambda-java-serialization + 1.0.0 + provided + org.jetbrains.kotlin kotlin-stdlib-jdk8 diff --git a/spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/aws/AwsKotlinTestsTests.kt b/spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/aws/AwsKotlinTestsTests.kt new file mode 100644 index 000000000..36eafbbe3 --- /dev/null +++ b/spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/aws/AwsKotlinTestsTests.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2020-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 org.springframework.cloud.function.kotlin.aws + +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.cloud.function.adapter.aws.FunctionInvoker +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream + +/** + * @author Oleg Zhurakousky + */ +//@SpringBootTest() +//@ContextConfiguration(classes = [RestApplication::class, AwsKotlinTestsTests.TestConfiguration::class]) +open class AwsKotlinTestsTests { + var dynamoDbEvent:String = "{\n" + + " \"Records\": [\n" + + " {\n" + + " \"eventID\": \"dc1e145db718184b1c809f989335b168\",\n" + + " \"eventName\": \"INSERT\",\n" + + " \"eventVersion\": \"1.1\",\n" + + " \"eventSource\": \"aws:dynamodb\",\n" + + " \"awsRegion\": \"eu-central-1\",\n" + + " \"dynamodb\": {\n" + + " \"ApproximateCreationDateTime\": 1.689335433E9,\n" + + " \"Keys\": {\n" + + " \"version\": {\n" + + " \"N\": \"1\"\n" + + " },\n" + + " \"urlPath\": {\n" + + " \"S\": \"image/6037/2023/07/14/1d058d91-c9db-4c6a-aadf-4ab749de95d1.jpg\"\n" + + " }\n" + + " },\n" + + " \"NewImage\": {\n" + + " \"createdAt\": {\n" + + " \"N\": \"1689335427\"\n" + + " },\n" + + " \"provider\": {\n" + + " \"S\": \"XXXXXX\"\n" + + " },\n" + + " \"urlPath\": {\n" + + " \"S\": \"image/6037/2023/07/14/1d058d91-c9db-4c6a-aadf-4ab749de95d1.jpg\"\n" + + " },\n" + + " \"version\": {\n" + + " \"N\": \"1\"\n" + + " },\n" + + " \"status\": {\n" + + " \"S\": \"SUCCESS\"\n" + + " }\n" + + " },\n" + + " \"SequenceNumber\": \"1049234200000000032682603273\",\n" + + " \"SizeBytes\": 7869,\n" + + " \"StreamViewType\": \"NEW_IMAGE\"\n" + + " },\n" + + " \"eventSourceARN\": \"arn:aws:dynamodb:eu-central-1:xxxxxxx:table/example-results/stream/2022-12-06T16:23:45.860\"\n" + + " }\n" + + " ]\n" + + "}" + + @Test + open fun testDynamoDb() { + System.setProperty("MAIN_CLASS", KotlinAwsLambdasConfiguration::class.java.getName()) + System.setProperty("spring.cloud.function.definition", "handleDynamoDbEvent") + var invoker = FunctionInvoker() + + var targetStream = ByteArrayInputStream(this.dynamoDbEvent.toByteArray()) + var output = ByteArrayOutputStream() + invoker.handleRequest(targetStream, output, null) + } +} diff --git a/spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/aws/KotlinAwsLambdasConfiguration.kt b/spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/aws/KotlinAwsLambdasConfiguration.kt new file mode 100644 index 000000000..315c1b63a --- /dev/null +++ b/spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/aws/KotlinAwsLambdasConfiguration.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2021-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 org.springframework.cloud.function.kotlin.aws + +import com.amazonaws.services.lambda.runtime.events.DynamodbEvent +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.messaging.Message +import reactor.core.publisher.Flux +import java.util.function.Function + +/** + * @author Adrien Poupard + * + */ +@EnableAutoConfiguration +@Configuration +open class KotlinAwsLambdasConfiguration { + + @Bean + open fun handleDynamoDbEvent(): (Message) -> Unit { + return { println(it) } + } +}