Is it possible to rename an AWS Lambda function?

后端 未结 3 622
一个人的身影
一个人的身影 2021-02-06 20:24

I have created some Lambda functions on AWS for testing purposes (named as test_function something), then after testing I found those functions can be used in prod

相关标签:
3条回答
  • 2021-02-06 20:32

    You cannot rename the function, your only option is to follow the suggestions already provided here or create a new one and copypaste the code.

    It's a good thing actually that you cannot rename it: if you were able to, it would cease to work because the policies attached to the function still point to the old name, unless you were to edit every single one of them manually, or made them generic (which is ill-advised).

    However, as a best practice in terms of software development, I suggest you to always keep production and testing (staging) separate, effectively duplicating your environment.

    This allows you to test stuff on a safe environment, where if you make a mistake you don't lose anything important, and when you confirm that your new features work, replicate them in production.

    So in your case, you would have two lambdas, one called 'my-lambda-staging' and the other 'my-lambda-prod'. Use the ENV variables of lambdas to adapt to the current environment, so you don't need to refactor!

    0 讨论(0)
  • 2021-02-06 20:51

    My solution is to export the function, create a new Lambda, then upload the .zip file to the new Lambda.

    0 讨论(0)
  • 2021-02-06 20:56

    The closest you can get to renaming the lambda function is using an alias, which is a way to name a specific version of a lambda. The actual name of the function though, is set once you create it. If you want to rename it, just create a new function and copy the exact same code into it. It won't cost you any extra to do this (since you are only charged for execution time) so you lose nothing.

    For a reference on how to name versions of the lambda function check out the documentation here.

    0 讨论(0)
提交回复
热议问题