11import * as cdk from 'aws-cdk-lib' ;
22import * as ec2 from 'aws-cdk-lib/aws-ec2' ;
3- import * as ecr from 'aws-cdk-lib/aws-ecr' ;
43import * as ecs from 'aws-cdk-lib/aws-ecs' ;
54import * as efs from 'aws-cdk-lib/aws-efs' ;
65import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2' ;
@@ -133,8 +132,10 @@ export class ComputeConstruct extends Construct {
133132
134133 // ==========================================================================
135134 // Task Execution Role (for pulling images and logging)
135+ // Role name must match SCP pattern: InnovationSandbox-ndx*
136136 // ==========================================================================
137137 const executionRole = new iam . Role ( this , 'ExecutionRole' , {
138+ roleName : `InnovationSandbox-ndx-${ deploymentMode } -exec` ,
138139 assumedBy : new iam . ServicePrincipal ( 'ecs-tasks.amazonaws.com' ) ,
139140 managedPolicies : [
140141 iam . ManagedPolicy . fromAwsManagedPolicyName ( 'service-role/AmazonECSTaskExecutionRolePolicy' ) ,
@@ -146,8 +147,10 @@ export class ComputeConstruct extends Construct {
146147
147148 // ==========================================================================
148149 // Task Role (for AWS AI services)
150+ // Role name must match SCP pattern: InnovationSandbox-ndx*
149151 // ==========================================================================
150152 const taskRole = new iam . Role ( this , 'TaskRole' , {
153+ roleName : `InnovationSandbox-ndx-${ deploymentMode } -task` ,
151154 assumedBy : new iam . ServicePrincipal ( 'ecs-tasks.amazonaws.com' ) ,
152155 } ) ;
153156
@@ -264,23 +267,20 @@ export class ComputeConstruct extends Construct {
264267 containerEnvironment . ADMIN_PASSWORD = props . adminPassword ;
265268 }
266269
267- // Look up the ECR repository for the Drupal image
268- const drupalRepository = ecr . Repository . fromRepositoryAttributes ( this , 'DrupalRepo' , {
269- repositoryArn : `arn:aws:ecr:${ cdk . Stack . of ( this ) . region } :${ cdk . Stack . of ( this ) . account } :repository/localgov-drupal` ,
270- repositoryName : 'localgov-drupal' ,
271- } ) ;
272-
273- // Add container
270+ // Add container - pull from GitHub Container Registry
274271 const container = taskDefinition . addContainer ( 'drupal' , {
275- image : ecs . ContainerImage . fromEcrRepository ( drupalRepository , 'latest ') ,
272+ image : ecs . ContainerImage . fromRegistry ( 'ghcr.io/co-cddo/ndx_try_aws_scenarios-localgov_drupal:fix-menu-links-search-index ') ,
276273 logging : ecs . LogDrivers . awsLogs ( {
277- streamPrefix : 'drupal' ,
278274 logGroup : this . logGroup ,
275+ streamPrefix : 'drupal' ,
279276 } ) ,
280- environment : containerEnvironment ,
281- secrets : {
282- DB_USER : ecs . Secret . fromSecretsManager ( props . databaseSecret , 'username' ) ,
283- DB_PASSWORD : ecs . Secret . fromSecretsManager ( props . databaseSecret , 'password' ) ,
277+ environment : {
278+ ...containerEnvironment ,
279+ // Use CloudFormation dynamic references for credentials
280+ // This resolves at deploy time, avoiding ECS secret fetch at runtime
281+ // (workaround for sandbox SCP restrictions on secretsmanager:GetSecretValue)
282+ DB_USER : props . databaseSecret . secretValueFromJson ( 'username' ) . unsafeUnwrap ( ) ,
283+ DB_PASSWORD : props . databaseSecret . secretValueFromJson ( 'password' ) . unsafeUnwrap ( ) ,
284284 } ,
285285 portMappings : [
286286 {
0 commit comments