Search code examples
node.jsamazon-web-servicesaws-lambdaserverlessaws-lambda-layers

AWS lambda layer code import throwing error while I trying to deploy nodejs serverless project


import { AppConfig } from "commons/environment/appconfig";
import { log } from 'commons/utils/logger';

Here I'm trying to import functions from my "commons" layer & trying to deploy the project but its throwing error that "commons/environment/appconfig doesn't exists". And its true because the layer doesn't exists in the local environment. Now how I will make it understand that take that files from the layer while deploying?

getAllNotificationRecord:
  handler: src/lambdaHandler/v1/notifications.getAllData
  layers:
    - arn:aws:lambda:us-east-1:112233445:layer:dev-common-layer:1
  events:
    - http:
        path: notification
        method: GET
        cors:
          origin: "*"
          headers:
            - Content-Type
            - X-Api-Key
            - accesstoken

here is the sample lambda function.


Solution

  • resolve: {
        alias: {
          'commons': false,
          './commons': false
        }
      }
    

    Just need to add a alias property in the resolve object of webpack.config.js file and then the folder name "commons" to false. So it will be ignored by the webpack while deploying the project.