Skip to content

feat(ecs-patterns): allow specifying task role for QueueProcessingFargateService and QueueProcessingEc2Service#37320

Closed
syukawa-gh wants to merge 4 commits intoaws:mainfrom
syukawa-gh:feat/ecs-patterns-queue-processing-task-role-clean
Closed

feat(ecs-patterns): allow specifying task role for QueueProcessingFargateService and QueueProcessingEc2Service#37320
syukawa-gh wants to merge 4 commits intoaws:mainfrom
syukawa-gh:feat/ecs-patterns-queue-processing-task-role-clean

Conversation

@syukawa-gh
Copy link
Copy Markdown
Contributor

Add a taskRole property to QueueProcessingServiceBaseProps that is passed to the internally created task definition. This allows users to provide a custom IAM role for the task without having to create a full task definition.

Closes #16297

…gateService and QueueProcessingEc2Service

Add a taskRole property to QueueProcessingServiceBaseProps that is
passed to the internally created task definition. This allows users
to provide a custom IAM role for the task without having to create
a full task definition.

Closes aws#16297
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Mar 23, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team March 23, 2026 03:52
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Features must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@syukawa-gh
Copy link
Copy Markdown
Contributor Author

Exemption Request: Integration test snapshot cannot be generated locally because the taskRole property is a new addition not yet in the released aws-cdk-lib. Unit test and README have been added.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Mar 23, 2026
@alvazjor alvazjor self-assigned this Mar 23, 2026
@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Mar 23, 2026
Copy link
Copy Markdown
Contributor

@alvazjor alvazjor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @syukawa-gh
Added some comments. Once the changes are in place, this could be merged.
Related to the integration test exemption, even though the code change is straightforward, we want to verify the deployment behavior is correct (e.g., the task role is properly attached to the task definition at deploy time). Please add an integ tests that deploys a QueueProcessingFargateService and QueueProcessingEc2Service with a custom taskRole and asserts the resulting task definition has the expected role ARN.

const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
const iam = require('../../../aws-iam');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a proper import for this dependency. require is a pattern we dont use in this repo

/**
* The role that will be used by the task.
*
* Only used when `image` is specified (not when `taskDefinition` is provided).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When taskDefinition is provided, the new taskRole prop is silently ignored. The existing code already validates the image + taskDefinition conflict with a clear error, we should also add a similar validation (or expand the existing one) for this new prop

// Create a Task Definition for the container to start
this.taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef', {
family: props.family,
taskRole: props.taskRole,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also require proper unit + integration testing

@alvazjor alvazjor removed the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Mar 23, 2026
@syukawa-gh
Copy link
Copy Markdown
Contributor Author

Superseded by new PR with review fixes applied (proper import, taskRole+taskDefinition validation, integ test). Rebased on latest main to remove unrelated file changes.

@syukawa-gh syukawa-gh closed this Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(ecs-patterns): QueueProcessingFargateService - Allow task role to be specified

4 participants