https://kotlinlang.org logo
#kotless
Title
# kotless
l

LeoColman

07/19/2020, 5:25 PM
Is there any example that runs on Api Gateway + Kotless (ktor)?
t

TanVD

07/19/2020, 5:39 PM
Both of them runs:
<http://ktor.site.kotless.io|ktor.site.kotless.io>
and
<http://ktor.short.kotless.io|ktor.short.kotless.io>
l

LeoColman

07/19/2020, 5:41 PM
None of them explictly use api gateway tho, right?
t

TanVD

07/19/2020, 5:42 PM
Kotless would not use API Gateway explicitly, it will generate it from code
You can use
generate
task and see
APIGateway
resources in generated Terraform code 🙂
So, Kotless always use APIGateway (in case of AWS), but it is not stated explicitly
l

LeoColman

07/19/2020, 5:44 PM
The APIs work if I'm using that randomized string for the api, but not for a custom domain
I guess this is api gateway's fault, but idk how to solve this with kotless
t

TanVD

07/19/2020, 5:46 PM
Hm, where do you use randomized string? You mean as name of Rest API?
BTW, note that to use custom domain you need certificate in Virgina
l

LeoColman

07/19/2020, 5:49 PM
For the path /hello/world Api gateway creates API endpoint: https://XXXXXXXYYYYYY.execute-api.us-east-1.amazonaws.com/1/hello/world
Calling that directly works, but when adding it to a custom api gateway endpoiint doesn't
When adding the custom domain to API gateway itself
t

TanVD

07/19/2020, 5:49 PM
Hm, do you use Kotless custom domain?
it has built-in support of DNS records bounded to API Gateway
l

LeoColman

07/19/2020, 5:50 PM
It's bounded to Route53. I'm currently experimenting on AWS free tier, and route53 isn't part of it
t

TanVD

07/19/2020, 5:50 PM
Oh, hm
l

LeoColman

07/19/2020, 5:51 PM
I don't think this is an issue with Kotless. It's probably a problem with AWS itself
It adds extra path to the URL, and then Kotless + Ktor can't find it. And it seems there isn't a way to wildcard that extra path
t

TanVD

07/19/2020, 5:52 PM
Well, yeah, probably. Kotless works with DNS-aliased applications in a pretty same fashion it does with anonymous applications. So it should not give 404
Do you have any errors in cloudwatch log of application?
l

LeoColman

07/19/2020, 5:54 PM
No
t

TanVD

07/19/2020, 5:54 PM
It may be, that custom domain attached that way generates incorrect (from Kotless POV) routes to application
l

LeoColman

07/19/2020, 5:54 PM
Butt it gets called
t

TanVD

07/19/2020, 5:55 PM
Well, you can try to enable info level of logging to see the whole trace of execution
In that case we would know at least what is going on and what route Kotless see in request
Oh, hm
l

LeoColman

07/19/2020, 5:56 PM
I did. Api Gateway maps a different endpoint, and I can't get Kotless + Ktor to identify it. For example https://my.customdomain/1/basepath/hello/world
And I can't get that to be wildcarded
I can't add it as part of the path either, or else kotless will generate an api with that path as part of it. And this won't be supported again by API Gateway
t

TanVD

07/19/2020, 5:58 PM
Hm, you mean APIGateway adds
basepath
to application with Custom Domain?
l

LeoColman

07/19/2020, 5:58 PM
yes
t

TanVD

07/19/2020, 5:59 PM
And it does so only for custom domain?
l

LeoColman

07/19/2020, 5:59 PM
Yes
t

TanVD

07/19/2020, 5:59 PM
Have you tried to set empty path during configuration of API?)
l

LeoColman

07/19/2020, 5:59 PM
I think this guy explains it better
t

TanVD

07/19/2020, 5:59 PM
Yep, one moment
I'll take a look)
l

LeoColman

07/19/2020, 6:00 PM
Have you tried to set empty path during configuration of API?)
I can't, as I'm using Kotless to define multiple APIs
And to define multiple apis we need to define the path
t

TanVD

07/19/2020, 6:10 PM
You mean you have Kotless application, that has few parts -- each is a separate API? And you need to map those paths to according DNS records?
Could you give an example of what you are trying to do?) It may help a bit 🙂
l

LeoColman

07/19/2020, 6:20 PM
Sure! Thank you for your patience! Let's say I have 2 teams. Team 1 works on
HelloWorld
project and Team 2 works on
HiWorld
project. Both the teams define their APIs: • /helloworld • /hiworld And now I want to deploy both to an API gateway, as we're serving these apis do an external client. I want both to be indexed under
api.hi
, so • https://api.hi/helloworldhttps://api.hi/hiworld Each API is defined in its own Kotless application, as both teams are doing entire different applications.
Today I can do that via
serverless
It seems that with Kotless I can do it with a single project, but that seems a little bit counter intuitive, as I would have to put all functions under the same application
It's probably way out of scope for what Kotless is usually used for, but I'm trying to replicate this usecase to test Kotless' as an alternative for our typescript stuff
I can open an issue if you think it's more appropriate
t

TanVD

07/19/2020, 6:36 PM
Yeah, it would be very nice of you. As for use-case. In general it means that you have two different applications that should end up being one APIGateway under different base paths. This use-case is not supported right now, unfortunately. As an alternative, you can use different third level names, like
hi.api.hi
and
hello.api.hi
I would say, that for a big projects that approach is also preferrable -- it makes links shorter and looks cleaner in address panel of browser.
Still, I would consider implementation of your use-case as well, if you would create an issue 🙂
5 Views