Coder Social home page Coder Social logo

issabayevmk / multiple-account-cdk-cicd-pipeline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/multiple-account-cdk-cicd-pipeline

0.0 0.0 0.0 3.87 MB

In this guide, we will introduce a way to build up CI/CD piplelines to realize services multi account/region deployments using CDK.

License: MIT No Attribution

JavaScript 8.50% TypeScript 91.50%

multiple-account-cdk-cicd-pipeline's Introduction

CI/CD Pipelines with CDK - Multi Account/Region Deployments

This project is foundation for secure AWS infrastructure deployment through CI/CD pipelines using the CDK to realize multi account/region deployments. An example use case for this is deployment of S3 bucket to multiple environments such as Bitstamp Development and Bitstamp Scratch.

 

Stack Architecture

 

The following diagram shows the pipeline and target accounts’ regional architecture. The entire architecture spans four accounts. One account is for the deployment pipeline, and the other three accounts are the accounts that the application is deployed to:

CI/CD Pipeline with CDK - Multi Account/Region Deployments Architecture

 

Regional CDK Bootstrapping

Each account region combo that is deployed to must be bootstrapped. Since it is a cross-account deployment, a trust must be established during this process.

Deploying AWS CDK apps into an AWS environment may require that you provision resources the AWS CDK needs to perform the deployment. These resources include an Amazon S3 bucket for storing files and IAM roles that grant permissions needed to perform deployments. The process of provisioning these initial resources is called bootstrapping.

  1. For each target account/region run the following CLI command (Must be ran as user with appropriate privs in the target account):
    cdk bootstrap --trust <pipelineAccountId> --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess aws://<targetAccountId>/<targetRegion> --profile <yourProfileNameForTargetAccount>
    

Example: cdk bootstrap --trust 118379544242 --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess aws://603325786329/eu-west-1 --profile 603325786329_SecOps

  1. Given we are deploying to 2 regions in 2 different accounts, we must run this command 4 times

 

Initial Deployment of Pipeline

 

Pipeline Overview

./cdk/bin/pipeline.ts: Creation of CDK App for Pipeline

./cdk/lib/cdk-pipeline-stack.ts: Definition of stacks to deploy, as well as environments to deploy to.

 

Github Access

  1. Create a github token here. Set the permission as below

    github_repo

  2. In pipeline account/region, create Secret Manager secret to store access token for GitHub repo. The token must stored as a plaintext secret with a name of github-token:

    github_token

 

Deploy Pipeline

  1. Clone the repo and run command. When prompted to create security groups/deploy, accept.

    cdk deploy CdkPipelineStack
    
  2. Navigate to CodePipeline in Console and cancel the initial build.

  3. Set Env Vars in the Build step of the pipeline as below.

    edit_env

    env_setting

 

Configure Pipeline Role

In pipeline account, create a Policy for each target account to allow Pipeline role to assume Roles created during bootstrap process

  1. Get CDK prefix from a target account

    prefix

  2. Create policy for all 3 accounts

    pipeline_policy

  3. Attach all 3 policies to the Pipeline Build role (Very similar to what we did for cross account access in console)

    attach_role

 

Run Pipeline

Navigate to Pipeline and Release Changes, app resources will be deployed in three accounts and two regions in each account.

Waves can be used to deploy multiple stages in parallel. In this example:

  • DEV and QA
  • PRD and STG Primary
  • PRD and STG Secondary

release_change

 

App Architecture

App structure contains three stacks:

  • VPC: Core networking
  • RDS: RDS Postgres Instance (or read replica in multi-region deployment)
  • API: Lambda w/ VPC attachment and API gateway

multi_region_app

 

Cleanup

Each Stack (VPC, RDS, API) is deployed independently to each account/region This allows each to be updated separately.

You will need to go CloudFormation in each account/region and delete the stacks when you want to clean up the resources.

Explore nested stacks if this behavior is not acceptable

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

multiple-account-cdk-cicd-pipeline's People

Contributors

amazon-auto avatar austinloveless avatar issabayevmk avatar kevasync avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.