Skip to content

Commit df333f6

Browse files
committed
Fixing CDK errors
1 parent 5c1d609 commit df333f6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

backend/src/iac/backend-stack.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)