0

I am using terraform to create all the infra(CodePipeline, lambda, buckets) on AWS

currently, I've created a pipeline that builds the source zip file and puts it on s3 bucket but the lambda still keeps using the older source. So, I update the URL manually in the AWS console and it works. Now I want to automate the flow but available solutions are:

  • AWS SAM + CFT
  • Codebuild Stage to update the source using AWS CLI
  • Create a lambda that updates the source
  • Code Deploy + AWS SAM + CFT

I am not willing to use CFT at all since all of our code is in terraform and CFT requires me to create new lambdas instead of using old ones.

is there any other simpler way to update the lambda source through Codepipeline

1 Answer 1

0

The preferred way to deploy a Lambda via CodePipeline is using a CloudFormation Deploy action [1]. Since you are not looking to use CloudFormation, next option could be to run your terraform plan/apply commands from within a CodeBuild job that is part of the pipeline. You will need to provide the CodeBuild role required permission for resource creation (or export the credentials in Environment variabels for TF to use via this [2] method) and install the TF binary within install phase of buildspec.

Ref:

[1] Building a Continuous Delivery Pipeline for a Lambda Application with AWS CodePipeline - https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html

[2] How to retrieve Secret Manager data in buildspec.yaml

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

2 Comments

The reason I am not using CloudFormation is that it tries to create new lambda instead of updating existing lambda created by Terraform
If at all I have to use CodeBuild then using aws cli to update the lambda makes more sense to me

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.