Skip to content

Commit

Permalink
fix(aws-apigatewayv2): incorrect arn function causing unwanted behavi…
Browse files Browse the repository at this point in the history
…or in websocket iam auth
  • Loading branch information
Ike Nefcy committed Jan 23, 2025
1 parent 076aa9f commit a26c45b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ new iam.Role(stack, 'test-iam-role', {
actions: ['execute-api:Invoke'],
resources: [
websocketApi.arnForExecuteApi(),
websocketApi.arnForExecuteApi('$connect', 'prod'),
websocketApi.arnForExecuteApi('connect', 'prod'),
],
}),
],
Expand Down
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-apigatewayv2/lib/websocket/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export class WebSocketApi extends ApiBase implements IWebSocketApi {
* If 'stage' is not specified, it also defaults to '*', representing all stages.
*/
public arnForExecuteApi(route?: string, stage?: string): string {
if (route&&!route.startsWith('$')) {
route = `$${route}`;
};

return Stack.of(this).formatArn({
service: 'execute-api',
resource: this.apiId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('WebSocketApi', () => {
{ Ref: 'AWS::AccountId' },
':',
stack.resolve(api.apiId),
'/stage/route',
'/stage/$route',
]],
});
});
Expand Down

0 comments on commit a26c45b

Please sign in to comment.