Lambda layer not attaching to function

I followed the example repo found here. The function deploys without issue however it does not have a layer attached per the Lambda console. I can manually add the layer from the console after the function has deployed. sls deploy -v doesn’t complain about anything. Any help is appreciated.

serverless.yml:

service: yumyum-layered

provider:
  name: aws
  runtime: nodejs8.10
  region: us-east-1

  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "dynamodb:*"
        - "s3:*"
        - "lambda:*"
        - "cognito:*"
      Resource: "*"

package:
  individually: true

functions:
  masterResolver:
    handler: functions/MasterResolver.handler
    layers:
      - arn:aws:lambda:us-east-1:XXXXXXX:layer:yumyum-coreLibraries:1

I’m also experiencing this issue did you find a solution.

Hi, my colleague had the same issue and updating his Serverless seemed to solve the issue.

The example from that repo you referenced doesn’t look valid. Also I don’t see your layers property in your serverless.yml file.

I’ve got it working with serverless.yml:

layers:
  test:
    path: layer # path of the dir you're expecting to import stuff from.
    name: ${self:provider.stage}-layerName
    description: Description of what the lambda layer does
    compatibleRuntimes:
      - nodejs8.10
    allowedAccounts:
      - ${self:provider.accountId}
    retain: true

and then my lambda function has a property of “layers” as well, like. You can reference the lambda layer by name case sensitive (e.g. Test, not test) appended with “LambdaLayer”:

layers:
  - {Ref: TestLambdaLayer}

Hi, you can consider this plugin, it attaches automatically layers to your lambda.

Node Version: 12.16.1
Serverless Framework Core Version: 1.73.1

I have the same problem and so far I haven’t been able to attach the layer to the lambda, below my serverless.yml:

service: product-types

frameworkVersion: '>=1.34.0 <2.0.0'

provider:
  name: aws
  runtime: nodejs12.x
  region: ${opt:region, 'sa-east-1'}
  stage: ${opt:stage, 'DEV'}
  layers:
    - arn:aws:lambda:${self:provider.region}:#{AWS::AccountId}:layer:Elasticsearch-NodeJS-${self:provider.stage}:latest

package:
  exclude:
    - ./**
  include:
    - src/**

functions:
  getAll:
    name: ProductTypes-GetAll-${self:provider.stage}
    handler: src/handlers.getAll
    runtime: ${self:provider.runtime}
    events:
      - http:
          method: get
          path: product-types
          cors: true
    layers: ${self:provider.layers}

  getByCode:
    name: ProductTypes-GetByCode-${self:provider.stage}
    handler: src/handlers.getByCode
    runtime: ${self:provider.runtime}
    events:
      - http:
          method: get
          path: product-types/{code}
          cors: true
    layers: ${self:provider.layers}

plugins:
  - serverless-latest-layer-version
  - serverless-offline
  - serverless-pseudo-parameters

I tried to use your plugin and was not successful