Package software.amazon.awscdk.appdelivery


@Stability(Deprecated) @Deprecated package software.amazon.awscdk.appdelivery
Deprecated.

Continuous Integration / Continuous Delivery for CDK Applications

---

Deprecated

This API may emit warnings. Backward compatibility is not guaranteed.


This library includes a CodePipeline composite Action for deploying AWS CDK Applications.

This module is part of the AWS Cloud Development Kit project.

This library has been deprecated. We recommend you use the @aws-cdk/pipelines module instead.

Limitations

The construct library in it's current form has the following limitations:

  1. It can only deploy stacks that are hosted in the same AWS account and region as the CodePipeline is.
  2. Stacks that make use of Assets cannot be deployed successfully.

Getting Started

In order to add the PipelineDeployStackAction to your CodePipeline, you need to have a CodePipeline artifact that contains the result of invoking cdk synth -o <dir> on your CDK App. You can for example achieve this using a CodeBuild project.

The example below defines a CDK App that contains 3 stacks:

  • CodePipelineStack manages the CodePipeline resources, and self-updates before deploying any other stack
  • ServiceStackA and ServiceStackB are 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.ts

 import software.amazon.awscdk.services.codebuild.*;
 import software.amazon.awscdk.services.codepipeline.*;
 import software.amazon.awscdk.services.codepipeline.actions.*;
 import software.amazon.awscdk.core.*;
 import software.amazon.awscdk.appdelivery.*;
 import software.amazon.awscdk.services.iam.*;
 
 public class MyServiceStackA extends Stack {
 }
 public class MyServiceStackB extends Stack {
 }
 
 App app = new App();
 
 // We define a stack that contains the CodePipeline
 Stack pipelineStack = new Stack(app, "PipelineStack");
 Pipeline pipeline = Pipeline.Builder.create(pipelineStack, "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.
         .restartExecutionOnUpdate(true)
         .build();
 
 // Configure the CodePipeline source - where your CDK App's source code is hosted
 Artifact sourceOutput = new Artifact();
 GitHubSourceAction source = GitHubSourceAction.Builder.create()
         .actionName("GitHub")
         .output(sourceOutput)
         .owner("myName")
         .repo("myRepo")
         .oauthToken(SecretValue.unsafePlainText("secret"))
         .build();
 pipeline.addStage(StageOptions.builder()
         .stageName("source")
         .actions(List.of(source))
         .build());
 
 PipelineProject project = PipelineProject.Builder.create(pipelineStack, "CodeBuild").build();
 Artifact synthesizedApp = new Artifact();
 CodeBuildAction buildAction = CodeBuildAction.Builder.create()
         .actionName("CodeBuild")
         .project(project)
         .input(sourceOutput)
         .outputs(List.of(synthesizedApp))
         .build();
 pipeline.addStage(StageOptions.builder()
         .stageName("build")
         .actions(List.of(buildAction))
         .build());
 
 // Optionally, self-update the pipeline stack
 IStage selfUpdateStage = pipeline.addStage(StageOptions.builder().stageName("SelfUpdate").build());
 selfUpdateStage.addAction(PipelineDeployStackAction.Builder.create()
         .stack(pipelineStack)
         .input(synthesizedApp)
         .adminPermissions(true)
         .build());
 
 // Now add our service stacks
 IStage deployStage = pipeline.addStage(StageOptions.builder().stageName("Deploy").build());
 MyServiceStackA serviceStackA = MyServiceStackA.Builder.create(app, "ServiceStackA").build();
 // Add actions to deploy the stacks in the deploy stage:
 PipelineDeployStackAction deployServiceAAction = PipelineDeployStackAction.Builder.create()
         .stack(serviceStackA)
         .input(synthesizedApp)
         // See the note below for details about this option.
         .adminPermissions(false)
         .build();
 deployStage.addAction(deployServiceAAction);
 // 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.
 String myResourceArn = "arn:partition:service:region:account-id:resource-id";
 deployServiceAAction.addToDeploymentRolePolicy(PolicyStatement.Builder.create()
         .actions(List.of("service:SomeAction"))
         .resources(List.of(myResourceArn))
         .build());
 
 MyServiceStackB serviceStackB = MyServiceStackB.Builder.create(app, "ServiceStackB").build();
 deployStage.addAction(PipelineDeployStackAction.Builder.create()
         .stack(serviceStackB)
         .input(synthesizedApp)
         .createChangeSetRunOrder(998)
         .adminPermissions(true)
         .build());
 

buildspec.yml

The repository can contain a file at the root level named buildspec.yml, or you can in-line the buildspec. Note that buildspec.yaml is not compatible.

For example, a TypeScript or Javascript CDK App can add the following buildspec.yml at 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: '**/*'
 

The PipelineDeployStackAction expects it's input to contain the result of synthesizing a CDK App using the cdk synth -o <directory>. Deprecated: Use the @aws-cdk/pipelines module instead