Title: Day 51: Your CI/CD Pipeline on AWS - Part 2

ANSAR SHAIKANSAR SHAIK
3 min read

Happy Valentine's Day, DevOps enthusiasts! Welcome back to Day 51 of our 90DaysOfDevOps challenge. Today, we're diving deeper into AWS services, focusing specifically on AWS CodeBuild.

What is AWS CodeBuild?

AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy. It eliminates the need to manage build servers and allows you to scale your build infrastructure dynamically.

Task 01: Understanding the Buildspec file for CodeBuild

The Buildspec file is a YAML-formatted file that defines the build process for AWS CodeBuild. It includes commands, environment variables, and settings required to run your build. Let's take a look at a simple Buildspec file:

version: 0.1
phases:
  install:
    commands:
      - echo Installing nginx
      - sudo apt-get update
      - sudo apt-get install nginx -y
  build:
    commands:
      - echo Build started on 'date'
      - cp index.html /var/www/html/
  post_build:
    commands:
      - echo Configuring nginx

artifacts:
  files:
    - /var/www/html/index.html

This Buildspec file instructs CodeBuild to install dependencies, build the project using npm, and then deploy artifacts to an S3 bucket.

Task 02: Creating a Build Project in AWS CodeBuild

Now, let's walk through the step-by-step process of creating a build project in AWS CodeBuild using the Buildspec.yml file we defined earlier.

  1. Navigate to AWS CodeBuild: Go to the AWS Management Console and search for CodeBuild.

  2. Create Build Project:

    • Click on "Create build project."

    • Provide a name for your project.

    • Choose your source provider (e.g., AWS CodeCommit, GitHub).

    • Select the repository and branch to build from.

    • Specify the Buildspec file location (e.g., buildspec.yml).

  3. Configure Build Settings:

    • Choose your environment (e.g., Ubuntu, Amazon Linux).

    • Select a runtime version.

    • Define build commands and environment variables as needed.

    • Provide service role

  4. Artifact Settings:

    • Choose the type of artifacts to generate (e.g., Amazon S3, AWS CodeArtifact). S3 bucket and build project must be in same region

    • Specify the location to store artifacts (e.g., S3 bucket).

  1. Optional Settings:

    • Configure advanced settings like caching, IAM role, VPC settings, etc.
  2. Review and Create:

    • Review your build project configuration.

    • Click on "Create build project."

Once your build project is created, you can trigger builds manually or integrate them into your CI/CD pipeline using AWS CodePipeline.

  • Click on Start build for building the project

    • Build Successful

    • You can see artifacts are stored in S3 bucket

That's it for today! In Part 2, we'll explore more advanced features of AWS CodeBuild and integrate it into our CI/CD pipeline. Stay tuned, and happy coding!

Remember, DevOps is all about automation, collaboration, and continuous improvement. Keep up the great work, and don't forget to spread some love this Valentine's Day!

Keep learning, keep building, and happy Valentine's Day, fellow DevOps enthusiasts! ๐Ÿ’ปโค๏ธ๐Ÿš€

0
Subscribe to my newsletter

Read articles from ANSAR SHAIK directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ANSAR SHAIK
ANSAR SHAIK

AWS DevOps Engineer