Philipp Mayer
10/19/2023, 8:08 PMApiGatewayV2LambdaFunction
, which didn’t work, but it worked with ApiGatewayV1LambdaFunction
(http trigger). What do I have to configure to use v2, and is this recommended? 🙂s4nchez
10/19/2023, 8:11 PMPhilipp Mayer
10/19/2023, 8:17 PMdave
10/19/2023, 8:21 PMPhilipp Mayer
10/19/2023, 8:23 PMdave
10/19/2023, 8:24 PMPhilipp Mayer
10/19/2023, 8:24 PMdave
10/19/2023, 8:24 PMPhilipp Mayer
10/19/2023, 8:25 PMconst lambdaIntegration = new aws.apigatewayv2.Integration("hello-http4k-api-lambda-integration", {
apiId: api.id,
integrationType: "AWS_PROXY",
integrationUri: lambdaFunction.arn,
payloadFormatVersion: "1.0"
});
dave
10/19/2023, 8:25 PMPhilipp Mayer
10/19/2023, 8:26 PMprivate val dynamoDb = DynamoDb.Http(
region = Region.EU_CENTRAL_1,
credentialsProvider = { config.credentials },
http = config.http
)
private val table: DynamoDbTableMapper<Artist, String, Unit> =
dynamoDb.tableMapper<Artist, String, Unit>(
tableName = TableName.of("pedro-artists"),
hashKeyAttribute = Attribute.string().required("id"),
autoMarshalling = Jackson
)
When going with Kotshi, one than has to dive into KSP/gradle/code generation, which is quite a burden.
I know it’s nothing you can change as it’s rather a general JSON problem on the JVM and I really respect what you’re doing, but might be good to hear about some speedbumps from an “outsider” 🙂dave
10/19/2023, 8:56 PMPhilipp Mayer
10/19/2023, 9:03 PM"java.base/java.lang.ClassLoader.defineClass1(Native Method)",
"java.base/java.lang.ClassLoader.defineClass(Unknown Source)",
"java.base/java.security.SecureClassLoader.defineClass(Unknown Source)",
"java.base/java.net.URLClassLoader.defineClass(Unknown Source)",
"java.base/java.net.URLClassLoader$1.run(Unknown Source)",
"java.base/java.net.URLClassLoader$1.run(Unknown Source)",
"java.base/java.security.AccessController.doPrivileged(Unknown Source)",
"java.base/java.net.URLClassLoader.findClass(Unknown Source)",
"java.base/java.lang.ClassLoader.loadClass(Unknown Source)",
"java.base/java.lang.ClassLoader.loadClass(Unknown Source)",
"org.http4k.connect.amazon.dynamodb.KotshiDynamoDbJsonAdapterFactory.create(KotshiDynamoDbJsonAdapterFactory.kt:364)",
>> HERE IS THE FACTORY "org.http4k.connect.amazon.dynamodb.DynamoDbJsonAdapterFactory.create(DynamoDbMoshi.kt)",
"com.squareup.moshi.Moshi.adapter(Moshi.java:146)",
"com.squareup.moshi.Moshi.adapter(Moshi.java:106)",
"com.squareup.moshi.Moshi.adapter(Moshi.java:80)",
"org.http4k.format.ConfigurableMoshi.asFormatString(ConfigurableMoshi.kt:84)",
"org.http4k.connect.amazon.AwsJsonAction.toRequest(AwsJsonAction.kt:27)",
"org.http4k.connect.amazon.dynamodb.HttpDynamoDbKt$Http$1.invoke(HttpDynamoDb.kt:25)",
"org.http4k.connect.amazon.dynamodb.DynamodbExtensionsKt$scanPaginated$1.invoke(dynamodbExtensions.kt:327)",
"org.http4k.connect.amazon.dynamodb.DynamodbExtensionsKt$scanPaginated$1.invoke(dynamodbExtensions.kt:327)",
"org.http4k.connect.PagedKt$paginated$1.invoke(Paged.kt:42)",
"org.http4k.connect.PagedKt$paginated$1.invoke(Paged.kt:39)",
"kotlin.sequences.GeneratorSequence$iterator$1.calcNext(Sequences.kt:591)",
"kotlin.sequences.GeneratorSequence$iterator$1.hasNext(Sequences.kt:609)",
"kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214)",
"kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:311)",
"kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:303)",
"kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214)",
"kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:809)",
>>>> HERE IS THE SAVE TO THE DB "de.p10r.adapters.driven.db.ArtistRepository.save(ArtistRepository.kt:53)",
"de.p10r.domain.UserCommandHub.process(UserCommandHub.kt:24)",
"de.p10r.AppKt$App$1.invoke(App.kt:32)",
"de.p10r.AppKt$App$1.invoke(App.kt:32)",
"de.p10r.adapters.driving.http.ApiRoutesKt$ApiRoutes$2.invoke(ApiRoutes.kt:46)",
"de.p10r.adapters.driving.http.ApiRoutesKt$ApiRoutes$2.invoke(ApiRoutes.kt:45)",
"org.http4k.filter.ServerFilters$CatchAll$invoke$2$1.invoke(ServerFilters.kt:284)",
"org.http4k.filter.ServerFilters$CatchAll$invoke$2$1.invoke(ServerFilters.kt:282)",
"org.http4k.core.Http4kKt$then$2$1.invoke(Http4k.kt:15)",
"org.http4k.core.Http4kKt$then$2$1.invoke(Http4k.kt:15)",
"org.http4k.filter.ResponseFilters$ReportHttpTransaction$invoke$2$1.invoke(ResponseFilters.kt:48)",
"org.http4k.filter.ResponseFilters$ReportHttpTransaction$invoke$2$1.invoke(ResponseFilters.kt:46)",
"org.http4k.filter.ServerFilters$RequestTracing$invoke$3$1$1.invoke(ServerFilters.kt:96)",
"org.http4k.filter.ServerFilters$RequestTracing$invoke$3$1$1.invoke(ServerFilters.kt:92)",
"org.http4k.filter.ZipkinTracesKt.ensureCurrentSpan(ZipkinTraces.kt:105)",
"org.http4k.filter.ServerFilters$RequestTracing$invoke$3$1.invoke(ServerFilters.kt:92)",
"org.http4k.filter.ServerFilters$RequestTracing$invoke$3$1.invoke(ServerFilters.kt:91)",
"org.http4k.filter.ServerFilters$CatchAll$invoke$2$1.invoke(ServerFilters.kt:284)",
"org.http4k.filter.ServerFilters$CatchAll$invoke$2$1.invoke(ServerFilters.kt:282)",
"org.http4k.core.Http4kKt$then$2$1.invoke(Http4k.kt:15)",
"org.http4k.core.Http4kKt$then$2$1.invoke(Http4k.kt:15)",
"org.http4k.routing.TemplateRouter$match$1.invoke(Router.kt:154)",
"org.http4k.routing.TemplateRouter$match$1.invoke(Router.kt:154)",
"org.http4k.routing.RouterMatch$MatchingHandler.invoke(Router.kt:54)",
"org.http4k.routing.RouterMatch$MatchingHandler.invoke(Router.kt:53)",
"org.http4k.routing.RouterBasedHttpHandler.invoke(RouterBasedHttpHandler.kt:19)",
"org.http4k.routing.RouterBasedHttpHandler.invoke(RouterBasedHttpHandler.kt:13)",
"org.http4k.serverless.CommonKt$AddLambdaContextAndRequest$1$1.invoke(common.kt:14)",
"org.http4k.serverless.CommonKt$AddLambdaContextAndRequest$1$1.invoke(common.kt:11)",
"org.http4k.filter.ServerFilters$InitialiseRequestContext$invoke$1$1.invoke(ServerFilters.kt:345)",
"org.http4k.filter.ServerFilters$InitialiseRequestContext$invoke$1$1.invoke(ServerFilters.kt:342)",
"org.http4k.filter.ServerFilters$CatchAll$invoke$2$1.invoke(ServerFilters.kt:284)",
"org.http4k.filter.ServerFilters$CatchAll$invoke$2$1.invoke(ServerFilters.kt:282)",
"org.http4k.core.Http4kKt$then$2$1.invoke(Http4k.kt:15)",
"org.http4k.core.Http4kKt$then$2$1.invoke(Http4k.kt:15)",
"org.http4k.serverless.ApiGatewayFnLoader.invoke$lambda$0(ApiGatewayFnLoader.kt:27)",
"org.http4k.serverless.AwsLambdaEventFunction.handleRequest(AwsLambdaEventFunction.kt:15)",
"com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$2.call(EventHandlerLoader.java:905)",
"com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:245)",
"com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:197)",
"com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:187)"
]
}
But why does that only happen in prod, but not in local tests? 🤔
Just to clarify: Setting up Kotshi, annotating the class that will be saved and rerunning fixes it. It’s just not transparent from the outside. I’ll think about how to add this to the documentation.dave
10/19/2023, 9:37 PMPhilipp Mayer
10/19/2023, 9:44 PMfun DynamoDb.createPedroTables() =
createTable(
TableName = TableName.of("pedro-artists"),
KeySchema = KeySchema.compound(AttributeName.of("id")),
AttributeDefinitions = listOf(Attribute.string().required("id").asAttributeDefinition()),
ProvisionedThroughput = ProvisionedThroughput(
ReadCapacityUnits = 10,
WriteCapacityUnits = 10
)
)
The creation of tables works, but using it in the tableMapper doesn’t:
private val table: DynamoDbTableMapper<Artist, String, Unit> =
dynamoDb.tableMapper<Artist, String, Unit>(
tableName = TableName.of("pedro-artists"),
hashKeyAttribute = Attribute.string().required("id"),
)
Maybe also something for @Andrew O'Hara. I’ll look into it more closely tomorrow.Andrew O'Hara
10/19/2023, 10:21 PMdave
10/20/2023, 6:14 AMPhilipp Mayer
10/20/2023, 6:17 AMAndrew O'Hara
10/20/2023, 1:32 PMPhilipp Mayer
10/20/2023, 1:37 PMkotlin-reflect
, which makes sense, but for the MVP I used Jackson in the rest of the app, so Jackson (and as sub dependency kotlin-reflect) was on the classpath, also in production.
2. I was getting a kotshi error even though I was providing autoMarshalling = Jackson
.
Just adding Kotshi + annotating the class fixed it for me, so I didn’t bother diving deeper. My suggestion is that I will create a PR that calls out that kotshi + ksp + the correct annotation at the entity to save need to be in place to make everything work. Wdyt?dave
10/20/2023, 1:41 PMPhilipp Mayer
10/20/2023, 1:42 PM