5

I have by mistake given wrong name to AWS Lambda function. Now, I wanted to change its name. I found from the given stackoverflow question that best way to do that is just create a new function and copy the exact same code into it. Is it possible to rename an AWS Lambda function?

I am thinking to do that but I am just worried about data loss. Since my lambda is currently had 2 SNS triggers from where it is constantly receiving data. So, if I stop this lambda and create new one, I would lose some data during that time. Also, if I start the new lambda before deleting previous one, I would some entries in my datastore twice. So, is there any way I could use to get this done?

Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63
hatellla
  • 4,796
  • 8
  • 49
  • 101

2 Answers2

6

As @John Rotenstein said, it is not possible to rename an AWS Lambda. If you look at the documentation for Lambda (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html) you will see that updating FunctionName requires replacement of the entity.

If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.

If you are working with more complex systems, as it seems due to your note of SNS triggers, I would highly encourage you to take a look at CloudFormation (https://aws.amazon.com/cloudformation/), which uses code to manage deployed services. This not only has the benefit of allowing easier updates, but also enables other fun things which are inherent with code, such as integration with a VCS.

As a data loss prevention strategy while you perform this migration, you can create a new Lambda and point it to a staging database, delete the old Lambda, repoint your new Lambda to your production database, and push updates from your staging database into your production database. Check out the import/export docs (http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBPipeline.html) to see one method in which you might perform data migration.

Ming Slogar
  • 2,327
  • 1
  • 19
  • 41
  • Just a note. It's not always possible and acceptable to have staging and production databases in the same account. – Konstantin Pavlov May 28 '18 at 12:26
  • @KonstantinPavlov that's entirely fair. While it does become more difficult (especially when encryption is involved), it is still possible to stream data between resources in different accounts. Take a look at https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html for more info. – Ming Slogar May 29 '18 at 15:03
2

There is no rename function for an AWS Lambda function.

You could instead try creating an alias to a Lambda function that would allow both names to function simultaneously. (This is normally used when different versions exist.)

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470