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 env.
Is it possible to rename the Lambda function? and how? Or should I create a new one and copy paste source code?
Once a Lambda function is created, you can not rename it or move it to another region. Like other resources in AWS, name and region of a Lambda function are in a unique ARN.
In Python, a lambda function is a single-line function declared with no name, which can have any number of arguments, but it can only have one expression.
Each alias has a unique ARN. An alias can point only to a function version, not to another alias. You can update an alias to point to a new version of the function. Event sources such as Amazon Simple Storage Service (Amazon S3) invoke your Lambda function.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With