AWS Layers support was added in v1.34. How it seems to work right now is that every time you deploy your serverless app the layers are packaged and uploaded. However, this is not what I expected. I thought we would only want to upload/update the layer package if a file was added/removed or changed.
Is there a reason it is implemented this way? I think my deployment time would be cut down by a minute or two if we didnβt upload unchanged layers because some of my layers are large (100mb +) so they take a while to upload.
Update: Iβve tried tweaking the cloudformation template in subsequent uploads so that the layer definition is identical. But it still creates a new layer version. As such, the work around above is your best solution it seems.
+1, having layers deployed only when they change would be really nice. The ffmpeg example in the blog post is about 50MB, which is quite long to upload and layers could definitely be the solution to upload it only once.
Iβve done this but I redeploy my layer (creating a new version) and my service still points to the previous version of the layer, how can I solve this? without having to redeploy my service?
I noticed this too. I think (IMO) it makes more sense to just not even use Serverless at all when creating layers. Iβll probably just manually create a layer to hold my audio binaries (ffmpeg, etc), and then use the ARN in my Serverless stacks to use those binaries. That way, if I recompile ffmpeg, I can create a new version, write in the description about what version of ffmpeg it is (or whatever), and then just update the Serverless config to point to the new version.
I was able to avoid the Excluding development dependencies by zipping the layers manually and referencing them with package>artifact>layer.zip , this helped me to reduce deployment time by 30 sec
I agree that the solution is to have your layers in another project. One huge reason to use layers is to share code, like writing your DB connection pooling once, deploy it as a layer, and have all your other projects use the layer to get connections. Itβs great for auth layers too so you donβt have to copy paste your auth code everywhere.
Keeping them in the same project is nice while you learn them, but to share them youβll find youβll eventually want to move them so youβre not always trying to figure out which app project the DB layer is in then having to redeploy that project to get DB changes out.