Prefix AWS Lambda Names per environment

Hi guys,

I’m looking for help with setting up a lambda where different versions can be deployed at the same time to different environments within the same aws account…

The way I’m imagining this is I write function for a lambda called ‘MyFunction’, I want to deploy it to three environments: DEV, UAT, PROD

so I setup my serverless.yml with:

     ...function config...

but I tried this and it tried to create a function called literally ${env:ENVIRONMENT}MyFunction… so that didn’t work…

next I tried using:

    name: ${env:ENVIRONMENT}MyFunction
     ...function config...

and that DID work! But only on the first deploy… Thereafter complaining that the function already existed!

I thought that maybe the issue was that I had specified:

  versionFunctions: false

which I hoped meant that it would just overwrite the existing funciton, so I got rid of that, and yet the same error came about… So I get the impression that modifying the function’s name breaks that versionFunctions thing (because it can’t suffix the name any more?) does that make sense… Do you know what I am doing wrong / how I should achieve this?

I’m thinking that I could handle the versioning myself, but then I’d have to work out how to automatically cleanup the previous version of the lambda that was deployed (like i could add a version to the end of the name easily enough, but then it would just deploy that and I don’t think it would clean up the old lambda).

Is there something I’m missing?

Best wishes,

Joseph Roffey

For reference, here is the error and my environment info:

  Serverless Error ---------------------------------------
  An error occurred: MyFunctionLambdaFunction - DEVMyFunction already exists.

  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           8.12.0
     Serverless Version:     1.36.3

Please note, I have checked all the features added since 1.36.3 and none seemed to mention anything that should affect this, but I haven’t tried deploying with the latest version of serverless just yet (I’m using the latest docker image: “amaysim/serverless:1.36.3”)

I also tried sls deploy --force and got the same error.