Skip to content

Commit

Permalink
feat(custom-resources): rename getData* to getResponseField* (#6556)
Browse files Browse the repository at this point in the history
Renaming for some more clarity.

Relates to #5873 

BREAKING CHANGE: `getDataString` was renamed to `getResponseField` and `getData` was renamed to `getResponseFieldReference`
  • Loading branch information
iliapolo authored and Elad Ben-Israel committed Mar 9, 2020
1 parent b9a64c6 commit 3189e9d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/@aws-cdk/custom-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('...')
},
Expand All @@ -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`.

Expand All @@ -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')]
});
```

Expand All @@ -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')
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ test('getData', () => {
});

// WHEN
const token = awsSdk.getData('Data');
const token = awsSdk.getResponseFieldReference('Data');

// THEN
expect(stack.resolve(token)).toEqual({
Expand Down Expand Up @@ -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`/);

});

Expand All @@ -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`/);

});

Expand Down Expand Up @@ -462,7 +462,7 @@ test('getDataString', () => {
service: 'service',
action: 'action',
parameters: {
a: awsSdk.getDataString('Data')
a: awsSdk.getResponseField('Data')
},
physicalResourceId: PhysicalResourceId.of('id')
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 3189e9d

Please sign in to comment.