@@ -126,13 +126,20 @@ export class BackendStack extends cdk.Stack {
126126 ) ;
127127
128128 // Create Task Execution Role - this is used during task startup
129- const taskExecutionRole = new iam . Role ( this , `${ appName } TaskExecutionRole-${ props . environment } ` , {
130- assumedBy : new iam . ServicePrincipal ( 'ecs-tasks.amazonaws.com' ) ,
131- description : 'Role that the ECS service uses to pull container images and publish logs to CloudWatch' ,
132- managedPolicies : [
133- iam . ManagedPolicy . fromAwsManagedPolicyName ( 'service-role/AmazonECSTaskExecutionRolePolicy' )
134- ]
135- } ) ;
129+ const taskExecutionRole = new iam . Role (
130+ this ,
131+ `${ appName } TaskExecutionRole-${ props . environment } ` ,
132+ {
133+ assumedBy : new iam . ServicePrincipal ( 'ecs-tasks.amazonaws.com' ) ,
134+ description :
135+ 'Role that the ECS service uses to pull container images and publish logs to CloudWatch' ,
136+ managedPolicies : [
137+ iam . ManagedPolicy . fromAwsManagedPolicyName (
138+ 'service-role/AmazonECSTaskExecutionRolePolicy' ,
139+ ) ,
140+ ] ,
141+ } ,
142+ ) ;
136143
137144 // Create Task Role - this is used by the container during runtime
138145 const taskRole = new iam . Role ( this , `${ appName } TaskRole-${ props . environment } ` , {
@@ -145,16 +152,15 @@ export class BackendStack extends cdk.Stack {
145152 reportsTable . grantReadWriteData ( taskRole ) ;
146153
147154 // Add permission to read Perplexity API key from Secrets Manager
148- taskRole . addToPolicy ( new iam . PolicyStatement ( {
149- effect : iam . Effect . ALLOW ,
150- actions : [
151- 'secretsmanager:GetSecretValue' ,
152- 'secretsmanager:DescribeSecret'
153- ] ,
154- resources : [
155- `arn:aws:secretsmanager:${ this . region } :${ this . account } :secret:medical-reports-explainer/${ props . environment } /perplexity-api-key-*`
156- ]
157- } ) ) ;
155+ taskRole . addToPolicy (
156+ new iam . PolicyStatement ( {
157+ effect : iam . Effect . ALLOW ,
158+ actions : [ 'secretsmanager:GetSecretValue' , 'secretsmanager:DescribeSecret' ] ,
159+ resources : [
160+ `arn:aws:secretsmanager:${ this . region } :${ this . account } :secret:medical-reports-explainer/${ props . environment } /perplexity-api-key-*` ,
161+ ] ,
162+ } ) ,
163+ ) ;
158164
159165 // Task Definition with explicit roles
160166 const taskDefinition = new ecs . FargateTaskDefinition (
@@ -163,8 +169,8 @@ export class BackendStack extends cdk.Stack {
163169 {
164170 memoryLimitMiB : isProd ? 1024 : 512 ,
165171 cpu : isProd ? 512 : 256 ,
166- taskRole : taskRole , // Role that the application uses to call AWS services
167- executionRole : taskExecutionRole // Role that ECS uses to pull images and write logs
172+ taskRole : taskRole , // Role that the application uses to call AWS services
173+ executionRole : taskExecutionRole , // Role that ECS uses to pull images and write logs
168174 } ,
169175 ) ;
170176
0 commit comments