How to associate a lambda layer with a function in serverless.ts typescript using Ref

Viewed 22

I use serverless framework and i use the typescript template which generates a serverless.ts file.

I am working with lambda layers and im tyring to associate a lambda layer i have created with an existing function. However im getting a typescript error.

Type '{ Ref: string; }' is not assignable to type 'AwsLambdaLayers'. Object literal may only specify known properties, and 'Ref' does not exist in type 'AwsArn[]'.

    functions: {
        main: {
            handler: "handler.MainHandler",
            timeout: 300,
            layers: {
                Ref: "PrismaLambdaLayer",
            },
        },
    },

  layers: {
        prisma: {
            path: ".prisma-layer",
            description: "Layer for prisma clients",
            package: {
                patterns: [
                    "!nodejs/node_modules/@prisma/engines/*",
                    "!nodejs/node_modules/.prisma/**/libquery_engine-*",
                    "nodejs/node_modules/.prisma/**/libquery_engine-rhel-openssl-1.0.x.so.node",
                    "!nodejs/prisma/**",
                    "nodejs/prisma/*.db",
                ],
            },
        },
    },

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html

1 Answers

Looks like it has to be an array, and then you can add an object with the intrinsic ref.

layers: [{ Ref: "PrismaLambdaLayer" }],
Related