Skip to content

Commit e4ac767

Browse files
authored
feat(stepfunctions): add service integrations (#1646)
Introducing the `@aws-cdk/aws-stepfunctions-tasks` package, with service integrations for ECS, SNS and SQS. Lambda and Activity integrations have been moved there as well. Add jest bindings for `haveResource` and `haveResourceLike`. Allow specifying `placementConstraints` and `placementStrategies` in the constructor of `EC2Service`. Exposing parts of `TokenMap` so that the reverse mapping of string => Token can be used by non-core libraries, if they need to embed non-literal data representation facilities into complex data structures (used in the SFN tasks to represent data that is extracted from the state JSON via a JSONPath). BREAKING CHANGES * If your using Lambdas or Activities in StepFunctions workflows, you must now instantiate `InvokeFunction` or `InvokeActivity` from the `@aws-cdk/aws-stepfunctions-tasks` package around it. * `PlacementConstraint` used in task definitions is now a union object, constructed using factory functions on the `PlacementConstraint` class. * Empty placement constraints and strategies will no longer render in the CloudFormation template. This may appear as diffs showing an empty line.
1 parent 1cc43b3 commit e4ac767

File tree

100 files changed

+13867
-1231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+13867
-1231
lines changed

design/aws-guidelines.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ into an `{ "Fn::Join" }` expression which includes the relevant intrinsic
143143
functions.
144144

145145
If needed, you can query whether an object includes unresolved tokens by using
146-
the `cdk.unresolved(x)` function.
146+
the `cdk.isToken(x)` function.
147147

148148
Resource attributes should use a type that corresponds to the __resolved__ AWS
149149
CloudFormation type (e.g. `string`, `string[]`).

packages/@aws-cdk/assert/jest.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Stack } from "@aws-cdk/cdk";
2+
import { SynthesizedStack } from "@aws-cdk/cx-api";
3+
import { HaveResourceAssertion, ResourcePart } from "./lib/assertions/have-resource";
4+
import { expect as ourExpect } from './lib/expect';
5+
6+
declare global {
7+
namespace jest {
8+
interface Matchers<R> {
9+
toHaveResource(resourceType: string,
10+
properties?: any,
11+
comparison?: ResourcePart): R;
12+
13+
toHaveResourceLike(resourceType: string,
14+
properties?: any,
15+
comparison?: ResourcePart): R;
16+
}
17+
}
18+
}
19+
20+
expect.extend({
21+
toHaveResource(
22+
actual: SynthesizedStack | Stack,
23+
resourceType: string,
24+
properties?: any,
25+
comparison?: ResourcePart) {
26+
27+
const assertion = new HaveResourceAssertion(resourceType, properties, comparison, false);
28+
return assertHaveResource(assertion, actual);
29+
},
30+
toHaveResourceLike(
31+
actual: SynthesizedStack | Stack,
32+
resourceType: string,
33+
properties?: any,
34+
comparison?: ResourcePart) {
35+
36+
const assertion = new HaveResourceAssertion(resourceType, properties, comparison, true);
37+
return assertHaveResource(assertion, actual);
38+
}
39+
});
40+
41+
function assertHaveResource(assertion: HaveResourceAssertion, actual: SynthesizedStack | Stack) {
42+
const inspector = ourExpect(actual);
43+
const pass = assertion.assertUsing(inspector);
44+
if (pass) {
45+
return {
46+
pass,
47+
message: () => `Not ` + assertion.generateErrorMessage(),
48+
};
49+
} else {
50+
return {
51+
pass,
52+
message: () => assertion.generateErrorMessage(),
53+
};
54+
}
55+
}

packages/@aws-cdk/assert/lib/assertions/have-resource.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function haveResourceLike(resourceType: string,
3030

3131
type PropertyPredicate = (props: any, inspection: InspectionFailure) => boolean;
3232

33-
class HaveResourceAssertion extends Assertion<StackInspector> {
33+
export class HaveResourceAssertion extends Assertion<StackInspector> {
3434
private inspected: InspectionFailure[] = [];
3535
private readonly part: ResourcePart;
3636
private readonly predicate: PropertyPredicate;
@@ -66,17 +66,21 @@ class HaveResourceAssertion extends Assertion<StackInspector> {
6666
return false;
6767
}
6868

69-
public assertOrThrow(inspector: StackInspector) {
70-
if (!this.assertUsing(inspector)) {
71-
const lines: string[] = [];
72-
lines.push(`None of ${this.inspected.length} resources matches ${this.description}.`);
69+
public generateErrorMessage() {
70+
const lines: string[] = [];
71+
lines.push(`None of ${this.inspected.length} resources matches ${this.description}.`);
7372

74-
for (const inspected of this.inspected) {
75-
lines.push(`- ${inspected.failureReason} in:`);
76-
lines.push(indent(4, JSON.stringify(inspected.resource, null, 2)));
77-
}
73+
for (const inspected of this.inspected) {
74+
lines.push(`- ${inspected.failureReason} in:`);
75+
lines.push(indent(4, JSON.stringify(inspected.resource, null, 2)));
76+
}
7877

79-
throw new Error(lines.join('\n'));
78+
return lines.join('\n');
79+
}
80+
81+
public assertOrThrow(inspector: StackInspector) {
82+
if (!this.assertUsing(inspector)) {
83+
throw new Error(this.generateErrorMessage());
8084
}
8185
}
8286

0 commit comments

Comments
 (0)