Layers upload on each deploy?


#1

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.


#2

I agree. Also, every time a deploy is made, a new version of the layer is generated even if we don’t make any change to it.


#3

You’re right about that. Looking into it now.

For the time being, one way to handle this is to have your layer & your service using the layer in different serverless projects.

In your service’s serverless.yml:

service: foobar
provider:
  name: aws
  language: python3.6
functions:
  hello:
    handler: handler.hello
    layers:
      - ${cf:foobar-layer-dev.FoobarLayerExport}

Then in a separate project managing your layer:

service: foobar-layer
provider:
  name: aws
layers:
  foobar:
    path: layer
resources:
  Outputs:
    FoobarLayerExport:
        Value:
          Ref: FoobarLambdaLayer
        Export:
          Name: FoobarLambdaLayer

#4

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.