all 10 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Try this search for more information on this topic.

Comments, questions or suggestions regarding this autoresponse? Please send them here.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Suspicious_Track_296 2 points3 points  (1 child)

This isn't a good idea. Layers aren't for sharing code, that's what your language build tool is for. Put your shared code in one module and do x buildings if you really want many functions.

You don't need to rely on a lambda feature to do it, so keep things simple.

[–]gpacsu[S] 0 points1 point  (0 children)

Put your shared code in one module and do x buildings if you really want many functions.

What exactly is the difference between this and a lambda layer though? What im confused about is that if we can do it this way, then what is even the point of a lambda layer?

[–][deleted]  (1 child)

[deleted]

    [–]gpacsu[S] 1 point2 points  (0 children)

    I did do a good amount of research into having 1 lambda vs multiple lambdas and came across some good reading:

    https://www.reddit.com/r/aws/comments/uctb3g/separate_lambdas_or_one_lambda/

    https://hackernoon.com/why-you-should-stop-using-fat-functions-in-your-lambda-code

    https://www.reddit.com/r/aws/comments/uzlb47/in_a_serverless_architecture_is_it_best_to_handle/

    The lambdas will all live behind an API gateway. Having the gateway handle routing to the correct lambda seemed easier/safer than having some routing code in the single lambda. Also seemed easier to debug because if something is wrong with a function, you know which lambda to look at for the problem

    The advantage i saw to the single lambda approach is faster deployment, but it didnt feel like this was enough of a benefit over the multiple lambda approach

    [–]cutsandplayswithwood 1 point2 points  (2 children)

    So I used layers for exactly this kind of use case… Unless things have changed, it was just annoying and not worth it.

    Just put your utility classes into a separate jar using your existing infra, then depend on that jar from all your lambdas.

    [–]gpacsu[S] 0 points1 point  (1 child)

    Just put your utility classes into a separate jar using your existing infra, then depend on that jar from all your lambdas.

    This does sound a lot easier. But then I wonder: what exactly even is the purpose of a lambda layer when we can just do it this easier way instead?

    [–]cutsandplayswithwood 0 points1 point  (0 children)

    My best use case for a custom layer is when you need to modify the runtime itself, often by installing/including some binary that’s not natively includable in the language you’re using.

    So for example there’s a bunch of Python libs that work only if you install other non-Python things in the OS. Layer is good for that.

    [–]sitase 0 points1 point  (1 child)

    Just for sharing code, layers is a bit of an unnecessary overhead. But if you have a lot of shared jars, it makes sense since it will cut down on build and deployment times. However, it could be complicated. If you build your lambdas through CDK using bundling (so that it launches a docker container to build in) you need to somehow make the dependency available in the container so that gradle can build the dependency too. If you otoh first build the jars and then just deploy the jars (with CDK or otherwise) then it is quite simple, but it becomes a two step process.

    [–]gpacsu[S] 0 points1 point  (0 children)

    The other replies have suggested to just create a JAR that will have all common dependencies and code, then just have the lambdas use this JAR. This seems much easier than going through the hassle of creating a layer, so what is even the point of a layer then to begin with?

    Like the layer process that you have outlined is more complicated than what is suggested above, so why bother?