Best practices for managing CodePipeline definition?

Unlike other pipeline tools where a pipeline.yml file is defined in the git repo, CodePipelines can be defined by

  1. Clicking through the wizard in the AWS console
  2. Creating a CloudFormation template

Obviously I prefer the latter, but what runs the CloudFormation template? Can I create a CodePipeline pipeline that manages itself?

Hahaha that would be funny to see… No I don’t think you can and I don’t recommend codepipeline for real world pipelining… Use it for small use cases like deploying an image from ECR to ECS or something.

You could bootstrap that by doing a manual deploy of a Cloudformation template that defines a CodePipeline for managing your Code* configurations from a more complicated Cloudformation template.

While CodePipeline isn’t the most featureful tool, if it’s the right tool for your job then there’s no real reason not to use it.

I don’t know if I got your question but you can configure the CodePipeline with Cloudformation.

The Pipeline start when you make a commit to a Repo in GitHub or Use their own CodeCommit to track commits. This really depends on how.you configure the CodePipeline.

When you make a commit your pipeline definition will start running and will go through each stage that you have defined.

We always deploy our CodePipelines to be self-updating. Basically:

  • Source (Checkout from GitHub)
  • Build => CodeBuild
  • Self-Mutate => CodeBuild that deploys the CloudFormation template for the pipeline
  • Deploy_staging
  • Deploy_prod

In the self-mutate step you just need to have a script that deploys the template with AWS CLI.

My question pertains to the pipeline definition itself. You mention

you can configure the CodePipeline with Cloudformation

but what runs the cloudformation template? If I want to make a change to the pipeline template, how to I keep the actual pipeline up to date without manually running cfn?

This is what I was looking for. Was wondering if a pipeline could manage its own definition or if it had to be managed by something else.

So there’s no non-manual AWS way I can keep my pipeline spec up to date?

Why is your pipeline changing often enough to worry about it instead of just manually running an update-stack from the CLI?

Are you looking for something like self-mutating pipelines with CDK?

https://aws.amazon.com/about-aws/whats-new/2020/07/announcing-cdk-pipelines-preview/

It’s not about frequency, it’s about confidence.

I need to trust that what’s defined on GitHub accurately reflects what’s on AWS before making changes.

This is awesome!

aws cloudformation get-template —template-name your stack —stage-name “Original” > orgtemplate.yml

diff orgtemplate.yml github tenplate

Of course you can limit who has access to update the template in the first place.

Isn’t the answer (pretty much always in these kind of scenarions) secret option 3) of just using Terraform?

Believe me, I too love Terraform more than cloudformation, but in this case it just defers the problem elsewhere.

If I’m using terraform to define CodePipeline pipelines, then what is running terraform apply?

I do appreciate your effort here, but I’m looking for an automated way to pull this off without needing to loop in another CI provider.

Oh ok, yes you can always do it from codebuild

You can use the same self managing pattern as cloudformation after the first initial setup. The main benefit is not having to use cloudformation.

Alternatively, just keep the pipeline state in git and manually run applies after merges to master.

It’s the same pattern as any git based ci/cd, you just have to do a bunch of implementation you’d get for free with circleci or github actions, but you don’t have to use IAM users.

You always have to bootstrap something. It can’t be turtles all the way down.

Terraform Cloud. Or Enterprise. Monitors the TF code repo, can be configured to auto apply.