Skip to content

Commit

Permalink
code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Mar 3, 2020
1 parent 90c2f4e commit 656725b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
8 changes: 6 additions & 2 deletions packages/@aws-cdk/custom-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,13 @@ const awsCustom2 = new AwsCustomResource(this, 'API2', {

### Error Handling

Every error produced by the API call is treated as is and will cause a "FAILED" response to be submitted to CloudFormation. You can ignore some errors by specifying the `ignoreErrorCodesMatching` property, which accepts a regular expression that is tested against the `code` property of the response. If matched, a "SUCCESS" response is submitted. Note that in such a case, the call response data, and the `Data` key submitted to CloudFormation, will both be an empty JSON object. This presents us with some limitations:
Every error produced by the API call is treated as is and will cause a "FAILED" response to be submitted to CloudFormation.
You can ignore some errors by specifying the `ignoreErrorCodesMatching` property, which accepts a regular expression that is
tested against the `code` property of the response. If matched, a "SUCCESS" response is submitted.
Note that in such a case, the call response data and the `Data` key submitted to CloudFormation would both be an empty JSON object.
Since a successful resource provisioning might or might not produce outputs, this presents us with some limitations:

- `PhysicalResourceId.fromResponse` - Since the call response data is empty, we cannot use it to extract the physical id.
- `PhysicalResourceId.fromResponse` - Since the call response data might be empty, we cannot use it to extract the physical id.
- `getData` and `getDataString` - Since the `Data` key is empty, the resource will not have any attributes, and therefore, invoking these functions will result in an error.

In both the cases, you will get a synth time error if you attempt to use it in conjunction with `ignoreErrorCodesMatching`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ export interface AwsCustomResourceProps {
*
*/
export class AwsCustomResource extends cdk.Construct implements iam.IGrantable {

private static breakIgnoreErrorsCircuit(sdkCalls: Array<AwsSdkCall | undefined>, caller: string) {

for (const call of sdkCalls) {
if (call && call.ignoreErrorCodesMatching) {
throw new Error(`\`${caller}\`` + ' cannot be called along with `ignoreErrorCodesMatching`.');
}
}

}

public readonly grantPrincipal: iam.IPrincipal;

private readonly customResource: CustomResource;
Expand All @@ -211,8 +222,8 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable {
}

for (const call of [props.onCreate, props.onUpdate, props.onDelete]) {
if (call && call.ignoreErrorCodesMatching && call.physicalResourceId?.responsePath) {
throw new Error('`PhysicalResourceId.fromResponse` cannot be used along with `ignoreErrorCodesMatching`.');
if (call && call.physicalResourceId?.responsePath) {
AwsCustomResource.breakIgnoreErrorsCircuit([call], "PhysicalResourceId.fromResponse");
}
}

Expand Down Expand Up @@ -271,7 +282,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable {
* @param dataPath the path to the data
*/
public getData(dataPath: string) {
this.breakIgnoreErrorsCircuit("getData");
AwsCustomResource.breakIgnoreErrorsCircuit([this.props.onCreate, this.props.onUpdate], "getData");
return this.customResource.getAtt(dataPath);
}

Expand All @@ -287,19 +298,10 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable {
* @param dataPath the path to the data
*/
public getDataString(dataPath: string): string {
this.breakIgnoreErrorsCircuit("getDataString");
AwsCustomResource.breakIgnoreErrorsCircuit([this.props.onCreate, this.props.onUpdate], "getDataString");
return this.customResource.getAttString(dataPath);
}

private breakIgnoreErrorsCircuit(caller: string) {

for (const call of [this.props.onCreate, this.props.onUpdate, this.props.onDelete]) {
if (call && call.ignoreErrorCodesMatching) {
throw new Error(`\`${caller}\`` + ' cannot be called along with `ignoreErrorCodesMatching`.');
}
}

}
}

/**
Expand Down

0 comments on commit 656725b

Please sign in to comment.