How to get latest Layer version with serverless framework for AWS Lambda

Viewed 1358

I'm trying to get latest Layer version with serverless framework by using serverless-latest-layer-version plugin. That plugin itself can get latest version of Layer but problem is whenever I made new deployment for both layers and function, layer version is always showing previous one of new layer version. Below is serverless.yml that to get latest version and applied it into function. Help me to suggest anything I missed to configure to latest layer version?

layers:
    my-layers:
      path: my-layers
      name: ${opt:stage, 'development'}-my-layer
      description: Save all common npm dependencies in single project
      compatibleRuntimes:
        - nodejs10.x

  functions:
    app:
      handler: index.handler
      layers:
        - arn:aws:lambda:ap-southeast-1:#{AWS::AccountId}:layer:${opt:stage, 'development'}-my-layer:latest
1 Answers

I think you could use a CloudFormationRef. See the documentation at Serverless (https://www.serverless.com/framework/docs/providers/aws/guide/layers/):

To use a layer with a function in the same service, use a CloudFormation Ref. The name of your layer in the CloudFormation template will be your layer name TitleCased (without spaces) and have LambdaLayer appended to the end. EG:

layers:
  test:
    path: layer
functions:
  hello:
    handler: handler.hello
    layers:
      - { Ref: TestLambdaLayer }
Related