Skip to content

Commit 0b25265

Browse files
fix(appsync): sanitized datasource name isn't exported (#23802)
Closes #23743 When providing a name with unsupported characters to an AppSync datasource, it is sanitized internally. #22378 introduced a bug where the sanitized name was no longer exposed on DataSource class instances. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* ![image](https://user-images.githubusercontent.com/5336472/214185923-6e90b49a-e834-4932-a23a-12094546181d.png) ![image](https://user-images.githubusercontent.com/5336472/214186095-a4ee51f7-37e1-451c-ba08-d27277cba0b9.png) The above code generates the shown diff. This is due to #23743 where the name is sanitised, but not when setting `this.name`.
1 parent 9c915c1 commit 0b25265

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/@aws-cdk/aws-appsync/lib/data-source.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export abstract class BaseDataSource extends Construct {
125125
serviceRoleArn: this.serviceRole?.roleArn,
126126
...extended,
127127
});
128-
this.name = name;
128+
this.name = supportedName;
129129
this.api = props.api;
130130
}
131131

packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ describe('None Data Source configuration', () => {
5454
});
5555
});
5656

57+
test('appsync data source exports sanitised name', () => {
58+
// WHEN
59+
const ds = api.addNoneDataSource('ds', {
60+
name: 'Produce-Custom',
61+
});
62+
63+
// THEN
64+
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
65+
Type: 'NONE',
66+
Name: 'ProduceCustom',
67+
});
68+
expect(ds.name).toBe('ProduceCustom');
69+
});
70+
5771
test('appsync configures name and description correctly', () => {
5872
// WHEN
5973
api.addNoneDataSource('ds', {
@@ -116,5 +130,3 @@ describe('adding none data source from imported api', () => {
116130
});
117131
});
118132
});
119-
120-

0 commit comments

Comments
 (0)