Kami menggunakan cookie penting serta alat serupa yang diperlukan untuk menyediakan situs dan layanan. Kami menggunakan cookie performa untuk mengumpulkan statistik anonim sehingga kami dapat memahami cara pelanggan menggunakan situs dan melakukan perbaikan. Cookie penting tidak dapat dinonaktifkan, tetapi Anda dapat mengklik “Kustom” atau “Tolak” untuk menolak cookie performa.
Jika Anda setuju, AWS dan pihak ketiga yang disetujui juga akan menggunakan cookie untuk menyediakan fitur situs yang berguna, mengingat preferensi Anda, dan menampilkan konten yang relevan, termasuk iklan yang relevan. Untuk menerima atau menolak semua cookie yang tidak penting, klik “Terima” atau “Tolak”. Untuk membuat pilihan yang lebih detail, klik “Kustomisasi”.
Sesuaikan preferensi cookie
Kami menggunakan cookie dan alat yang serupa (secara kolektif, “cookie”) untuk tujuan berikut.
Penting
Cookie ini diperlukan untuk menjalankan situs dan layanan kami dan tidak dapat dinonaktifkan. Cookie biasanya tersusun hanya sebagai tanggapan atas tindakan Anda di situs, seperti mengatur preferensi privasi, masuk, atau mengisi formulir.
Kinerja
Cookie kinerja menyediakan statistik anonim tentang cara pelanggan menavigasi situs kami sehingga kami dapat menyempurnakan pengalaman dan kinerja situs. Pihak ketiga yang disetujui dapat melakukan analisis atas nama kami, tetapi tidak dapat menggunakan data untuk tujuannya sendiri.
Diizinkan
Fungsional
Cookie fungsional membantu kami menyediakan berbagai fitur bermanfaat, mengingat preferensi Anda, dan menampilkan konten yang relevan pada situs. Pihak ketiga yang disetujui dapat mengatur cookie ini untuk menyediakan fitur tertentu pada situs. Jika Anda tidak mengizinkan cookie ini, maka beberapa atau semua layanan ini mungkin tidak berjalan dengan baik.
Diizinkan
Iklan
Cookie ini dapat diatur melalui situs kami oleh mitra iklan dan membantu kami mempersonalisasi konten pemasaran. Jika Anda tidak mengizinkan cookie, Anda akan mendapatkan iklan yang kurang relevan.
Diizinkan
Memblokir beberapa jenis cookie dapat memengaruhi pengalaman Anda di situs kami. Anda dapat mengubah preferensi cookie kapan saja dengan mengklik Preferensi cookie di footer situs ini. Untuk mempelajari lebih lanjut tentang bagaimana kami dan pihak ketiga yang disetujui menggunakan cookie di situs kami, silakan baca di jendela baru.
Tidak dapat menyimpan preferensi cookie
Kami hanya akan menyimpan cookie penting saat ini, karena kami tidak dapat menyimpan preferensi cookie Anda.
Jika Anda ingin mengubah preferensi cookie, coba lagi nanti menggunakan tautan di footer konsol AWS, atau hubungi dukungan jika masalah berlanjut.
Manage blue/green deployments of microservices to multiple accounts and Regions by using AWS code services and AWS KMS multi-Region keys - AWS Prescriptive Guidance
Created by Balaji Vedagiri (AWS), Ashish Kumar (AWS), Faisal Shahdad (AWS), Anand Krishna Varanasi (AWS), Vanitha Dontireddy (AWS), and Vivek Thangamuthu (AWS)
Summary
Notice: AWS CodeCommit is no longer available to new customers. Existing customers of AWS CodeCommit can continue to use the service as normal. Learn more
This pattern describes how to deploy a global microservices application from a central AWS account to multiple workload accounts and Regions in accordance with a blue/green deployment strategy. The pattern supports the following:
Software is developed in a central account, whereas workloads and applications are spread across multiple accounts and AWS Regions.
A single AWS Key Management System (AWS KMS) multi-Region key is used for encryption and decryption to cover disaster recovery.
The KMS key is Region-specific and has to be maintained or created in three different Regions for pipeline artifacts. A KMS multi-Region key helps retain the same key ID across Regions.
The Git workflow branching model is implemented with two branches (development and main) and code is merged by using pull requests (PRs). The AWS Lambda function that is deployed from this stack creates a PR from the development branch to the main branch. The PR merge to the main branch initiates an AWS CodePipeline pipeline, which orchestrates the continuous integration and continuous delivery (CI/CD) flow and deploys the stacks across accounts.
This pattern provides a sample infrastructure as code (IaC) setup through AWS CloudFormation stacks to demonstrate this use case. The blue/green deployment of microservices is implemented by using AWS CodeDeploy.
Prerequisites and limitations
Prerequisites
Four active AWS accounts:
A tools account to manage the code pipeline and maintain the AWS CodeCommit repository.
Three workload (test) accounts for deploying the microservices workload.
This pattern uses the following Regions. If you want to use other Regions, you must make the appropriate modifications to the AWS CodeDeploy and AWS KMS multi-Region stacks.
Tools (AWS CodeCommit) account: ap-south-1
Workload (test) account 1: ap-south-1
Workload (test) account 2: eu-central-1
Workload (test) account 3: us-east-1
Three Amazon Simple Storage Service (Amazon S3) buckets for the deployment Regions in each workload account. (These are called S3BUCKETNAMETESTACCOUNT1, S3BUCKETNAMETESTACCOUNT2 and S3BUCKETNAMETESTACCOUNT3 later in this pattern.)
For example, you can create these buckets in specific accounts and Regions with unique bucket names as follows (replace xxxx with a random number):
##In Test Account 1aws s3 mb s3://ecs-codepipeline-xxxx-ap-south-1 --region ap-south-1##In Test Account 2aws s3 mb s3://ecs-codepipeline-xxxx-eu-central-1 --region eu-central-1##In Test Account 3aws s3 mb s3://ecs-codepipeline-xxxx-us-east-1 --region us-east-1#Example##In Test Account 1aws s3 mb s3://ecs-codepipeline-18903-ap-south-1 --region ap-south-1##In Test Account 2aws s3 mb s3://ecs-codepipeline-18903-eu-central-1 --region eu-central-1##In Test Account 3aws s3 mb s3://ecs-codepipeline-18903-us-east-1 --region us-east-1
Limitations
The pattern uses AWS CodeBuild and other configuration files to deploy a sample microservice. If you have a different workload type (for example, serverless), you must update all relevant configurations.
Architecture
Target technology stack
AWS CloudFormation
AWS CodeCommit
AWS CodeBuild
AWS CodeDeploy
AWS CodePipeline
Target architecture
Automation and scale
The setup is automated by using AWS CloudFormation stack templates (IaC). It can be easily scaled for multiple environments and accounts.
Tools
AWS services
AWS CloudFormation helps you set up AWS resources, provision them quickly and consistently, and manage them throughout their lifecycle across AWS accounts and Regions.
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 Elastic Compute Cloud (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.
Git is an open-source, distributed version control system that works with the AWS CodeCommit repository.
Docker is a set of platform as a service (PaaS) products that use virtualization at the operating-system level to deliver software in containers. This pattern uses Docker to build and test container images locally.
cfn-lint and cfn-nag are open-source tools that help you review CloudFormation stacks for any errors and security issues.
Clone the sample repository into a new repository in your work location:
##In work location
git clone https://github.com/aws-samples/ecs-blue-green-global-deployment-with-multiregion-cmk-codepipeline.git
AWS DevOps
Package the Cloudformation resources.
In this step, you package the local artifacts that the CloudFormation templates reference to create the infrastructure resources required for services such as Amazon Virtual Private Cloud (Amazon VPC) and Application Load Balancer.
The templates are available in the Infra folder of the code repository.
Package and deploy the CloudFormation stacks for the infrastructure
Task
Description
Skills required
Clone the repository.
Clone the sample repository into a new repository in your work location:
##In work location
git clone https://github.com/aws-samples/ecs-blue-green-global-deployment-with-multiregion-cmk-codepipeline.git
AWS DevOps
Package the Cloudformation resources.
In this step, you package the local artifacts that the CloudFormation templates reference to create the infrastructure resources required for services such as Amazon Virtual Private Cloud (Amazon VPC) and Application Load Balancer.
The templates are available in the Infra folder of the code repository.
Push a sample (NGINX) image to the Amazon Elastic Container Registry (Amazon ECR) repository named web (as set in parameters). You can customize the image as required.
To log in and set the credentials for pushing an image to Amazon ECR, follow the instructions in the Amazon ECR documentation.
where Poc-Service refers to your sample application.
Verify that the services are accessible from the Application Load Balancer by using a fully qualified domain name (FQDN) or DNS from a browser or by using the curl command.
AWS DevOps
Push a sample image and scale Amazon ECS
Task
Description
Skills required
Push a sample image to the Amazon ECR repository.
Push a sample (NGINX) image to the Amazon Elastic Container Registry (Amazon ECR) repository named web (as set in parameters). You can customize the image as required.
To log in and set the credentials for pushing an image to Amazon ECR, follow the instructions in the Amazon ECR documentation.
where Poc-Service refers to your sample application.
Verify that the services are accessible from the Application Load Balancer by using a fully qualified domain name (FQDN) or DNS from a browser or by using the curl command.
AWS DevOps
Task
Description
Skills required
Create a CodeCommit repository in the tools account.
Create a CodeCommit repository in the tools account by using the codecommit.yaml template, which is in the code folder of the GitHub repository. You must create this repository only in the single Region where you plan to develop the code.
Create an S3 bucket for managing artifacts generated by CodePipeline.
Create an S3 bucket for managing artifacts generated by CodePipeline by using the pre-reqs-bucket.yaml template, which is in the code folder of the GitHub repository. The stacks must be deployed in all three workload (test) and tools accounts and Regions.
Create a multi-Region KMS key with primary and replica keys that CodePipeline will use. In our example, ToolsAccount1region - ap-south-1 will be the primary Region.
Set the CMKARN variables to pass to CodeBuild projects. The values are available in the output of the ecs-codepipeline-pre-reqs-KMS template stack (the key ID will be same in all Regions and starts with mrk-). Or, you can get the CMKARN values from the tools account. Export them in all account sessions:
Set up the CodeBuild project in the tools account.
Use the codebuild_IAM.yaml template from the code folder of the GitHub repository to set up AWS Identity and Access Management (IAM) for AWS CodeBuild in a single Region in the tools account:
Use the codedeploy.yaml template in the code folder of the GitHub repository to set up CodeDeploy in all three workload accounts. The output of mainInfraStack includes the Amazon Resource Names (ARNs) of the Amazon ECS cluster and Application Load Balancer listener.
Note
The values from the infrastructure stacks are exported already, so they are imported by the CodeDeploy stack templates.
Create a CodeCommit repository in the tools account.
Create a CodeCommit repository in the tools account by using the codecommit.yaml template, which is in the code folder of the GitHub repository. You must create this repository only in the single Region where you plan to develop the code.
Create an S3 bucket for managing artifacts generated by CodePipeline.
Create an S3 bucket for managing artifacts generated by CodePipeline by using the pre-reqs-bucket.yaml template, which is in the code folder of the GitHub repository. The stacks must be deployed in all three workload (test) and tools accounts and Regions.
Create a multi-Region KMS key with primary and replica keys that CodePipeline will use. In our example, ToolsAccount1region - ap-south-1 will be the primary Region.
Set the CMKARN variables to pass to CodeBuild projects. The values are available in the output of the ecs-codepipeline-pre-reqs-KMS template stack (the key ID will be same in all Regions and starts with mrk-). Or, you can get the CMKARN values from the tools account. Export them in all account sessions:
Set up the CodeBuild project in the tools account.
Use the codebuild_IAM.yaml template from the code folder of the GitHub repository to set up AWS Identity and Access Management (IAM) for AWS CodeBuild in a single Region in the tools account:
Use the codedeploy.yaml template in the code folder of the GitHub repository to set up CodeDeploy in all three workload accounts. The output of mainInfraStack includes the Amazon Resource Names (ARNs) of the Amazon ECS cluster and Application Load Balancer listener.
Note
The values from the infrastructure stacks are exported already, so they are imported by the CodeDeploy stack templates.
Clone the CodeCommit repository that was created in the codecommitrepoStack by using the git clone command, as described in the AWS CodeCommit documentation.
Update the input artifacts with the required details:
JSON file: Update AccountID in the file in three places of this file. Rename the three files to include the account IDs.
YAML files: Update the task definition ARN and version. Rename the three files to include the account IDs.
Modify the index.html file to make a few minor changes to the home page.
Copy the following files to the repository and commit:
Start or restart the pipeline and verify the results.
Access the service from the Application Load Balancer using by using an FQDN or DNS, and verify that the updates have been deployed.
Call and test the pipeline
Task
Description
Skills required
Push changes to the CodeCommit repository.
Clone the CodeCommit repository that was created in the codecommitrepoStack by using the git clone command, as described in the AWS CodeCommit documentation.
Update the input artifacts with the required details:
JSON file: Update AccountID in the file in three places of this file. Rename the three files to include the account IDs.
YAML files: Update the task definition ARN and version. Rename the three files to include the account IDs.
Modify the index.html file to make a few minor changes to the home page.
Copy the following files to the repository and commit: