Definition:
What is AWS CodePipeline? Why are we using it?
With CodePipeline, devs can create a workflow that automatically moves the code changes through the build and deployment stage. In this project, a new push to the GitHub repository automtically triggers a build in CodeBuild (continuous integration), and then a deployment in CodeDeploy (continuous deployment)!
Using CodePipeline makes sure the deployments are consistent, reliable and happen automatically whenever the code is updated- with less risk of human errors. It saves time too.
Head to CodePipeline console on AWS
Select Create Pipeline → Select Build custom pipeline → Click Next → Name the pipeline → Under execution mode select Superseded
What is Execution mode?
Execution mode determines how CodePipeline handles multiple runs of the same pipeline.
In Superseded mode, if a new pipeline execution is triggered while another execution is already in progress, the newer execution will immediately take over and cancel the older one. This is perfect for making sure only the latest code changes are processed.
There are other execution modes available in CodePipeline:
- In Queued mode, executions are processed one after another. If a pipeline is already running, any new executions will wait in a queue until the current execution finishes.
- Parallel mode allows multiple executions to run at the same time, completely independently of each other. This can speed up the overall processing time if there are multiple branches or code changes that can be built and deployed concurrently.
Under Service roll, select new service role. Keep default role name
What is a service role?
A service role is a special type of IAM role that AWS services like CodePipeline use to perform actions on user’s behalf. It's like giving CodePipeline permission to access other AWS resources it needs to run the pipeline, such as S3 buckets for storing artifacts or CodeBuild for building the code.
Expand Advanced Settings → Leave everything as default (Artifact store, Encryption key and Variables)
What are Artifact store, Encryption key, and Variables?
- Artifact store: Without an artifact store, there's no way for the build outputs to be passed to deployment! This S3 bucket is where CodePipeline automatically saves the files created at each stage - like the source code from GitHub and the build artifacts from CodeBuild - making them available to the next stage in the pipeline.
- Encryption key: By default, CodePipeline encrypts everything in the artifact store using AWS managed keys. This keeps the code and build artifacts secure while they're being stored and transferred between stages. For most projects, this default encryption is perfectly sufficient.
- Variables: Right now information like version numbers or build timestamps might be manually tracked . Pipeline variables solve this by letting to pass dynamic values between different stages automatically. Variables become essential in more complex pipelines when you need information generated in one stage (like a build number) to be available in another stage (like deployment).
Click Next
Source stage config: In the Source provider dropdown, select GitHub (via GitHub App)
Under Repository name and branch name select correct repo and branch of GitHub repo used
For Output artifact format , leave it as CodePipeline default
What is Output artifact format?
Output artifact format determines how CodePipeline packages the source code it fetches from GitHub.
- CodePipeline default: This option packages the source code as a ZIP file, which is efficient for most deployment scenarios. It does not include Git metadata about the repository.
- Full clone: This option provides a full clone of the Git repository as an artifact, including Git history and metadata. This is useful if the build process requires Git history, but it results in a larger artifact size.
Check the Webhook box under Webhook events
What are Webhook events?
Webhook events let CodePipeline automatically start the pipeline whenever code is pushed to a specified branch in GitHub. This is what makes the pipeline truly "continuous" – it reacts to code changes in real-time
How do Webhooks work?
Webhooks are like digital notifications. When webhook events are enabled, CodePipeline sets up a webhook in the GitHub repository. This webhook is configured to listen for specific events, such as code pushes to the master branch.
Whenever code is pushed to the master branch, GitHub sends a webhook event (a notification) to CodePipeline. CodePipeline then automatically starts a new pipeline execution in response to this event. It's a seamless way to automate the CI/CD process
Click Next → Build stage → In the Build provider dropdown, select Other build providers → AWS CodeBuild
What is the Build stage?
The Build stage is where the source code gets compiled and packaged into something that can be deployed.
Under Project name dropdown , select the created CodeBuild project name
For Environment variables, Build type, and Region leave them as default
Under Input artifacts, Source Artifact to be selected as default
What are Input artifacts?
Input artifacts are the outputs from the previous stage that are used as inputs for the current stage. In the Build stage, SourceArtifact is being used, which is the ZIP file containing the source code that was outputted by the Source stage.