Is there any example that runs on Api Gateway + Ko...
# kotless
l
Is there any example that runs on Api Gateway + Kotless (ktor)?
t
Both of them runs:
<http://ktor.site.kotless.io|ktor.site.kotless.io>
and
<http://ktor.short.kotless.io|ktor.short.kotless.io>
l
None of them explictly use api gateway tho, right?
t
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
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
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
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
Hm, do you use Kotless custom domain?
it has built-in support of DNS records bounded to API Gateway
l
It's bounded to Route53. I'm currently experimenting on AWS free tier, and route53 isn't part of it
t
Oh, hm
l
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
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
No
t
It may be, that custom domain attached that way generates incorrect (from Kotless POV) routes to application
l
Butt it gets called
t
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
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
Hm, you mean APIGateway adds
basepath
to application with Custom Domain?
l
yes
t
And it does so only for custom domain?
l
Yes
t
Have you tried to set empty path during configuration of API?)
l
I think this guy explains it better
t
Yep, one moment
I'll take a look)
l
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
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
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/helloworld • https://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
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 🙂