Lambda with Platform SDK cold starts very slowly

Hi all! I need to create some Lambdas invoked from Genesys cloud data actions. We know that Java cold start (before it is cached by AWS) takes a lot longer then expected but it looks like when I add the platform SDK, the cold standby becomes seriously slow. I have a code which performs oauth client authentication and then it calls a conversation API, this takes sometimes over 30 seconds to complete when run first while later it completes in 2-3 seconds. The data action times out after 15 seconds which means a failed request in this case (and a long delay).

I can see that the lambda starts relatively quickly (within a second) but the next update is when the oauth authentication completes which takes 10-15 seconds (1 single command in the lambda code):
ApiResponse authResponse = apiClient.authorizeClientCredentials(clientId, clientSecret);
I know AWS introduced snapstart last year to help with this type of problem but it didnt help too much with my application and snapstart is NOT available in all aws zones anyway (for example it is not available in London).
I suspect the biggest problem is that the platform SDK is 60+ MB with 24k files in it and this doesnt help with the cold standby. If i remove the Genesys platform SDK then the lambda runs pretty quickly but I obviosly need the SDK.
Are there any best practices or recommendations to speed up cold standby when using Java and Genesys platform SDK?
Zsolt

If all you're doing is performing auth and making a single API request, I would suggest not using the SDK as it's only providing a very small amount of benefit in that context. (The SDK benefits the developer during development; it does not provide any runtime benefit and the package size can be a detractor in some use cases like lambdas and mobile apps.) For the best of both worlds, you can lift just the bits of code you need from the SDK's source: https://github.com/MyPureCloud/platform-client-sdk-java.

You could also look into using more performant languages for lambdas, like Go (compiles to a single binary file, my personal go-to language for lambda work) or node.js (surprisingly fast cold-start benchmarked times and the Platform Client SDK for node is very lightweight compared to Java (it doesn't have models or type checking).

Otherwise, you may want to look into caching the auth token in memory so every request doesn't have to re-authorize. This could be done by doing the authorization in the lambda's initializer instead of in the handler, or using a memory cache like Redis could allow it to be used by multiple cold start lambdas.

Thanks Tim, I guess not using the SDK is indeed a viable option when only a few API calls are made from the lambda. I already tested crafting an http post to get a token and it was quite fast.
Zsolt

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.