File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -364,22 +364,22 @@ export class BackendStack extends cdk.Stack {
364364 ] ,
365365 } ) ;
366366
367- // Attach the execution role to the API
368- const apiResource = api . node . findChild ( 'Default' ) as apigateway . CfnRestApi ;
369- apiResource . addPropertyOverride ( 'Policy' , {
370- Version : '2012-10-17' ,
371- Statement : [
372- {
373- Effect : 'Allow' ,
374- Principal : {
375- Service : 'apigateway.amazonaws.com' ,
376- } ,
377- Action : 'sts:AssumeRole' ,
378- Resource : executionRole . roleArn ,
379- } ,
367+ // Replace the problematic code with a proper way to set the API Gateway policy
368+ const apiPolicy = new iam . PolicyDocument ( {
369+ statements : [
370+ new iam . PolicyStatement ( {
371+ effect : iam . Effect . ALLOW ,
372+ principals : [ new iam . ServicePrincipal ( 'apigateway.amazonaws.com' ) ] ,
373+ actions : [ 'sts:AssumeRole' ] ,
374+ resources : [ executionRole . roleArn ] ,
375+ } ) ,
380376 ] ,
381377 } ) ;
382378
379+ // Apply the policy to the API Gateway using CfnRestApi
380+ const cfnApi = api . node . defaultChild as apigateway . CfnRestApi ;
381+ cfnApi . policy = apiPolicy . toJSON ( ) ;
382+
383383 // Outputs
384384 new cdk . CfnOutput ( this , 'ReportsTableName' , {
385385 value : reportsTable . tableName ,
You can’t perform that action at this time.
0 commit comments