typescript icon indicating copy to clipboard operation
typescript copied to clipboard

Provisioned concurrency variable doesn't work with typescript

Open trent-dailey opened this issue 3 years ago • 2 comments

Instead of using serverless.yml files we use serverless.ts files since our code is written in typescript and we wanted to keep things consistent. However this has caused a problem with being able to dynamically set the number of provisioned concurrency on deployment. We need this functionality as we do not need as much, or any, provisioned concurrency in non-production but do need it for production. Below is a snippet of our index.ts file for our helloworld lambda using serverless framework.

import schema from "./schema";
import { handlerPath } from "@libs/handlerResolver";

export default {
  handler: `${handlerPath(__dirname)}/handler.main`,
  provisionedConcurrency: parseInt("${self:custom.envConfig.helloProvisionedMin}"),
  events: [
    {
      http: {
        method: "post",
        path: "hello",
        request: {
          schemas: {
            "application/json": schema,
          },
        },
      },
    },
  ],
};

We have tried multiple iterations, shown here.

provisionedConcurrency: "${self:custom.envConfig.helloProvisionedMin}", // DOESNT WORK, ERRORS WITH TYPE ERROR
provisionedConcurrency: parseInt("${self:custom.envConfig.helloProvisionedMin}"), // DOESNT WORK AS IT DOES NOT PROVISION ANY CONCURRENCY
provisionedConcurrency: 1, // WORKS

I also attempted to set this directly in the serverless.ts file, instead of using the index.ts for each function, but have not been able to get that working either. Being able to dynamically set provisioned concurrency based on the environment being deployed to should be possible. How would we be able to accomplish this?

We are on serverless version 3.24.1 and @serverless/typescript version 3.21.0.

trent-dailey avatar Nov 17 '22 22:11 trent-dailey

I have also tried to get around this by adding // @ts-nocheck or // @ts-ignore to not get the type error as a workaround but those options do not work.

trent-dailey avatar Nov 19 '22 00:11 trent-dailey

How did you solve it?

PingQiao avatar May 06 '24 23:05 PingQiao

Also experiencing this same issue. Haven't figured out a solution. This is necessary for setting different values per environment.

cc @fredericbarthelet

chad-codes avatar Nov 07 '24 03:11 chad-codes

We ended up switching back to using serverless.yml and funtion.yml files as we kept running into different issues when trying to use typescript. It just works better when using yml.

trent-dailey avatar Nov 07 '24 14:11 trent-dailey