-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(ecs): Allow passing executionRole to imported TaskDefinitions #24984
Comments
Fix proposed with #24987 |
Makes sense to me and thank you for your PR! |
…24987) See #24984 for details. TLDR; there's not a way currently exposed to define the `executionRole` on an imported `TaskDefinition`. This change allows optionally passing an `executionRole`. Fixes issue #24984. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
any idea why i get this error? it seems like it's saying that we don't have a taskRole in this task definition object either... "Error: This operation requires the taskRole in ImportedTaskDefinition to be defined. Add the 'taskRole' in ImportedTaskDefinitionProps to instantiate ImportedTaskDefinition
|
Describe the feature
Currently, when importing a TaskDefinition, either via
TaskDefinition.fromTaskDefinitionAttributes
orFargate.fromFargateTaskDefinitionAttributes
, you can pass ataskRole
, but not anexecutionRole
.In both cases, the
CommonTaskDefinitionAttributes
interface defines the attributes that can be passed when importing:aws-cdk/packages/aws-cdk-lib/aws-ecs/lib/base/task-definition.ts
Lines 231 to 253 in a98a981
As you can see, you can pass
taskRole
but notexecutionRole
.Use Case
I have a shared TaskDefinition that I use in other CDK apps. This TaskDefinition is triggered by an EventBridge rule. I share the TaskDefinition ARN, Task Role ARN (and Execution Role ARN) via
CfnOutput
s.Since I use a custom image stored in ECR, my TaskDefinition has both a Task Role and an Execution Role. When creating the EventBridge rule, the
EcsTask
target needs to allow theevents
ServicePrincipal
toiam:PassRole
both the Task Role and Execution Role for EventBridge to successfullyRunTask
.The
EcsTask
target already has this logic:aws-cdk/packages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts
Lines 206 to 213 in a98a981
However, because I can't pass the
executionRole
when I import the Task Definition, the logic to allowPassRole
isn't added, and the EventBridge invocation fails.I can work around this issue by forcing
taskDefinition.executionRole
assignment after the import:Proposed Solution
Currently, these
.from
imports rely on theImportedTaskDefinition
class: https://github.com/aws/aws-cdk/blob/a98a98147534f89a219521a2e51a6a1e25a2ac06/packages/aws-cdk-lib/aws-ecs/lib/base/_imported-task-definition.tsThis class already exposes an
executionRole
property:aws-cdk/packages/aws-cdk-lib/aws-ecs/lib/base/_imported-task-definition.ts
Lines 53 to 57 in a98a981
However, it's not exposed for setting in the static methods. I think we can just add
executionRole
as an optional parameter to theCommonTaskDefinitionAttributes
interface and allow passing it through.Other Information
No response
Acknowledgements
CDK version used
2.73.0
Environment details (OS name and version, etc.)
macOS
The text was updated successfully, but these errors were encountered: