diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/ec2/queue-processing-ecs-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/ec2/queue-processing-ecs-service.test.ts index 7be7e67aa95c5..66844caceb3bd 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/ec2/queue-processing-ecs-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/ec2/queue-processing-ecs-service.test.ts @@ -568,3 +568,16 @@ it('throws validation errors of the specific queue prop, when setting queue and }); }).toThrow(new Error('visibilityTimeout can be set only when queue is not set. Specify them in the QueueProps of the queue')); }); + +test('throws if image is undefined', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + // WHEN + expect(() => { + new ecsPatterns.QueueProcessingEc2Service(stack, 'Service', { + cluster: new ecs.Cluster(stack, 'Cluster', { vpc }), + memoryLimitMiB: 512, + }); + }).toThrow(new Error('image must be specified for EC2 queue processing service')); +}); \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.test.ts index c0fe1ffc86bef..3af988aa0bdc1 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.test.ts @@ -789,3 +789,40 @@ test('test Fargate queue worker service construct - with task definition', () => TaskRoleArn: { 'Fn::GetAtt': ['TaskDefTaskRole1EDB4A67', 'Arn'] }, }); }); + +test('test Fargate queue worker service construct - with task definition and image', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', { + memoryLimitMiB: 1024, + cpu: 512, + ephemeralStorageGiB: 30, + }); + taskDefinition.addContainer('QueueProcessingContainer', { + image: ecs.ContainerImage.fromRegistry('test'), + }); + + expect(() => { + new ecsPatterns.QueueProcessingFargateService(stack, 'Service', { + vpc, + taskDefinition, + image: ecs.ContainerImage.fromRegistry('test'), + }); + }).toThrow(new Error('You must specify only one of taskDefinition or image')); +}); + +test('test Fargate queue worker service construct - with no taskDefinition or image', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + expect(() => { + new ecsPatterns.QueueProcessingFargateService(stack, 'Service', { + vpc, + }); + }).toThrow(new Error('You must specify one of: taskDefinition or image')); +}); +