https://kotlinlang.org logo
#http4k
Title
# http4k
p

Philipp Mayer

10/08/2023, 3:44 PM
The readme of the dynamo db adapter states
Note that there currently is no Fake implementation of the Dynamo adapter. You can use DynamoDB local instead.”
Although there is a fake implementation - is it a leftover? 🙂
✔️ 1
Seems to be that some guy named David Denton committed this in 2021..
d

dave

10/08/2023, 3:48 PM
Yes. That's a leftover. There is a pretty fully featured fake dynamo now! 🙃
p

Philipp Mayer

10/08/2023, 3:50 PM
That’s why I was surprised! I’ll create a PR. I’m just having trouble getting it to work - can the fake break when there’s a reverse proxy in-between? Currently debugging..
d

dave

10/08/2023, 3:51 PM
Don't worry about the docs - I'll update them to reflect what FakeDynamo does right now
❤️ 1
If you can repro it simply I can try to help. It should work very well (although some "SQL like" functions arent supported really - the main operations are)
p

Philipp Mayer

10/08/2023, 3:53 PM
I’m quite sure the problem is 70cm away from the display. I’m currently wrapping my head around “exploring the testing hyperpyramid”, I’m sure I just forgot to set something correctly.
I have the following scenario: Simple repository class that writes to dynamo db. The test for wiring up the repository and sticking a fake in it works well: Github Trying the same with wiring up the whole app fails with a 501: Github it’s quite a lot of code, I’ll see if I can boil down the example.
Running E2ETests gives me a 501 when calling DynamoDb, which is interesting Looks like the reverse proxy can’t route to the dynamo fake
d

dave

10/08/2023, 4:22 PM
The test fails with a 400 on my machine (from your repo). Is the table created?
p

Philipp Mayer

10/08/2023, 4:24 PM
I’m doing something wrong here, I’m quite sure about it. It fails with “No mapped host for: http://dynamo-db/“, which is the response by the reverse proxy
d

dave

10/08/2023, 4:25 PM
When running the e2e tests - I get a response 400 from dynamo - it can't find the artists table. Is there another test to run on main?
p

Philipp Mayer

10/08/2023, 4:26 PM
It will always tries to create the table on instantiation here, which is failing. The 400 gets raised when the test tries to read from the db. So first a 501 (from the reverse proxy), then a 400. Which makes me wonder: Is DynamoDB not set up when I try to create the table, but ready later on?
d

dave

10/08/2023, 4:27 PM
how can i recreate your 501?
p

Philipp Mayer

10/08/2023, 4:29 PM
If you run E2ETests, you’ll see in the logs:
Copy code
{"timestamp":"2023-10-08T16:28:10.592291Z","event":"Outgoing","data":{"uri":"<http://dynamo-db/>","method":"POST","status":501,"latency":0,"xuriTemplate":""}}
could not create table
RemoteFailure(method=POST, uri=/, status=501 Not Implemented, message=No mapped host for: <http://dynamo-db/>)
{"timestamp":"2023-10-08T16:28:10.808905Z","event":"Outgoing","data":{"uri":"<http://dynamo-db/>","method":"POST","status":400,"latency":36,"xuriTemplate":""}}
I pushed some more debugging stuff
d

dave

10/08/2023, 4:31 PM
this is a timing thing
you are trying to create the table before the http has been set in the network access I think
Copy code
networkAccess.http = routes(
      reverseProxyRouting(
        env[DYNAMO_URI].authority to dynamoDb,
        env[TELEGRAM_URI].authority to telegram,
        env[RA_URI].authority to ra,
        Uri.of("<http://pedro>").authority to ProdApp(env, events, networkAccess.debug()),
      )
    )
This code calls ProdApp and then once it's done it sets the http on networkaccess
p

Philipp Mayer

10/08/2023, 4:32 PM
Yes, this is also my guess! I’m just trying to figure out how this happens.
Ugh, this makes sense. I’m looking way too long on this already.
d

dave

10/08/2023, 4:33 PM
yep - you create the table on the creation of ArtistRepository
(which is done by creating your app)
Back to the drawing board. Thanks a ton.
d

dave

10/08/2023, 4:35 PM
np 🙂
you should probably just move the creation of the table completely out - otherwise you'll be trying to create it everytime you start you app 🙂
Ugh, this makes sense. I’m looking way too long on this already.
❤️ 1
p

Philipp Mayer

10/08/2023, 4:36 PM
Yes, this makes sense. 🙂 I think I went too deep into the pyramid, now it’s time to find a way out 😉
a

Andrew O'Hara

10/09/2023, 6:27 PM
Did you solve the reverse-proxy to dynamodb issue? The host must be
dynamodb
and not
dynamo-db
. You need to use the same host found in the service interface. For example:
Copy code
private val internet = reverseProxy(
    "dynamodb" to dynamo
)
And here's where you would find the host to use. https://github.com/http4k/http4k-connect/blob/master/amazon/dynamodb/client/src/main/kotlin/org/http4k/connect/amazon/dynamodb/DynamoDb.kt#L15
👍 1
❤️ 1
p

Philipp Mayer

10/10/2023, 7:26 AM
Thanks Andrew! I did resolve it - in the end it was exactly the problem David pointed out.