Package: aws-cdk.app-delivery
Continuous Integration / Continuous Delivery for CDK Applications---This API may emit warnings. Backward compatibility is not guaranteed.This library includes aCodePipelinecomposite Action for deploying AWS CDK Applications.This module is part of theAWS Cloud Development Kitproject.Replacement recommendedThis library has been deprecated. We recommend you use the@aws-cdk/pipelinesmodule instead.LimitationsThe construct library in it's current form has the following limitations:It can only deploy stacks that are hosted in the same AWS account and region as theCodePipelineis.Stacks that make use ofAssets cannot be deployed successfully.Getting StartedIn order to add thePipelineDeployStackActionto yourCodePipeline, you need to have aCodePipelineartifact that
contains the result of invokingcdk synth -o <dir>on yourCDK App. You can for example achieve this using aCodeBuildproject.The example below defines aCDK Appthat contains 3 stacks:CodePipelineStackmanages theCodePipelineresources, and self-updates before deploying any other stackServiceStackAandServiceStackBare service infrastructure stacks, and need to be deployed in this order┏━━━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  ┃     Source     ┃  ┃     Build      ┃  ┃  Self-Update    ┃  ┃             Deploy              ┃
  ┃                ┃  ┃                ┃  ┃                 ┃  ┃                                 ┃
  ┃ ┌────────────┐ ┃  ┃ ┌────────────┐ ┃  ┃ ┌─────────────┐ ┃  ┃ ┌─────────────┐ ┌─────────────┐ ┃
  ┃ │   GitHub   ┣━╋━━╋━▶ CodeBuild  ┣━╋━━╋━▶Deploy Stack ┣━╋━━╋━▶Deploy Stack ┣━▶Deploy Stack │ ┃
  ┃ │            │ ┃  ┃ │            │ ┃  ┃ │PipelineStack│ ┃  ┃ │ServiceStackA│ │ServiceStackB│ ┃
  ┃ └────────────┘ ┃  ┃ └────────────┘ ┃  ┃ └─────────────┘ ┃  ┃ └─────────────┘ └─────────────┘ ┃
  ┗━━━━━━━━━━━━━━━━┛  ┗━━━━━━━━━━━━━━━━┛  ┗━━━━━━━━━━━━━━━━━┛  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛index.tsimportaws_cdk.aws_codebuildascodebuildimportaws_cdk.aws_codepipelineascodepipelineimportaws_cdk.aws_codepipeline_actionsascodepipeline_actionsimportaws_cdk.coreascdkimportaws_cdk.app_deliveryascicdimportaws_cdk.aws_iamasiamclassMyServiceStackA(cdk.Stack):passclassMyServiceStackB(cdk.Stack):passapp=cdk.App()# We define a stack that contains the CodePipelinepipeline_stack=cdk.Stack(app,"PipelineStack")pipeline=codepipeline.Pipeline(pipeline_stack,"CodePipeline",# Mutating a CodePipeline can cause the currently propagating state to be# "lost". Ensure we re-run the latest change through the pipeline after it's# been mutated so we're sure the latest state is fully deployed through.restart_execution_on_update=True)# Configure the CodePipeline source - where your CDK App's source code is hostedsource_output=codepipeline.Artifact()source=codepipeline_actions.GitHubSourceAction(action_name="GitHub",output=source_output,owner="myName",repo="myRepo",oauth_token=cdk.SecretValue.unsafe_plain_text("secret"))pipeline.add_stage(stage_name="source",actions=[source])project=codebuild.PipelineProject(pipeline_stack,"CodeBuild")synthesized_app=codepipeline.Artifact()build_action=codepipeline_actions.CodeBuildAction(action_name="CodeBuild",project=project,input=source_output,outputs=[synthesized_app])pipeline.add_stage(stage_name="build",actions=[build_action])# Optionally, self-update the pipeline stackself_update_stage=pipeline.add_stage(stage_name="SelfUpdate")self_update_stage.add_action(cicd.PipelineDeployStackAction(stack=pipeline_stack,input=synthesized_app,admin_permissions=True))# Now add our service stacksdeploy_stage=pipeline.add_stage(stage_name="Deploy")service_stack_a=MyServiceStackA(app,"ServiceStackA")# Add actions to deploy the stacks in the deploy stage:deploy_service_aAction=cicd.PipelineDeployStackAction(stack=service_stack_a,input=synthesized_app,# See the note below for details about this option.admin_permissions=False)deploy_stage.add_action(deploy_service_aAction)# Add the necessary permissions for you service deploy action. This role is# is passed to CloudFormation and needs the permissions necessary to deploy# stack. Alternatively you can enable [Administrator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_job-functions.html#jf_administrator) permissions above,# users should understand the privileged nature of this role.my_resource_arn="arn:partition:service:region:account-id:resource-id"deploy_service_aAction.add_to_deployment_role_policy(iam.PolicyStatement(actions=["service:SomeAction"],resources=[my_resource_arn]))service_stack_b=MyServiceStackB(app,"ServiceStackB")deploy_stage.add_action(cicd.PipelineDeployStackAction(stack=service_stack_b,input=synthesized_app,create_change_set_run_order=998,admin_permissions=True))buildspec.ymlThe repository can contain a file at the root level namedbuildspec.yml, or
you can in-line the buildspec. Note thatbuildspec.yamlis not compatible.For example, aTypeScriptorJavascriptCDK App can add the followingbuildspec.ymlat the root of the repository:version: 0.2
phases:
  install:
    commands:
      # Installs the npm dependencies as defined by the `package.json` file
      # present in the root directory of the package
      # (`cdk init app --language=typescript` would have created one for you)
      - npm install
  build:
    commands:
      # Builds the CDK App so it can be synthesized
      - npm run build
      # Synthesizes the CDK App and puts the resulting artifacts into `dist`
      - npm run cdk synth -- -o dist
artifacts:
  # The output artifact is all the files in the `dist` directory
  base-directory: dist
  files: '**/*'ThePipelineDeployStackActionexpects it'sinputto contain the result of
synthesizing a CDK App using thecdk synth -o <directory>.