Skip to content

Commit 63ec7f9

Browse files
authored
chore(appsync): improve error message for missing iam authorization mode (#33501)
### Issue # (if applicable) Closes #33465 ### Reason for this change The error message when using grant methods like `grantPublish()` and `grantSubscribe()` on an Event API without IAM authorization mode needs improvement. Currently, users get a confusing error without clear guidance on how to fix it. The error should clearly explain: 1. Why the operation failed (you tried to use a grant method on an Event API with missing IAM authorization mode) 2. How to fix it (add IAM authorization mode to the auth providers list) ### Description of changes Rephrased the error message. ### Describe any new or updated permissions being added ### Description of how you validated changes ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8494ad0 commit 63ec7f9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/aws-cdk-lib/aws-appsync/lib/eventapi.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ export abstract class EventApiBase extends ApiBase implements IEventApi {
211211
*/
212212
public grant(grantee: IGrantable, resources: AppSyncEventResource, ...actions: string[]): Grant {
213213
if (!this.authProviderTypes.includes(AppSyncAuthorizationType.IAM)) {
214-
throw new ValidationError('IAM Authorization mode is not configured on this API.', this);
214+
throw new ValidationError('Cannot use grant method because IAM Authorization mode is missing in the auth providers on this API.',
215+
this,
216+
);
215217
}
216218
return Grant.addToPrincipal({
217219
grantee,

packages/aws-cdk-lib/aws-appsync/test/appsync-eventapi.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ describe('Event API security grant tests', () => {
361361
const api = new appsync.EventApi(stack, 'api', { apiName: 'api' });
362362

363363
// THEN
364-
expect(() => api.grantConnect(func)).toThrow('IAM Authorization mode is not configured on this API.');
364+
expect(() => api.grantConnect(func)).toThrow('Cannot use grant method because IAM Authorization mode is missing in the auth providers on this API.');
365365
});
366366

367367
test('Appsync Event API - grant publish for all channel namespaces within an API', () => {

0 commit comments

Comments
 (0)