serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

Doesn't support new Docker `image` syntax

Open smcelhinney opened this issue 3 years ago • 9 comments

As per https://www.serverless.com/blog/container-support-for-lambda, you can now use the image property in function instead of a handler.

Error

  Type Error ---------------------------------------------
 
  TypeError: Cannot read property 'split' of undefined

is thrown at https://github.com/prisma-labs/serverless-plugin-typescript/blob/master/src/typescript.ts#L51 because it expects a handler property to be defined.

Required if you have (like I do) a mix of typescript handlers and Docker images in the same application.

smcelhinney avatar Jan 22 '21 13:01 smcelhinney

If you've found this issue from a search engine, a (less-than-ideal) solution I've used for deployment is to create a separate serverless.docker.yml file with your Docker based deployments, and run serverless deploy -c serverless.docker.yml

smcelhinney avatar Jan 22 '21 13:01 smcelhinney

Sorry, I found this issue by search... and I was doing, presumably, exactly what you said, yet, this not working for me:

Test based on example (which is awfully outdated).

Dockerfile:

FROM public.ecr.aws/lambda/nodejs:14
COPY handler.ts ./
CMD ["handler.hello"]

serverlessD.yml:

service: serverless-example
frameworkVersion: "2 || 3"
plugins:
  - serverless-plugin-typescript

provider:
  name: aws
  # runtime: nodejs14.x
  ecr:
    images:
      appimage:
        path: ./
  region: eu-west-2
  lambdaHashingVersion: 20201221

functions:
  hello:
    # handler: handler.hello
    image:
      name: appimage
    events:
      - http:
          path: hello
          method: get

Then:

$ sls deploy -s test -c serverlessD.yml

Serverless: Compiling with Typescript...
 
 Type Error ----------------------------------------------
 
  TypeError: Cannot read property 'split' of undefined
...

What am I doing wrong please?

alanwilter avatar Mar 30 '22 09:03 alanwilter

still happening anyone have work around? It does look like the plugin is looking for handler property, but for instance with function that is mapped to docker image does not have this property. Adding handler property with image gets error on serverless deploy.

jamesjoung avatar Jul 25 '22 03:07 jamesjoung

Add a specific runtime for your function that use the image. If you set it to python3.9 for example, the typescript plugin won't run against it. You may be able to set this to an empty string, but my container does actually use python 3.9

Rhysjc avatar Mar 24 '23 18:03 Rhysjc

Any luck resolving this issue running into it myself now, switching from a handler to image.

nathanbbarton avatar May 23 '23 20:05 nathanbbarton

Has any progress been made on this? This bug makes it impossible to use ECR images with typescript lambdas in serverless.

allavytalize avatar Dec 13 '23 17:12 allavytalize

Trying in 2024 and the error seems to still be present

demi-encentral avatar Jan 18 '24 15:01 demi-encentral

I have the same error here when defining a function that uses image instead of handler.

douglasgsouza avatar Feb 02 '24 15:02 douglasgsouza

@douglasgsouza I was able to deploy my app by removing the plugin from my project and building it with tsc

demi-encentral avatar Feb 02 '24 19:02 demi-encentral