First of all, yes this is a bug that is being tracked on Github. But until that is fixed you’ll need to use a workaround.
The workaround works as following
Or like following code
= new Ec2TaskDefinition(this, 'TempTask');
const tempTaskDefinition .addContainer('TheContainer', {
taskDefinition: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
image: 256
memoryLimitMiB; })
That is the minimal needed for a task definition
= new Ec2Service(this, "ServiceId", {
const service ,
cluster: tempTaskDefinition,
taskDefinition; })
Ok, that is enough for our service, and now we’ll replace the property TaskDefinition with our own arn
.node.defaultChild as CfnService)?.addPropertyOverride("TaskDefinition", "arn:aws:ecs:{region}:{account-id}:task-definition/{taskdefinition-name}"); (service
Now the LATEST task-definition will be selected (if you want a specific version you can always add :{versionid}
)
And that takes care of the error that you can’t import an exisiting TaskDefinition!
Is this a nice solution? No 😪 but until they get .fromEc2TaskDefinitionArn
, fromTaskDefinitionArn
, fromFargateTaskDefinitionArn
working with a new service, this is the closest you will get.