Skip to content

Commit

Permalink
Merge branch 'master' into lambda-image-workdir
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 14, 2021
2 parents 3278a93 + a9d5118 commit dafed60
Show file tree
Hide file tree
Showing 256 changed files with 17,571 additions and 7,241 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.122.0](https://github.com/aws/aws-cdk/compare/v1.121.0...v1.122.0) (2021-09-08)

### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **assertions:** `hasOutput(props: any)` becomes `hasOutput(logicalId: string, props: any)`
* **assertions:** `findOutputs(props: any = {})` becomes `findOutputs(logicalId: string, props: any = {})`
* **assertions:** `hasMapping(props: any)` becomes `hasMapping(logicalId: string, props: any)`
* **assertions:** `findMappings(props: any = {})` becomes `findMappings(logicalId: string, props: any = {})`

### Features

* **ec2:** Allow ApplyCloudformationInitOptions to set additional params ([#16121](https://github.com/aws/aws-cdk/issues/16121)) ([1d94646](https://github.com/aws/aws-cdk/commit/1d94646bd50cbbbc1ace3732a7b8ebb313ed3ddf)), closes [#16004](https://github.com/aws/aws-cdk/issues/16004)
* **backup:** option to prevent recovery point deletions ([#16282](https://github.com/aws/aws-cdk/issues/16282)) ([6e71806](https://github.com/aws/aws-cdk/commit/6e718067b6c4e1a2c905fedcc60a6863ba3add12))
* **cli:** hotswap deployments ([#15748](https://github.com/aws/aws-cdk/issues/15748)) ([6e55c95](https://github.com/aws/aws-cdk/commit/6e55c952d683f87bb815deb29124b9a37824749a))
* **config:** EC2_INSTANCE_PROFILE_ATTACHED managed rule ([#16011](https://github.com/aws/aws-cdk/issues/16011)) ([816a319](https://github.com/aws/aws-cdk/commit/816a31984b5c6e08c4c7dd740919e0c1f5d0e196))
* **ec2:** rename SubnetTypes to improve clarity with EC2 conventions ([#16348](https://github.com/aws/aws-cdk/issues/16348)) ([2023004](https://github.com/aws/aws-cdk/commit/2023004cc941a0e7a908bf3c90ad9887c6679564)), closes [#15929](https://github.com/aws/aws-cdk/issues/15929)
* **ec2:** vpc endpoint for aws keyspaces ([#16306](https://github.com/aws/aws-cdk/issues/16306)) ([ad425d0](https://github.com/aws/aws-cdk/commit/ad425d004dd9154c367622733e2a2e36a38f1cef))
* **ecs-service-extensions:** Subscribe Extension ([#16049](https://github.com/aws/aws-cdk/issues/16049)) ([66baca5](https://github.com/aws/aws-cdk/commit/66baca58adc294d5c5924cf8f8c5fa122c6d6dfc))
* **elasticloadbalancingv2:** ALPN policy support for NLB listener ([#15956](https://github.com/aws/aws-cdk/issues/15956)) ([5427578](https://github.com/aws/aws-cdk/commit/5427578515c0b65d172f95c27f32f1933fcf8d60))
* **kms:** support fromLookup in KMS key to get key by alias name ([#15652](https://github.com/aws/aws-cdk/issues/15652)) ([34a57ed](https://github.com/aws/aws-cdk/commit/34a57eda01ab816cd77f260b10ca466a749586bf)), closes [#8822](https://github.com/aws/aws-cdk/issues/8822)
* **lambda:** python 3.9 runtime ([#16366](https://github.com/aws/aws-cdk/issues/16366)) ([a534829](https://github.com/aws/aws-cdk/commit/a534829b2458c5ed54d05fd5cca025cba2ddaaa7))
* **pipelines:** stack-level steps ([#16215](https://github.com/aws/aws-cdk/issues/16215)) ([d499c85](https://github.com/aws/aws-cdk/commit/d499c85e4c09cc00b457ca7f2f4611a925ca8aeb)), closes [#16148](https://github.com/aws/aws-cdk/issues/16148)
* **stepfunctions-tasks:** await the eval so async ops can be passed to tasks.EvaluateExpression ([#16290](https://github.com/aws/aws-cdk/issues/16290)) ([174b066](https://github.com/aws/aws-cdk/commit/174b066634755c76d1b78d05ca9b403145dedc47))


### Bug Fixes

* **apigatewayv2:** some methods of the `defaultStage` are not available without casting it to `IHttpStage` ([#15607](https://github.com/aws/aws-cdk/issues/15607)) ([27a0113](https://github.com/aws/aws-cdk/commit/27a0113ac68a05360faa22fa8897609f2f90b764))
* **assertions:** output and mapping assertions do not accept logical id ([#16329](https://github.com/aws/aws-cdk/issues/16329)), closes [#16242](https://github.com/aws/aws-cdk/issues/16242)
* **assets:** run executable command of container assets in cloud assembly root directory ([#16094](https://github.com/aws/aws-cdk/issues/16094)) ([c2852c9](https://github.com/aws/aws-cdk/commit/c2852c9c524a639a312bf296f7f23b0e3b112f6b)), closes [#15721](https://github.com/aws/aws-cdk/issues/15721)
* **autoscaling:** EbsDeviceVolumeType.IO2 is not a valid CloudFormation value ([#16028](https://github.com/aws/aws-cdk/issues/16028)) ([492d33b](https://github.com/aws/aws-cdk/commit/492d33b27bc5b935e3da75f0bddd875bb6f9c15d)), closes [#16027](https://github.com/aws/aws-cdk/issues/16027)
* **cli:** 'deploy' and 'diff' silently does nothing when given unknown stack name ([#16150](https://github.com/aws/aws-cdk/issues/16150)) ([74776f3](https://github.com/aws/aws-cdk/commit/74776f393462f7e7d23cb1953ef786a823adc896)), closes [#15866](https://github.com/aws/aws-cdk/issues/15866)
* **cloudwatch:** cross account alarms does not support math expressions ([#16333](https://github.com/aws/aws-cdk/issues/16333)) ([1ffd897](https://github.com/aws/aws-cdk/commit/1ffd89714f8b1c1389d4e43383cc77d16d00ed9e)), closes [#16331](https://github.com/aws/aws-cdk/issues/16331)
* **core:** allow asset bundling when selinux is enabled ([#15742](https://github.com/aws/aws-cdk/issues/15742)) ([dbfebb4](https://github.com/aws/aws-cdk/commit/dbfebb47a8ae61b2bb0557b6ba79a7b073f9d0df))
* **iam:** permissions boundary aspect doesn't always recognize roles ([#16154](https://github.com/aws/aws-cdk/issues/16154)) ([c8bfcf6](https://github.com/aws/aws-cdk/commit/c8bfcf650070a0138b148645f997f542431f70cf))
* **stepfunctions-tasks:** Athena StartQueryExecution includes QueryExecutionContext even when object is empty ([#16141](https://github.com/aws/aws-cdk/issues/16141)) ([6e2a3e0](https://github.com/aws/aws-cdk/commit/6e2a3e0f855221df98f78f6465586d5524f5c7d5)), closes [#16133](https://github.com/aws/aws-cdk/issues/16133) [#16133](https://github.com/aws/aws-cdk/issues/16133)

## [1.121.0](https://github.com/aws/aws-cdk/compare/v1.120.0...v1.121.0) (2021-09-01)


Expand Down
4 changes: 4 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ removed:@aws-cdk/aws-stepfunctions-tasks.BatchSubmitJobProps.jobDefinition
strengthened:@aws-cdk/aws-stepfunctions-tasks.BatchSubmitJobProps
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.cluster
strengthened:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps

# Remove IO2 from autoscaling EbsDeviceVolumeType. This value is not supported
# at the moment and was not supported in the past.
removed:@aws-cdk/aws-autoscaling.EbsDeviceVolumeType.IO2
4 changes: 3 additions & 1 deletion buildspec-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ phases:
- yarn --version || npm -g install yarn
build:
commands:
- /bin/bash ./build.sh --extract && git diff-index --exit-code --ignore-space-at-eol --stat HEAD
- /bin/bash ./build.sh --extract
- /bin/bash ./scripts/transform.sh --extract
- git diff-index --exit-code --ignore-space-at-eol --stat HEAD
1 change: 1 addition & 0 deletions buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ phases:
- 'if ${BUMP_CANDIDATE:-false}; then /bin/bash ./scripts/bump-candidate.sh; fi'
- /bin/bash ./scripts/align-version.sh
- /bin/bash ./build.sh
- /bin/bash ./scripts/transform.sh
post_build:
commands:
- "[ -f .BUILD_COMPLETED ] && /bin/bash ./pack.sh"
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
"nohoist": [
"**/jszip",
"**/jszip/**",
"@aws-cdk/assertions-alpha/colors",
"@aws-cdk/assertions-alpha/colors/**",
"@aws-cdk/assertions-alpha/diff",
"@aws-cdk/assertions-alpha/diff/**",
"@aws-cdk/assertions-alpha/fast-deep-equal",
"@aws-cdk/assertions-alpha/fast-deep-equal/**",
"@aws-cdk/assertions-alpha/string-width",
"@aws-cdk/assertions-alpha/string-width/**",
"@aws-cdk/assertions-alpha/table",
"@aws-cdk/assertions-alpha/table/**",
"@aws-cdk/assertions/colors",
"@aws-cdk/assertions/colors/**",
"@aws-cdk/assertions/diff",
Expand Down
142 changes: 134 additions & 8 deletions packages/@aws-cdk/assertions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,32 @@ By default, the `hasResource()` and `hasResourceProperties()` APIs perform deep
partial object matching. This behavior can be configured using matchers.
See subsequent section on [special matchers](#special-matchers).

## Other Sections
## Output and Mapping sections

Similar to the `hasResource()` and `findResources()`, we have equivalent methods
to check and find other sections of the CloudFormation resources.
The module allows you to assert that the CloudFormation template contains an Output
that matches specific properties. The following code asserts that a template contains
an Output with a `logicalId` of `Foo` and the specified properties -

* Outputs - `hasOutput()` and `findOutputs()`
* Mapping - `hasMapping()` and `findMappings()`
```ts
assert.hasOutput('Foo', {
Value: 'Bar',
Export: { Name: 'ExportBaz' },
});
```

All of the defaults and behaviour documented for `hasResource()` and
`findResources()` apply to these methods.
If you want to match against all Outputs in the template, use `*` as the `logicalId`.

```ts
assert.hasOutput('*', {
Value: 'Bar',
Export: { Name: 'ExportBaz' },
});
```

`findOutputs()` will return a list of outputs that match the `logicalId` and `props`,
and you can use the `'*'` special case as well.

The APIs `hasMapping()` and `findMappings()` provide similar functionalities.

## Special Matchers

Expand Down Expand Up @@ -168,7 +184,9 @@ assert.hasResourceProperties('Foo::Bar', {
The `Match.objectEquals()` API can be used to assert a target as a deep exact
match.

In addition, the `Match.absentProperty()` can be used to specify that a specific
### Presence and Absence

The `Match.absentProperty()` matcher can be used to specify that a specific
property should not exist on the target. This can be used within `Match.objectLike()`
or outside of any matchers.

Expand Down Expand Up @@ -202,6 +220,42 @@ assert.hasResourceProperties('Foo::Bar', {
});
```

The `Match.anyValue()` matcher can be used to specify that a specific value should be found
at the location. This matcher will fail if when the target location has null-ish values
(i.e., `null` or `undefined`).

This matcher can be combined with any of the other matchers.

```ts
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": {
// "Wobble": ["Flob", "Flib"],
// }
// }
// }
// }
// }

// The following will NOT throw an assertion error
assert.hasResourceProperties('Foo::Bar', {
Fred: {
Wobble: [Match.anyValue(), "Flip"],
},
});

// The following will throw an assertion error
assert.hasResourceProperties('Foo::Bar', {
Fred: {
Wimble: Match.anyValue(),
},
});
```

### Array Matchers

The `Match.arrayWith()` API can be used to assert that the target is equal to or a subset
Expand Down Expand Up @@ -267,6 +321,78 @@ assert.hasResourceProperties('Foo::Bar', Match.objectLike({
}});
```
### Serialized JSON
Often, we find that some CloudFormation Resource types declare properties as a string,
but actually expect JSON serialized as a string.
For example, the [`BuildSpec` property of `AWS::CodeBuild::Project`][Pipeline BuildSpec],
the [`Definition` property of `AWS::StepFunctions::StateMachine`][StateMachine Definition],
to name a couple.
The `Match.serializedJson()` matcher allows deep matching within a stringified JSON.
```ts
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Baz": "{ \"Fred\": [\"Waldo\", \"Willow\"] }"
// }
// }
// }
// }

// The following will NOT throw an assertion error
assert.hasResourceProperties('Foo::Bar', {
Baz: Match.serializedJson({
Fred: Match.arrayWith(["Waldo"]),
}),
});

// The following will throw an assertion error
assert.hasResourceProperties('Foo::Bar', {
Baz: Match.serializedJson({
Fred: ["Waldo", "Johnny"],
}),
});
```
[Pipeline BuildSpec]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-source.html#cfn-codebuild-project-source-buildspec
[StateMachine Definition]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-definition
## Capturing Values
This matcher APIs documented above allow capturing values in the matching entry
(Resource, Output, Mapping, etc.). The following code captures a string from a
matching resource.
```ts
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": ["Flob", "Cat"],
// "Waldo": ["Qix", "Qux"],
// }
// }
// }
// }

const fredCapture = new Capture();
const waldoCapture = new Capture();
assert.hasResourceProperties('Foo::Bar', {
Fred: fredCapture,
Waldo: ["Qix", waldoCapture],
});

fredCapture.asArray(); // returns ["Flob", "Cat"]
waldoCapture.asString(); // returns "Qux"
```
## Strongly typed languages
Some of the APIs documented above, such as `templateMatches()` and
Expand Down
98 changes: 98 additions & 0 deletions packages/@aws-cdk/assertions/lib/capture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Matcher, MatchResult } from './matcher';
import { Type, getType } from './private/type';

/**
* Capture values while matching templates.
* Using an instance of this class within a Matcher will capture the matching value.
* The `as*()` APIs on the instance can be used to get the captured value.
*/
export class Capture extends Matcher {
public readonly name: string;
private value: any = null;

constructor() {
super();
this.name = 'Capture';
}

public test(actual: any): MatchResult {
this.value = actual;

const result = new MatchResult(actual);
if (actual == null) {
result.push(this, [], `Can only capture non-nullish values. Found ${actual}`);
}
return result;
}

/**
* Retrieve the captured value as a string.
* An error is generated if no value is captured or if the value is not a string.
*/
public asString(): string {
this.checkNotNull();
if (getType(this.value) === 'string') {
return this.value;
}
this.reportIncorrectType('string');
}

/**
* Retrieve the captured value as a number.
* An error is generated if no value is captured or if the value is not a number.
*/
public asNumber(): number {
this.checkNotNull();
if (getType(this.value) === 'number') {
return this.value;
}
this.reportIncorrectType('number');
}

/**
* Retrieve the captured value as a boolean.
* An error is generated if no value is captured or if the value is not a boolean.
*/
public asBoolean(): boolean {
this.checkNotNull();
if (getType(this.value) === 'boolean') {
return this.value;
}
this.reportIncorrectType('boolean');
}

/**
* Retrieve the captured value as an array.
* An error is generated if no value is captured or if the value is not an array.
*/
public asArray(): any[] {
this.checkNotNull();
if (getType(this.value) === 'array') {
return this.value;
}
this.reportIncorrectType('array');
}

/**
* Retrieve the captured value as a JSON object.
* An error is generated if no value is captured or if the value is not an object.
*/
public asObject(): { [key: string]: any } {
this.checkNotNull();
if (getType(this.value) === 'object') {
return this.value;
}
this.reportIncorrectType('object');
}

private checkNotNull(): void {
if (this.value == null) {
throw new Error('No value captured');
}
}

private reportIncorrectType(expected: Type): never {
throw new Error(`Captured value is expected to be ${expected} but found ${getType(this.value)}. ` +
`Value is ${JSON.stringify(this.value, undefined, 2)}`);
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/assertions/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './capture';
export * from './template';
export * from './match';
export * from './matcher';
Loading

0 comments on commit dafed60

Please sign in to comment.