The Secret Life of AWS: CodePipeline

 

The Secret Life of AWS: CodePipeline

Stop deploying manually. How to use AWS CodePipeline to automate your software delivery.





Part 16 of The Secret Life of AWS

Timothy sat at his desk, hitting the "Up" arrow on his terminal to find his last command.

aws cloudformation deploy --template-file template.yaml --stack-name Production

He pressed Enter. He waited. Then he realized he had forgotten to save the latest change to the file before running the command. He sighed, saved the file, and ran the command again.

Margaret stood behind him. "Timothy, why are you deploying from your laptop?"

"I have to update the stack," Timothy said. "I changed the Lambda function code, so I am running the update command."

"What if you are sick tomorrow?" Margaret asked. "What if your laptop breaks? Does the deployment stop?"

"Well... yes."

"That is a Single Point of Failure," Margaret said. "Your laptop is not a server. We need to decouple the deployment process from your personal machine."

"Today," she said, "we will automate this using AWS CodePipeline."

The Source: Version Control

Margaret opened the AWS Console and navigated to AWS CodePipeline.

"A pipeline is a linear workflow," she explained. "It consists of Stages. The first stage is always the Source."

"Right now, your code lives on your laptop," she continued. "That is the wrong place for the source of truth. The source of truth should be a Version Control System, like a Git repository."

She pointed to the screen. "We configure the Source Stage to watch your Git branch. Whenever you 'Push' a commit to the repository, AWS CodePipeline detects the change. It downloads your code and zips it into an Artifact."

"This Artifact is passed to the next stage," she added. "It ensures that every stage works on the exact same snapshot of code."

The Build: Testing and Packaging

"Once the Source stage succeeds, it passes the Artifact to the Build Stage," Margaret said.

"In this stage, we use a service like AWS CodeBuild. It spins up a temporary server, installs the necessary runtimes, and runs your validation commands."

"For example," she said, "if this were a Python app, it would run pytest. If it were a Node.js app, it would run npm test."

"If the tests fail?" Timothy asked.

"The Pipeline stops immediately," Margaret said. "The deployment is rejected. This prevents bad code from ever reaching production."

The Deploy: CloudFormation Integration

"If the Build passes, the Artifact moves to the Deploy Stage," Margaret said.

"This is where AWS CodePipeline triggers AWS CloudFormation."

"We configure this stage to take your CloudFormation template (which we wrote in the last episode) and automatically update the Stack. It does exactly what you were doing from your laptop, but it does it in a consistent, repeatable environment."

The Safety Valve: Manual Approval

Timothy nodded. "But wait—what if I push code that passes the tests but isn't ready for Production? Does it just go live automatically?"

"It can," Margaret said. "But for Production, we add a Manual Approval action."

She clicked a button on the screen. "Now, the pipeline will pause before the Deploy stage. It will send an email to the Lead Engineer. The deployment waits until a human clicks 'Approve'."

The Workflow

Timothy looked at the diagram on the screen.

  1. Source: Timothy pushes code to Git.
  2. Build: AWS runs the tests (pytest).
  3. Approval: The team leads signs off.
  4. Deploy: AWS updates the CloudFormation Stack.

"This removes the human effort," Timothy realized. "I don't have to remember the commands. I don't have to worry about my local settings."

"Correct," Margaret said. "You focus on writing the code. AWS CodePipeline focuses on delivering it."

She successfully connected his Git repository to the new pipeline.

"Go ahead," she said. "Push a change."

Timothy typed git push.

Seconds later, the AWS Console screen came to life. The Source stage turned green. Then the Build stage spun up.

"It is working," Timothy said.

"It is Engineering," Margaret corrected. "We do not rely on manual effort for repeated tasks. We rely on automation."


Aaron Rose is a software engineer and technology writer at tech-reader.blog and the author of Think Like a Genius.

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Insight: The Great Minimal OS Showdown—DietPi vs Raspberry Pi OS Lite

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison