icy-traffic-21460
08/07/2025, 7:56 PMexecution_role in awsx.ecs.EC2ServiceTaskDefinitionArgs?icy-traffic-21460
08/07/2025, 7:58 PMexecution_role is a DefaultRoleWithPolicyArgs which takes either a RoleWithPolicyArgs or a role_arn: str... i'd like to use a dynamic value inside RoleWithPolicyArgsicy-traffic-21460
08/07/2025, 7:59 PMicy-traffic-21460
08/07/2025, 8:11 PMRoleWithPolicyArgs i was trying to use policy_arns, which doesn't accept an inputwitty-candle-66007
08/07/2025, 8:28 PMicy-traffic-21460
08/07/2025, 8:55 PMecs_service = awsx.ecs.FargateService(f"service-{app}",
task_definition_args=awsx.ecs.FargateServiceTaskDefinitionArgs(
execution_role=awsx.awsx.DefaultRoleWithPolicyArgs(
args=awsx.awsx.RoleWithPolicyArgs(
managed_policy_arns=infra_stack.get_output('strata_db_asm_policy_arn').apply(lambda arn: [
"arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
arn
]),
),
),
)
)icy-traffic-21460
08/07/2025, 8:56 PMmanaged_policy_arns param as above works, whereas the policy_arns param doesn'twitty-candle-66007
08/07/2025, 9:35 PMmanaged_policy_arns. That’s an (the?) intent of managed_policy_arns vs policy_arns - to allow for dynamic values (i.e. Output<T>).
Or is that not working?icy-traffic-21460
08/07/2025, 9:36 PMmanaged_policy_arns is working, but the doc suggests it's deprecatedicy-traffic-21460
08/07/2025, 9:37 PMicy-traffic-21460
08/07/2025, 9:40 PMicy-traffic-21460
08/07/2025, 9:40 PMTheargument is deprecated. Use themanaged_policy_arnsresource instead. If Pulumi should exclusively manage all managed policy attachments (the current behavior of this argument), use theaws.iam.RolePolicyAttachmentresource as well.aws.iam.RolePolicyAttachmentsExclusive
witty-candle-66007
08/07/2025, 10:11 PMawsx doesn’t take that managed_policy_arns and turn it into RolePolicyAttachments and instead does use the deprecated managed_policy_arns property on the execution role.
So, the right answer for now is to not set managed_policy_arns and let the taskdefinition get created without the policy arns attached to the execution role.
Then you can use RolePolicyAttachment or RolePolicyAttachmentsExclusive and specify the execution role that was created - task_definition.execution_role.arnicy-traffic-21460
08/07/2025, 10:51 PMicy-traffic-21460
08/07/2025, 10:53 PMrole_arn instead of args in DefaultRoleWithPolicyArgs when specifying execution_role?icy-traffic-21460
08/07/2025, 10:55 PMpolicy_arns the replacement for managed_policy_arns on awsx.DefaultRoleWithPolicyArgs? back to my original question - why doesn't it accept Input?witty-candle-66007
08/07/2025, 11:00 PMicy-traffic-21460
08/08/2025, 12:03 AMmanaged_policy_arns if i don't fiddle with that role/policies anywhere else?witty-candle-66007
08/08/2025, 1:24 PM# Simple EC2 Task Definition
task_definition = awsx.ecs.EC2TaskDefinition("my-task",
containers={
"nginx": awsx.ecs.TaskDefinitionContainerDefinitionArgs(
name="nginx", # Container name is required
image="nginx:latest",
memory=512,
cpu=256,
port_mappings=[
awsx.ecs.TaskDefinitionPortMappingArgs(
container_port=8080,
host_port=8080, # EC2 tasks can map to specific host ports
protocol="tcp",
)
],
# Optional: Add environment variables
environment=[
awsx.ecs.TaskDefinitionKeyValuePairArgs(
name="ENV",
value="production"
)
],
)
},
cpu="512",
memory="1024"
)
roleattachment = aws.iam.RolePolicyAttachment("my-role-attachment",
role=task_definition.execution_role.name,
policy_arn="arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess"
)
# Fargate Service using AWSX with existing task definition
fargate_service = awsx.ecs.FargateService("my-fargate-service",
task_definition=task_definition.task_definition, # Use the existing task definition
.....
)witty-candle-66007
08/08/2025, 1:26 PMmanaged_role_arns it’s probably safe to do so since the upstream provider can’t get rid of it anytime soon since so many users use it.