Export existing CodePipeline/CodeBuild projects to Cloudformation
A

3

16

Is there a way to export existing CodePipeline/CodeBuild projects to Cloudformation?

I'm in the process of converting our existing CI/CD infrastructure into code so it would be easy to replicate them on other AWS regions.

Currently, we've done all our CodePipeline/CodeBuild projects through the AWS console in the browser and obviously, this is tedious and error-prone.

Abulia answered 20/12, 2017 at 0:4 Comment(1)
You can create the CodeBuild from scratch, as the CodeBuild itself does not have many configurations. The real challenge is in the dependencies. See this post for more details: runkiss.blogspot.com/2021/10/setup-codebuild-project-using.htmlMerriemerrielle
F
23

If you have some codepipeline already created use the cli to extract them as cloudformation.

The command is roughly this

aws codepipeline get-pipeline --name

It will get you back a codepipeline resource for cloudformation. You will be able to see where you need to enter in other resources like codebuild projects and s3 buckets or codecommit repos.

Be aware though that you will need to work through the template to ensure it will be taken as valid by cloudformation. The lines of the resource from the cli need to start with capital letters so it can be tedious to change that.

Another thing to know is a pipeline needed I think two roles which you can have in your template also and it's own bucket. All of these things cab be put in a single template making reproducible pipelines possible. Good luck!

Filigreed answered 20/12, 2017 at 10:22 Comment(6)
Not really the answer I hoped but it's the closest thing I can do. Thanks.Abulia
Yep its certainly not ideal. But once you do it once, you may be able to create your other pipelines in the future more easily.Filigreed
it's returned as JSON. anyone got a quick hack to extract cloudformation YAML?Gompers
I don't believe it comes back that way, although you should check if it comes back as JSON simply because JSON is set as the output format of the cli profile you are using. Text is another format possible for output from CLI commands.Filigreed
A: I had no idea this existed. I might love you a little. B: @JohnVandivier and anyone else coming here wondering, I just use CloudFormation designer. Set the template format to JSON, paste in the CLI results, then set it to YAML and it will convert it for you.Solorio
this is beautiful. so simple and to the point. you saved me hourss! thanks!Galimatias
A
11

And try this for the codebuild-project:

aws codebuild batch-get-projects --name --output json

Then you the CodeBuild Template. Hint:

aws help

or

aws codebuild help

will help you very well.

Anus answered 25/2, 2019 at 19:13 Comment(0)
S
5

I would normally suggest CloudFormer for generating CloudFormation templates from existing resources, but it does not appear that CodePipeline/CodeBuild are supported.

Your next best bet is to start with existing templates, and modify them according to your needs.

Here are some examples:

  1. https://github.com/awslabs/codepipeline-nested-cfn
  2. https://github.com/stelligent/dromedary/blob/master/pipeline/cfn/codepipeline-cfn.json
Selector answered 20/12, 2017 at 0:16 Comment(1)
Thank you for the examples.Abulia

© 2022 - 2024 — McMap. All rights reserved.