From 3189e9d918217832ed4792792e2fbb7570f1a742 Mon Sep 17 00:00:00 2001 From: Eli Polonsky Date: Wed, 4 Mar 2020 16:38:59 +0200 Subject: [PATCH] feat(custom-resources): rename `getData*` to `getResponseField*` (#6556) Renaming for some more clarity. Relates to #5873 BREAKING CHANGE: `getDataString` was renamed to `getResponseField` and `getData` was renamed to `getResponseFieldReference` --- packages/@aws-cdk/custom-resources/README.md | 8 ++++---- .../lib/aws-custom-resource/aws-custom-resource.ts | 4 ++-- .../test/aws-custom-resource/aws-custom-resource.test.ts | 8 ++++---- .../test/aws-custom-resource/integ.aws-custom-resource.ts | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/@aws-cdk/custom-resources/README.md b/packages/@aws-cdk/custom-resources/README.md index 8831f7897e7df..89572f86f4488 100644 --- a/packages/@aws-cdk/custom-resources/README.md +++ b/packages/@aws-cdk/custom-resources/README.md @@ -368,7 +368,7 @@ const awsCustom2 = new AwsCustomResource(this, 'API2', { service: '...', action: '...' parameters: { - text: awsCustom1.getDataString('Items.0.text') + text: awsCustom1.getResponseField('Items.0.text') }, physicalResourceId: PhysicalResourceId.of('...') }, @@ -385,7 +385,7 @@ Note that in such a case, the call response data and the `Data` key submitted to Since a successful resource provisioning might or might not produce outputs, this presents us with some limitations: - `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. +- `getResponseField` and `getResponseFieldReference` - 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`. @@ -409,7 +409,7 @@ const verifyDomainIdentity = new AwsCustomResource(this, 'VerifyDomainIdentity', new route53.TxtRecord(this, 'SESVerificationRecord', { zone, recordName: `_amazonses.example.com`, - values: [verifyDomainIdentity.getDataString('VerificationToken')] + values: [verifyDomainIdentity.getResponseField('VerificationToken')] }); ``` @@ -430,7 +430,7 @@ const getParameter = new AwsCustomResource(this, 'GetParameter', { }); // Use the value in another construct with -getParameter.getData('Parameter.Value') +getParameter.getResponseField('Parameter.Value') ``` diff --git a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts index d96d57aa93560..881954c056e97 100644 --- a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts +++ b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts @@ -339,7 +339,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable { * * @param dataPath the path to the data */ - public getData(dataPath: string) { + public getResponseFieldReference(dataPath: string) { AwsCustomResource.breakIgnoreErrorsCircuit([this.props.onCreate, this.props.onUpdate], "getData"); return this.customResource.getAtt(dataPath); } @@ -355,7 +355,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable { * * @param dataPath the path to the data */ - public getDataString(dataPath: string): string { + public getResponseField(dataPath: string): string { AwsCustomResource.breakIgnoreErrorsCircuit([this.props.onCreate, this.props.onUpdate], "getDataString"); return this.customResource.getAttString(dataPath); } diff --git a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts index dcfbfa15d194c..27e3b89311703 100644 --- a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts +++ b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts @@ -342,7 +342,7 @@ test('getData', () => { }); // WHEN - const token = awsSdk.getData('Data'); + const token = awsSdk.getResponseFieldReference('Data'); // THEN expect(stack.resolve(token)).toEqual({ @@ -371,7 +371,7 @@ test('fails when getData is used with `ignoreErrorCodesMatching`', () => { policy: AwsCustomResourcePolicy.fromSdkCalls({resources: AwsCustomResourcePolicy.ANY_RESOURCE}), }); - expect(() => resource.getData("ShouldFail")).toThrow(/`getData`.+`ignoreErrorCodesMatching`/); + expect(() => resource.getResponseFieldReference("ShouldFail")).toThrow(/`getData`.+`ignoreErrorCodesMatching`/); }); @@ -393,7 +393,7 @@ test('fails when getDataString is used with `ignoreErrorCodesMatching`', () => { policy: AwsCustomResourcePolicy.fromSdkCalls({resources: AwsCustomResourcePolicy.ANY_RESOURCE}), }); - expect(() => resource.getDataString("ShouldFail")).toThrow(/`getDataString`.+`ignoreErrorCodesMatching`/); + expect(() => resource.getResponseField("ShouldFail")).toThrow(/`getDataString`.+`ignoreErrorCodesMatching`/); }); @@ -462,7 +462,7 @@ test('getDataString', () => { service: 'service', action: 'action', parameters: { - a: awsSdk.getDataString('Data') + a: awsSdk.getResponseField('Data') }, physicalResourceId: PhysicalResourceId.of('id') }, diff --git a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts index 3f6df0bf44af3..bf186440eac6b 100644 --- a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts +++ b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts @@ -51,8 +51,8 @@ const getParameter = new AwsCustomResource(stack, 'GetParameter', { policy: AwsCustomResourcePolicy.fromSdkCalls({resources: AwsCustomResourcePolicy.ANY_RESOURCE}) }); -new cdk.CfnOutput(stack, 'MessageId', { value: snsPublish.getDataString('MessageId') }); -new cdk.CfnOutput(stack, 'TopicArn', { value: listTopics.getDataString('Topics.0.TopicArn') }); -new cdk.CfnOutput(stack, 'ParameterValue', { value: getParameter.getDataString('Parameter.Value') }); +new cdk.CfnOutput(stack, 'MessageId', { value: snsPublish.getResponseField('MessageId') }); +new cdk.CfnOutput(stack, 'TopicArn', { value: listTopics.getResponseField('Topics.0.TopicArn') }); +new cdk.CfnOutput(stack, 'ParameterValue', { value: getParameter.getResponseField('Parameter.Value') }); app.synth();