Skip to content

Commit

Permalink
Merge branch 'master' into revert/add-new-asset-interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Feb 2, 2021
2 parents a01f887 + 06b6d82 commit 99b2358
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 94 deletions.
2 changes: 0 additions & 2 deletions packages/@aws-cdk/aws-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ assert(bucket.encryptionKey === myKmsKey);
Enable KMS-SSE encryption via [S3 Bucket Keys](https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-key.html):

```ts
const myKmsKey = new kms.Key(this, 'MyKey');

const bucket = new Bucket(this, 'MyEncryptedBucket', {
encryption: BucketEncryption.KMS,
bucketKeyEnabled: true
Expand Down
71 changes: 35 additions & 36 deletions packages/@aws-cdk/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ definition. The definition is specified by its start state, and encompasses
all states reachable from the start state:

```ts
const startState = new stepfunctions.Pass(this, 'StartState');
const startState = new sfn.Pass(this, 'StartState');

new stepfunctions.StateMachine(this, 'StateMachine', {
new sfn.StateMachine(this, 'StateMachine', {
definition: startState
});
```
Expand Down Expand Up @@ -138,8 +138,8 @@ will be passed as the state's output.

```ts
// Makes the current JSON state { ..., "subObject": { "hello": "world" } }
const pass = new stepfunctions.Pass(this, 'Add Hello World', {
result: stepfunctions.Result.fromObject({ hello: 'world' }),
const pass = new sfn.Pass(this, 'Add Hello World', {
result: sfn.Result.fromObject({ hello: 'world' }),
resultPath: '$.subObject',
});

Expand All @@ -154,9 +154,9 @@ The following example filters the `greeting` field from the state input
and also injects a field called `otherData`.

```ts
const pass = new stepfunctions.Pass(this, 'Filter input and inject data', {
const pass = new sfn.Pass(this, 'Filter input and inject data', {
parameters: { // input to the pass state
input: stepfunctions.JsonPath.stringAt('$.input.greeting'),
input: sfn.JsonPath.stringAt('$.input.greeting'),
otherData: 'some-extra-stuff'
},
});
Expand All @@ -177,8 +177,8 @@ state.
```ts
// Wait until it's the time mentioned in the the state object's "triggerTime"
// field.
const wait = new stepfunctions.Wait(this, 'Wait For Trigger Time', {
time: stepfunctions.WaitTime.timestampPath('$.triggerTime'),
const wait = new sfn.Wait(this, 'Wait For Trigger Time', {
time: sfn.WaitTime.timestampPath('$.triggerTime'),
});

// Set the next state
Expand All @@ -191,11 +191,11 @@ A `Choice` state can take a different path through the workflow based on the
values in the execution's JSON state:

```ts
const choice = new stepfunctions.Choice(this, 'Did it work?');
const choice = new sfn.Choice(this, 'Did it work?');

// Add conditions with .when()
choice.when(stepfunctions.Condition.stringEqual('$.status', 'SUCCESS'), successState);
choice.when(stepfunctions.Condition.numberGreaterThan('$.attempts', 5), failureState);
choice.when(sfn.Condition.stringEquals('$.status', 'SUCCESS'), successState);
choice.when(sfn.Condition.numberGreaterThan('$.attempts', 5), failureState);

// Use .otherwise() to indicate what should be done if none of the conditions match
choice.otherwise(tryAgainState);
Expand All @@ -206,9 +206,9 @@ all branches come together and continuing as one (similar to how an `if ...
then ... else` works in a programming language), use the `.afterwards()` method:

```ts
const choice = new stepfunctions.Choice(this, 'What color is it?');
choice.when(stepfunctions.Condition.stringEqual('$.color', 'BLUE'), handleBlueItem);
choice.when(stepfunctions.Condition.stringEqual('$.color', 'RED'), handleRedItem);
const choice = new sfn.Choice(this, 'What color is it?');
choice.when(sfn.Condition.stringEquals('$.color', 'BLUE'), handleBlueItem);
choice.when(sfn.Condition.stringEquals('$.color', 'RED'), handleRedItem);
choice.otherwise(handleOtherItemColor);

// Use .afterwards() to join all possible paths back together and continue
Expand Down Expand Up @@ -275,7 +275,7 @@ A `Parallel` state executes one or more subworkflows in parallel. It can also
be used to catch and recover from errors in subworkflows.

```ts
const parallel = new stepfunctions.Parallel(this, 'Do the work in parallel');
const parallel = new sfn.Parallel(this, 'Do the work in parallel');

// Add branches to be executed in parallel
parallel.branch(shipItem);
Expand All @@ -298,7 +298,7 @@ Reaching a `Succeed` state terminates the state machine execution with a
succesful status.

```ts
const success = new stepfunctions.Succeed(this, 'We did it!');
const success = new sfn.Succeed(this, 'We did it!');
```

### Fail
Expand All @@ -308,7 +308,7 @@ failure status. The fail state should report the reason for the failure.
Failures can be caught by encompassing `Parallel` states.

```ts
const success = new stepfunctions.Fail(this, 'Fail', {
const success = new sfn.Fail(this, 'Fail', {
error: 'WorkflowFailure',
cause: "Something went wrong"
});
Expand All @@ -323,11 +323,11 @@ While the `Parallel` state executes multiple branches of steps using the same in
execute the same steps for multiple entries of an array in the state input.

```ts
const map = new stepfunctions.Map(this, 'Map State', {
const map = new sfn.Map(this, 'Map State', {
maxConcurrency: 1,
itemsPath: stepfunctions.JsonPath.stringAt('$.inputForMap')
itemsPath: sfn.JsonPath.stringAt('$.inputForMap')
});
map.iterator(new stepfunctions.Pass(this, 'Pass State'));
map.iterator(new sfn.Pass(this, 'Pass State'));
```

### Custom State
Expand Down Expand Up @@ -420,7 +420,7 @@ const definition = step1
.branch(step9.next(step10)))
.next(finish);

new stepfunctions.StateMachine(this, 'StateMachine', {
new sfn.StateMachine(this, 'StateMachine', {
definition,
});
```
Expand All @@ -429,14 +429,13 @@ If you don't like the visual look of starting a chain directly off the first
step, you can use `Chain.start`:

```ts
const definition = stepfunctions.Chain
const definition = sfn.Chain
.start(step1)
.next(step2)
.next(step3)
// ...
```


## State Machine Fragments

It is possible to define reusable (or abstracted) mini-state machines by
Expand All @@ -461,24 +460,24 @@ interface MyJobProps {
jobFlavor: string;
}

class MyJob extends stepfunctions.StateMachineFragment {
public readonly startState: State;
public readonly endStates: INextable[];
class MyJob extends sfn.StateMachineFragment {
public readonly startState: sfn.State;
public readonly endStates: sfn.INextable[];

constructor(parent: cdk.Construct, id: string, props: MyJobProps) {
super(parent, id);

const first = new stepfunctions.Task(this, 'First', { ... });
const first = new sfn.Task(this, 'First', { ... });
// ...
const last = new stepfunctions.Task(this, 'Last', { ... });
const last = new sfn.Task(this, 'Last', { ... });

this.startState = first;
this.endStates = [last];
}
}

// Do 3 different variants of MyJob in parallel
new stepfunctions.Parallel(this, 'All jobs')
new sfn.Parallel(this, 'All jobs')
.branch(new MyJob(this, 'Quick', { jobFlavor: 'quick' }).prefixStates())
.branch(new MyJob(this, 'Medium', { jobFlavor: 'medium' }).prefixStates())
.branch(new MyJob(this, 'Slow', { jobFlavor: 'slow' }).prefixStates());
Expand All @@ -500,7 +499,7 @@ You need the ARN to do so, so if you use Activities be sure to pass the Activity
ARN into your worker pool:

```ts
const activity = new stepfunctions.Activity(this, 'Activity');
const activity = new sfn.Activity(this, 'Activity');

// Read this CloudFormation Output from your application and use it to poll for work on
// the activity.
Expand All @@ -512,7 +511,7 @@ new cdk.CfnOutput(this, 'ActivityArn', { value: activity.activityArn });
Granting IAM permissions to an activity can be achieved by calling the `grant(principal, actions)` API:

```ts
const activity = new stepfunctions.Activity(this, 'Activity');
const activity = new sfn.Activity(this, 'Activity');

const role = new iam.Role(stack, 'Role', {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
Expand Down Expand Up @@ -564,11 +563,11 @@ destination LogGroup:
```ts
const logGroup = new logs.LogGroup(stack, 'MyLogGroup');

new stepfunctions.StateMachine(stack, 'MyStateMachine', {
definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')),
new sfn.StateMachine(stack, 'MyStateMachine', {
definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')),
logs: {
destination: logGroup,
level: stepfunctions.LogLevel.ALL,
level: sfn.LogLevel.ALL,
}
});
```
Expand All @@ -580,8 +579,8 @@ Enable X-Ray tracing for StateMachine:
```ts
const logGroup = new logs.LogGroup(stack, 'MyLogGroup');

new stepfunctions.StateMachine(stack, 'MyStateMachine', {
definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')),
new sfn.StateMachine(stack, 'MyStateMachine', {
definition: sfn.Chain.start(new sfn.Pass(stack, 'Pass')),
tracingEnabled: true
});
```
Expand Down
12 changes: 0 additions & 12 deletions tools/eslint-plugin-cdk/test/rules/eslintrc.js

This file was deleted.

63 changes: 63 additions & 0 deletions tools/eslint-plugin-cdk/test/rules/fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ESLint } from 'eslint';
import * as fs from 'fs-extra';
import * as path from 'path';

const rulesDirPlugin = require('eslint-plugin-rulesdir');
rulesDirPlugin.RULES_DIR = path.join(__dirname, '../../lib/rules');

const linter = new ESLint({
baseConfig: {
parser: '@typescript-eslint/parser',
plugins: ['rulesdir'],
rules: {
quotes: [ 'error', 'single', { avoidEscape: true }],
'rulesdir/no-core-construct': [ 'error' ],
'rulesdir/no-qualified-construct': [ 'error' ],
}
},
rulePaths: [
path.join(__dirname, '../../lib/rules'),
],
fix: true,
});

const outputRoot = path.join(process.cwd(), '.test-output');
fs.mkdirpSync(outputRoot);

const fixturesRoot = path.join(__dirname, 'fixtures');

fs.readdirSync(fixturesRoot).filter(f => fs.lstatSync(path.join(fixturesRoot, f)).isDirectory()).forEach(d => {
describe(d, () => {
const outputDir = path.join(outputRoot, d);
fs.mkdirpSync(outputDir);

const fixturesDir = path.join(fixturesRoot, d);
const fixtureFiles = fs.readdirSync(fixturesDir).filter(f => f.endsWith('.ts') && !f.endsWith('.expected.ts'));

fixtureFiles.forEach(f => {
test(f, async (done) => {
const actualFile = await lintAndFix(path.join(fixturesDir, f), outputDir);
const expectedFile = path.join(fixturesDir, `${path.basename(f, '.ts')}.expected.ts`);
if (!fs.existsSync(expectedFile)) {
done.fail(`Expected file not found. Generated output at ${actualFile}`);
}
const actual = await fs.readFile(actualFile, { encoding: 'utf8' });
const expected = await fs.readFile(expectedFile, { encoding: 'utf8' });
if (actual !== expected) {
done.fail(`Linted file did not match expectations. Expected: ${expectedFile}. Actual: ${actualFile}`);
}
done();
});
});
});
});

async function lintAndFix(file: string, outputDir: string) {
const newPath = path.join(outputDir, path.basename(file))
let result = await linter.lintFiles(file);
await ESLint.outputFixes(result.map(r => {
r.filePath = newPath;
return r;
}));
return newPath;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as cdk from '@aws-cdk/core';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct } from '@aws-cdk/core';

class MyConstruct extends Construct {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as cdk from '@aws-cdk/core';

class MyConstruct extends cdk.Construct {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as cdk from '@aws-cdk/core';
import * as constructs from 'constructs';

let x: constructs.Construct;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as cdk from '@aws-cdk/core';

let x: cdk.Construct;
44 changes: 0 additions & 44 deletions tools/eslint-plugin-cdk/test/rules/no-core-construct.test.ts

This file was deleted.

0 comments on commit 99b2358

Please sign in to comment.