AWS Certified Developer - Associate

AWS CICD Developer Tools

CodePipeline Demo

This guide explains how to set up your first pipeline in CodePipeline, which automatically deploys an application to AWS Elastic Beanstalk when changes are pushed to a CodeCommit repository.

Below you will find detailed steps, technical diagrams, and code snippets to help you through the process.


Deploying Your Application to Elastic Beanstalk

Begin by downloading a simple demo application (e.g., the nodejs.zip file) from the AWS Elastic Beanstalk documentation page under tutorials and samples.

Follow these steps once you have the demo application:

  1. Create an Application
    Log in to the AWS Elastic Beanstalk console and create a new application, naming it web app.

  2. Create Environments
    Set up two environments: one for development and one for production.

    • Development Environment
      Click on "Create environment" and select the web server environment type. Name this environment webapp-dev. Upload your application code by selecting the nodejs.zip file, then choose Node.js as the platform. For cost efficiency, configure the environment with a single instance.

      The image shows the AWS Elastic Beanstalk Developer Guide webpage listing tutorials and sample applications.
      The image shows the AWS Elastic Beanstalk interface for creating a new application.
      The image shows the AWS Elastic Beanstalk console lacking any existing environments.
      The image shows the AWS Elastic Beanstalk configuration page for setting up environment details.

    • Production Environment
      Create another environment called webapp-env-prod. Choose Node.js as the platform and specify the existing application version (v1) instead of uploading a new file. Ensure the correct EC2 role and key pair are selected.

      The image shows the AWS Elastic Beanstalk configuration screen for uploading application code.
      The image shows the AWS Elastic Beanstalk configuration screen for service access settings.
      The image shows the AWS Elastic Beanstalk configuration screen for service access settings (production).

  3. Verify Deployment
    After a few minutes, confirm that both environments are successfully deployed by checking the URLs provided in the Elastic Beanstalk dashboards.

    • Production Environment Dashboard
      Dashboard for "Webapp-env-prod" showing details such as health status and platform information.

    • Development Environment Dashboard
      Dashboard for "Webapp-env-dev" after deployment showing that the application is running.


Setting Up the CodeCommit Repository

Next, set up a CodeCommit repository to store your application code, which will be tied into CodePipeline.

  1. Create the Repository
    Navigate to the CodeCommit service and create a repository named webapp.

  2. Push the Code
    Initialize your local Git repository, add your source files, commit your changes, and push to the remote repository. Replace the remote URL as needed.

    Tip

    You might see warnings about line endings (LF vs. CRLF); these warnings can be safely ignored.

    echo "# webapp2" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/Sanjeev-Thiyagarajan/webapp2.git
    git push -u origin main
    

    Refresh the CodeCommit page after pushing to verify that all files are present.


Configuring CodePipeline

Now that your application and repository are set up, configure CodePipeline to automate your deployment process.

  1. Create a New Pipeline
    Open the CodePipeline service page and create a new pipeline named web app pipeline. Select the latest pipeline version to take advantage of advanced execution features, including supersede and queued modes.

    • Service Role & Artifact Store
      Create a new service role for the pipeline and use the default S3 artifact store settings unless you need custom configurations.

      The image shows the AWS CodePipeline setup screen with artifact store configuration options.

  2. Configure the Source Stage
    Select CodeCommit as the source provider, choose the webapp repository, and select the main branch. For change detection, use CloudWatch events or periodic checks as recommended.

    The image shows an AWS CodePipeline source stage setup connected to GitHub, illustrating the configuration process.

  3. Skip the Build Stage
    Since this demo focuses on deploying to Elastic Beanstalk using CodeDeploy, skip the build stage. (Future demos may include integration with CodeBuild or Jenkins.)

    The image shows the CodePipeline interface where the build stage is being skipped.

  4. Configure the Deploy Stage
    Set up the deployment action to deploy your application to Elastic Beanstalk:

    • Choose Elastic Beanstalk as the deployment provider.
    • Select the application web app and the development environment webapp-dev.

    The image shows the AWS CodePipeline deploy stage configuration with Elastic Beanstalk settings.

  5. Review and Create the Pipeline
    Review your configuration settings and create the pipeline. It will automatically:

    • Pull code from CodeCommit in the source stage.
    • Deploy the code to Elastic Beanstalk in the deploy stage.

    The image shows the AWS CodePipeline interface indicating successful deployment stages.

  6. Examine Pipeline Details
    In the CodePipeline interface, you can view:

    • Source commit IDs
    • Input and output artifacts
    • Deployment details

    Your S3 artifact store contains the zipped artifacts.

    The image shows various details of the CodePipeline deployment stage.

    The image shows the AWS CodePipeline interface with both successful source and deploy stages.


