5

I have several AWS Lambda Functions created using AWS Console and every function has some dependent APIs.Now I want to integrate the same with AWS CI/CD using CodeBuild, CodePipeline, and CloudFormation. But the problem is I'm unable to update the existing lambda functions that are not created using the CloudFormation Stack
Error Message ABC_Lambda already exists

Please note that if I create a new lambda using the CI/CD flow and then try to update it, that's working fine.

So my questions are

  1. How do I integrate the existing Lambda functions with AWS CI/CD workflow, without deleting and re-creating them?

  2. Is there any way or SAM_template config param that force the CloudFormation to update the existing lambda(created using AWS console/AWS Commandline tool).

4 Answers 4

2

As noted by @omuthu, if you have not created the Lambdas with Cloudformation, you cannot use Cloudformation to update them.

What you could do, is, in your CodeBuild step, use the update-function-code and update-function-configuration APIs to perform the operations you need. This though does not allow you to integrate with SAM due to the limitation mentioned above.

Sign up to request clarification or add additional context in comments.

Comments

1

AWS CloudFormation can update only resources created by the same stack.

The only possibility I can think of is to have CloudFormation Custom Resource.

The custom resource lambda should take care of handling any resources that are not created by the stack.

Learn more about it here (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources-lambda.html)

Hoe this helps !!!

1 Comment

Yes, I know that CF can only update the resources created by the same stack. And the Custom Resource method is only possible using CloudFormation to create/update/delete a custom resource, but how do I implement it using SAM template? I didn't find any article regarding this though I read "AWS::Serverless::CustomResource" written somewhere in aws serverless docs, but still don't know how to use it.
0

I would treat the Lambda functions you created in the console as prototypes and incrementally build a CloudFormation stack to replace the prototype. The trick to avoid the error message (ABC_Lambda already exists) is to only specify a logical name in CloudFormation and let it assign the physical name. If you call the Lambda functions by name or an API Gateway endpoint, you'll need to update the caller when you're ready to cut over to the new stack.

Comments

0

If you really needed to keep the old lambda functions around for legacy reasons you could create your new functions in Cloudformation, and update your old function manually to "proxy" and execute your new lambda code.

However, you will incur additional cost for the second lambda - and possibly hit your concurrent lambda request limit.

Over time you can update your old config / code to call just the new function, and eventually remove the old one entirely.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.