Open tomvisions opened 7 months ago
Yes, at this moment it only supports FargateTaskDefinition
This is because it will addContainer
which IFargateTaskDefinition does not have such method.
If you look at the TaskDefinition from CFN, the ContainerDefinitions is a prop of it, so when you import an existing TaskDefintion in CDK, CDK would not modify that TaskDefinition to render new ContainerDefinitions and that might be the reason. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
Thank you for the feedback. You placed this as a feature-request. Is there a place online to officially make that a feature request?
Describe the bug
When I created a Task Definition with the class: new ecs.FargateTaskDefinition, the object is of type cdk.aws_ecs.FargateTaskDefinition.
If I use the function ecs.FargateTaskDefinition.fromFargateTaskDefinitionAttributes to import a task definition already created, the object is of type IFargateTaskDefinition.
In some cases this might be a non issue, however, if I try to import the task definition into aws_ecs_patterns.ApplicationLoadBalancedFargateService, the taskDefinition key is looking for a value of type cdk.aws_ecs.FargateTaskDefinition, not type IFargateTaskDefinition. My IDE highlights this issue.
There might be a workaround for it, but I'm actively trying to keep this modular. In the service class I'm building (using ApplicationLoadBalancedFargateService), i want to import the already made task definition created in the task deifnition class.
Expected Behavior
When calling ApplicationLoadBalancedFargateService and applying the taskDefinition value, I should be able to call fromFargateTaskDefinitionAttributes to import a task definition already created from soomewhere else.
Current Behavior
It is described in "Describe the Bug", unless you want more details?
Reproduction Steps
Created this class.
`import {Stack, StackProps, CfnOutput, aws_iam, Size} from 'aws-cdk-lib'; import { Construct } from 'constructs'; import as cdk from "aws-cdk-lib"; import as ecs from "aws-cdk-lib/aws-ecs"; import {EcsTaskDefinitionRoleStack} from "./ecs-task-definition-role-stack" import {LogGroupStack} from "./log-group-stack"; import {EcrStack} from "./ecr-stack";
const stage = process.env.stage ?? "production" const region = process.env.region ?? "ca-central-1" const containerName =
api-${stage}
;const taskDefinitionArn = cdk.Fn.importValue('taskDefinitionArn')
export class EcsTaskDefinitionStack extends Stack { private _taskDefinition: cdk.aws_ecs.FargateTaskDefinition;
}`
When calling getECSTaskDefinition in a different class, it highlights the issue
TS2740: Type IFargateTaskDefinition is missing the following properties from type FargateTaskDefinition: family, containers, volumes, placementConstraints , and 33 more.
Possible Solution
When calling ApplicationLoadBalancedFargateService, have taskDefinition accept either FargateTaskDefinition or IFargateTaskDefinition.
Additional Information/Context
No response
CDK CLI Version
2.117.0
Framework Version
No response
Node.js Version
20.8.1
OS
MacOS
Language
TypeScript
Language Version
5.3.3
Other information
No response