DevFlow

DevOverflow

Search
Menu
DevFlow

DevOverflow

Home menu icon

Home

Community menu icon

Community

Collections menu icon

Collections

Find Jobs menu icon

Find Jobs

Tags menu icon

Tags

Ask a question menu icon

Ask a question

    Menu

    Top Questions

    How to center a div?

    chevron

    How to do code parsing with React.js and NextJS?

    chevron

    How to get better at Nextjs?

    chevron

    Postgres: upgrade a user to be a superuser? ?

    chevron

    This is another test question

    chevron

    Popular Tags

    nextjs

    6

    React

    4

    next.js

    3

    reactjs

    3

    css

    3

    Profile

    Juan Cruz Cáceres

    upvote

    0

    downvote

    0

    star

    How do I include a JavaScript Lambda layer into a TypeScript Serverless Framework project?

    clock icon

    Asked 9 months ago

    message

    0 Answers

    eye

    1 Views

    0

    I'm working with an AWS Lambda Layer called "helpers". It is written in JavaScript as an ES module. I'm trying to set up a new TypeScript project using Serverless Framework. I want to import the layer that's on the account. This is my serverless file.

    service: stub
    frameworkVersion: "3"
    
    custom:
      aws:
        layers:
          helpers:
            version: 1
      basePath: /stub
      esbuild:
        external:
          - helpers
    
     plugins:
      - serverless-esbuild
    
    // ...
    
    functions:
      hello:
        handler: handler.hello
        events:
          - http:
              path: ${self:custom.basePath}
              method: get
        layers:
          - {layer_arn_from_custom}
    
    

    my handler is:

    import { createLogger } from 'helpers';
    
    export const hello = (event) => {
      const logger = createLogger();
      // ...
    }
    

    Serverles-esbuild cannot tell "helpers" is a Lambda layer and cannot resolve it properly. Even though the layer is associated with the Function (confirmed in the AWS console), executing the Function results in an import error. Adding a .d.ts file for "helpers" did not fix the problem.

    aws lambda
    typescript

    Write your answer here

    0 Answers