Triggering Pipeline Executions with Code Changes

Demonstrate how pipeline automation works by modifying your application code in CodeCommit and reviewing the updated deployment process.

  1. Make a Code Change
    Edit the index.html file in CodeCommit (for example, change the text from “congratulations” to “this is version two”) and commit your changes.

    The image shows the AWS CodeCommit interface with an HTML file being edited.

  2. Observe the Pipeline Execution
    After committing, open the CodePipeline console to see the new execution:

    • The source stage will detect the new commit.
    • The deploy stage will update the development environment with the modified application.

    The image shows the Elastic Beanstalk environment dashboard after the update.
    The image shows the AWS CodeCommit repository interface listing files.
    The image shows the AWS CodePipeline interface indicating successful execution for the updated version.

  3. Verify the Change on Elastic Beanstalk
    Refresh the development environment URL to ensure that the application now displays version two.


Enhancing the Pipeline with a Production Deployment Stage

Improve your deployment process by adding a production stage that includes a manual approval step for enhanced security.

  1. Modify the Pipeline
    In the CodePipeline console, add a new stage called deploy prod.

  2. Add a Manual Approval Action
    Within the deploy prod stage, insert an action group for manual approval. For example, label this action leadership approval. This step requires team lead or management approval before proceeding with production deployment.

    The image shows the AWS CodePipeline "Edit Action" dialog where an action name and provider are selected.

  3. Deploy to Production
    Following the manual approval, add an action to deploy the code to the production environment using Elastic Beanstalk. Configure the action with:

    • Input artifact: the same artifact from the previous stage.
    • Environment: production (prod).
  4. Test the Pipeline Flow
    To test, modify the index.html file in CodeCommit (for example, update the text to “this is version three”) and commit the changes. The pipeline will then:

    • Update the development environment automatically.
    • Pause at the production stage for manual approval.

    Once approved, the pipeline will deploy the updated code to the production environment.

    The image shows the CodeCommit interface when editing an HTML file for a new commit.
    The image shows the AWS CodePipeline interface with the updated deployment process waiting for manual approval.

  5. Final Verification
    After manual approval and deployment, verify in Elastic Beanstalk that the production environment is running version three of the application.

    The image shows the AWS CodeCommit commits list for the "webapp" repository.

    You can inspect the deployed HTML code:

    <!DOCTYPE html>
    <html>
      <head>
        <title>Elastic Beanstalk</title>
        <style>
          body {
            color: #ffffff;
            font-family: Arial, sans-serif;
            font-size: 14px;
            -moz-transition-property: text-shadow;
            -moz-transition-duration: 4s;
            -webkit-transition-property: text-shadow;
            -webkit-transition-duration: 4s;
            text-shadow: none;
          }
          body.blurry {
            text-shadow: #fff 0px 0px 25px;
          }
          .linkColumn, .linksColumn {
            padding: 2em;
          }
          .textColumn {
            position: absolute;
          }
        </style>
      </head>
    </html>
    

    Once the production deployment is confirmed, the pipeline execution is complete.


Conclusion

This tutorial demonstrated how to configure a CodePipeline that triggers on changes in a CodeCommit repository and automatically deploys your application to AWS Elastic Beanstalk. With the added manual approval for production, you gain enhanced control over your deployments while automating routine tasks.

Happy deploying!

Watch Video

Watch video content

Practice Lab

Practice lab

Previous
CodePipeline