Create a pipeline in AWS Regions that don’t support AWS CodePipeline - AWS Prescriptive Guidance

Create a pipeline in AWS Regions that don’t support AWS CodePipeline

Created by Anand Krishna Varanasi (AWS)

Code repository: invisible-codepipeline-unsupported-regions

Environment: PoC or pilot

Technologies: Infrastructure; DevOps

AWS services: AWS CodeBuild; AWS CodeCommit; AWS CodeDeploy; AWS CodePipeline

Summary

AWS CodePipeline is a continuous delivery (CD) orchestration service that’s part of a set of DevOps tools from Amazon Web Services (AWS). It integrates with a large variety of sources (such as version control systems and storage solutions), continuous integration (CI) products and services from AWS and AWS Partners, and open-source products to provide an end-to-end workflow service for fast application and infrastructure deployments.

However, CodePipeline isn’t supported in all AWS Regions, and it’s useful to have an invisible orchestrator that connects AWS CI/CD services. This pattern describes how to implement an end-to-end workflow pipeline in AWS Regions where CodePipeline isn’t yet supported by using AWS CI/CD services such as AWS CodeCommit, AWS CodeBuild, and AWS CodeDeploy.

Prerequisites and limitations

Prerequisites

  • An active AWS account

  • AWS Cloud Development Kit (AWS CDK) CLI version 2.28 or later

Architecture

Target technology stack

The following diagram shows a pipeline that was created in a Region that doesn’t support CodePipeline, such as the Africa (Cape Town) Region. A developer pushes the CodeDeploy configuration files (also called deployment lifecycle hook scripts) to the Git repository that’s hosted by CodeCommit. (See the GitHub repository provided with this pattern.) An Amazon EventBridge rule automatically initiates CodeBuild.

The CodeDeploy configuration files are fetched from CodeCommit as part of the source stage of the pipeline and transferred to CodeBuild. 

In the next phase, CodeBuild performs these tasks: 

  1. Downloads the application source code TAR file. You can configure the name of this file by using Parameter Store, a capability of AWS Systems Manager.

  2. Downloads the CodeDeploy configuration files.

  3. Creates a combined archive of application source code and CodeDeploy configuration files that are specific to the application type.

  4. Initiates CodeDeploy deployment to an Amazon Elastic Compute Cloud (Amazon EC2) instance by using the combined archive.

Pipeline creation in unsupported AWS Region

Tools

AWS services

  • AWS CodeBuild is a fully managed build service that helps you compile source code, run unit tests, and produce artifacts that are ready to deploy.

  • AWS CodeCommit is a version control service that helps you privately store and manage Git repositories, without needing to manage your own source control system.

  • AWS CodeDeploy automates deployments to Amazon EC2 or on-premises instances, AWS Lambda functions, or Amazon Elastic Container Service (Amazon ECS) services.

  • AWS CodePipeline helps you quickly model and configure the different stages of a software release and automate the steps required to release software changes continuously.

  • AWS Cloud Development Kit (AWS CDK) is a software development framework that helps you define and provision AWS Cloud infrastructure in code.

Code

The code for this pattern is available in the GitHub CodePipeline Unsupported Regions repository.

Epics

TaskDescriptionSkills required

Install the AWS CDK CLI.

For instructions, see the AWS CDK documentation.

AWS DevOps

Install a Git client.

To create commits, you can use a Git client installed on your local computer, and then push your commits to the CodeCommit repository. To set up CodeCommit with your Git client, see the CodeCommit documentation.

AWS DevOps

Install npm.

Install the npm package manager. For more information, see the npm documentation.

AWS DevOps
TaskDescriptionSkills required

Clone the code repository.

Clone the GitHub CodePipeline Unsupported Regions repository to your local machine by running the following command.

git clone https://github.com/aws-samples/invisible-codepipeline-unsupported-regions
DevOps engineer

Set parameters in cdk.json.

Open the cdk.json file and provide values for the following parameters:

"pipeline_account":"XXXXXXXXXXXX", "pipeline_region":"us-west-2", "repo_name": "app-dev-repo", "ec2_tag_key": "test-vm", "configName" : "cbdeployconfig", "deploymentGroupName": "cbdeploygroup", "applicationName" : "cbdeployapplication", "projectName" : "CodeBuildProject"

where:

  • pipeline_account is the AWS account where the pipeline will be built.

  • pipeline_region is the AWS Region where the pipeline will be built.

  • repo_name is the name of the CodeCommit repository.

  • ec2_tag_key is the tag attached to the EC2 instance that you want to deploy the code to.

  • configName is the name of the CodeDeploy configuration file.

  • deploymentGroupName is the name of the CodeDeploy deployment group.

  • applicationName is the CodeDeploy application name.

  • projectName is the CodeBuild project name.

AWS DevOps

Set up the AWS CDK construct library.

In the cloned GitHub repository, use the following commands to install the AWS CDK construct library, build your application, and synthesize to generate the AWS CloudFormation template for the application.

npm i aws-cdk-lib npm run build cdk synth
AWS DevOps

Deploy the sample AWS CDK application.

Deploy the code by running the following command in an unsupported Region (such as af-south-1).

cdk deploy
AWS DevOps
TaskDescriptionSkills required

Set up CI/CD for the application.

Clone the CodeCommit repository that you specified in the cdk.json file (this is called app-dev-repo by default) to set up the CI/CD pipeline for the application.

git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/app-dev-repo

where the repository name and Region depend on the values you provided in the cdk.json file.

AWS DevOps
TaskDescriptionSkills required

Test the pipeline with deployment instructions.

The CodeDeploy_Files folder of the GitHub CodePipeline Unsupported Regions repository includes sample files that instruct CodeDeploy to deploy the application. The appspec.yml file is a CodeDeploy configuration file that contains hooks to control the flow of application deployment. You can use the sample files index.html, start_server.sh, stop_server.sh, and install_dependencies.sh to update a website that’s hosted on Apache. These are examples—you can use the code in the GitHub repository to deploy any type of application. When the files are pushed to the CodeCommit repository, the invisible pipeline is initiated automatically. For deployment results, check the results of individual phases in the CodeBuild and CodeDeploy consoles.

AWS DevOps

Related resources