Skip to content

Commit

Permalink
fix(appsync): sanitized datasource name isn't exported (#23802)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ramblingenzyme committed Jan 27, 2023
1 parent 9c915c1 commit 0b25265
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export abstract class BaseDataSource extends Construct {
serviceRoleArn: this.serviceRole?.roleArn,
...extended,
});
this.name = name;
this.name = supportedName;
this.api = props.api;
}

Expand Down
16 changes: 14 additions & 2 deletions packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ describe('None Data Source configuration', () => {
});
});

test('appsync data source exports sanitised name', () => {
// WHEN
const ds = api.addNoneDataSource('ds', {
name: 'Produce-Custom',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', {
Type: 'NONE',
Name: 'ProduceCustom',
});
expect(ds.name).toBe('ProduceCustom');
});

test('appsync configures name and description correctly', () => {
// WHEN
api.addNoneDataSource('ds', {
Expand Down Expand Up @@ -116,5 +130,3 @@ describe('adding none data source from imported api', () => {
});
});
});


0 comments on commit 0b25265

Please sign in to comment.