Skip to content

Commit

Permalink
refactor(aws-s3, aws-codepipeline): Align the S3 CodePipeline Action …
Browse files Browse the repository at this point in the history
…with other Actions. (#492)

BREAKING CHANGE: move the S3 CodePipeline Action out of the aws-codepipeline package
and into the aws-s3 package, and rename it from AmazonS3Source to PipelineSource.
  • Loading branch information
skinny85 authored Aug 15, 2018
1 parent 934ca5f commit 518cef3
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface SourceActionProps extends CommonActionProps {
/**
* Low-level class for source actions.
* It is recommended that concrete types are used instead,
* such as {@link codepipeline.AmazonS3Source} or
* such as {@link s3.PipelineSource} or
* {@link codecommit.PipelineSource}.
*/
export abstract class SourceAction extends Action {
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './github-source-action';
export * from './manual-approval-action';
export * from './pipeline';
export * from './s3-source-action';
export * from './stage';

// AWS::CodePipeline CloudFormation Resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const sourceStage = new codepipeline.Stage(pipeline, 'Source');
const bucket = new s3.Bucket(stack, 'PipelineBucket', {
versioned: true,
});
new codepipeline.AmazonS3Source(stack, 'Source', {
new s3.PipelineSource(stack, 'Source', {
stage: sourceStage,
artifactName: 'SourceArtifact',
bucket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const sourceStage = new codepipeline.Stage(pipeline, 'Source');
const bucket = new s3.Bucket(stack, 'PipelineBucket', {
versioned: true,
});
const source = new codepipeline.AmazonS3Source(stack, 'Source', {
const source = new s3.PipelineSource(stack, 'Source', {
stage: sourceStage,
artifactName: 'SourceArtifact',
bucket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import { Pipeline } from '../lib/pipeline';
import { AmazonS3Source } from '../lib/s3-source-action';
import { Stage } from '../lib/stage';

interface NameValidationTestCase {
Expand Down Expand Up @@ -61,13 +60,13 @@ export = {
const secondStage = new Stage(pipeline, 'SecondStage');

const bucket = new s3.Bucket(stack, 'PipelineBucket');
new AmazonS3Source(stack, 'FirstAction', {
new s3.PipelineSource(stack, 'FirstAction', {
stage: firstStage,
artifactName: 'FirstArtifact',
bucket,
bucketKey: 'key',
});
new AmazonS3Source(stack, 'SecondAction', {
new s3.PipelineSource(stack, 'SecondAction', {
stage: secondStage,
artifactName: 'SecondAction',
bucket,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export = {
const pipeline = new codepipeline.Pipeline(stack, 'PL');

const stage1 = new codepipeline.Stage(pipeline, 'S1');
new codepipeline.AmazonS3Source(stack, 'A1', {
new s3.PipelineSource(stack, 'A1', {
stage: stage1,
artifactName: 'Artifact',
bucket: new s3.Bucket(stack, 'Bucket'),
Expand Down
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ const policy = new BucketPolicy(this, 'MyBucketPolicy');
const bucket = new Bucket(this, 'MyBucket', { policy });
```

### Buckets as sources in CodePipeline

This package also defines an Action that allows you to use a
Bucket as a source in CodePipeline:

```ts
import codepipeline = require('@aws-cdk/aws-codepipeline');
import s3 = require('@aws-cdk/aws-s3');

const sourceBucket = new s3.Bucket(this, 'MyBucket', {
versioned: true, // a Bucket used as a source in CodePipeline must be versioned
});

const pipeline = new codepipeline.Pipeline(this, 'MyPipeline');
const sourceStage = new codepipeline.Stage(pipeline, 'Source');
const sourceAction = new s3.PipelineSource(this, 'S3Source', {
stage: sourceStage,
bucket: sourceBucket,
bucketKey: 'path/to/file.zip',
artifactName: 'SourceOuptut', //name can be arbitrary
});
// use sourceAction.artifact as the inputArtifact to later Actions...
```

### Importing and Exporting Buckets

You can create a `Bucket` construct that represents an external/existing/unowned bucket by using the `Bucket.import` factory method.
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-s3/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './bucket';
export * from './bucket-policy';
export * from './pipeline-action';
export * from './rule';

// AWS::S3 CloudFormation Resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import actions = require('@aws-cdk/aws-codepipeline-api');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { BucketRef } from './bucket';

/**
* Construction properties of the {@link AmazonS3Source S3 source action}.
* Construction properties of the {@link PipelineSource S3 source Action}.
*/
export interface AmazonS3SourceProps extends actions.CommonActionProps {
export interface PipelineSourceProps extends actions.CommonActionProps {
/**
* The name of the source's output artifact. Output artifacts are used by CodePipeline as
* inputs into other actions.
Expand All @@ -15,7 +15,7 @@ export interface AmazonS3SourceProps extends actions.CommonActionProps {
/**
* The Amazon S3 bucket that stores the source code
*/
bucket: s3.BucketRef;
bucket: BucketRef;

/**
* The key within the S3 bucket that stores the source code
Expand All @@ -34,8 +34,8 @@ export interface AmazonS3SourceProps extends actions.CommonActionProps {
/**
* Source that is provided by a specific Amazon S3 object.
*/
export class AmazonS3Source extends actions.SourceAction {
constructor(parent: cdk.Construct, name: string, props: AmazonS3SourceProps) {
export class PipelineSource extends actions.SourceAction {
constructor(parent: cdk.Construct, name: string, props: PipelineSourceProps) {
super(parent, name, {
stage: props.stage,
provider: 'S3',
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"pkglint": "^0.8.2"
},
"dependencies": {
"@aws-cdk/aws-codepipeline-api": "^0.8.2",
"@aws-cdk/aws-iam": "^0.8.2",
"@aws-cdk/aws-kms": "^0.8.2",
"@aws-cdk/aws-s3-notifications": "^0.8.2",
Expand Down

0 comments on commit 518cef3

Please sign in to comment.