question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

efsVolumeConfiguration is unsupported in ecs.CfnTaskDefinition

See original GitHub issue

I’m trying to use the newish EFS mounts in an EC2 ECS cluster and the resources are refusing to include the extra parameters even if I try to use the raw resources.

https://aws.amazon.com/about-aws/whats-new/2020/01/amazon-ecs-preview-support-for-efs-file-systems-now-available/

Reproduction Steps

import * as ec2 from "@aws-cdk/aws-ec2";
import * as ecs from "@aws-cdk/aws-ecs";
import * as efs from "@aws-cdk/aws-efs";
import * as elbv2 from "@aws-cdk/aws-elasticloadbalancingv2";
import * as logs from "@aws-cdk/aws-logs";
import * as cdk from "@aws-cdk/core";

export interface WebserverProps {
    filesystem: efs.IEfsFileSystem;
}

export class Webserver extends cdk.Construct {
    public constructor(scope: cdk.Construct, id: string, props: WebserverProps) {
        super(scope, id);
        
        // https://github.com/aws/containers-roadmap/issues/53 - EFS + Fargate
        const taskDefinition = new ecs.TaskDefinition(this, "TaskDefinition", {
            compatibility: ecs.Compatibility.EC2,
        });

        // Patch in the EFS support.
        const rawTask = taskDefinition.node.findChild("Resource") as ecs.CfnTaskDefinition;
        rawTask.volumes = [
            {
                name: "invision",
                efsVolumeConfiguration: {
                    fileSystemId: props.filesystem.fileSystemId,
                    rootDirectory: "/",
                },
            } as ecs.CfnTaskDefinition.VolumeProperty,
        ];
    }
}

Error Log

None, the resource just refuses to include the efsVolumeConfiguration options.

Environment

  • CLI Version : 1.30.0
  • Framework Version: 1.30.0
  • OS : Windows 10
  • Language : Typescript

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
michaelmoussacommented, May 21, 2020

I managed to devise a fairly consistent workaround to handle EFS volume configurations (as well as EFS access points and filesystem policies) while I wait for CFN+CDK support.

Full repo with the examples is https://github.com/aws-samples/amazon-efs-integrations/ if you want to give it a try separately before trying this workaround on your real code.

Basically, I let the ApplicationLoadBalanced(Ec2|Fargate)Service construct from ECS Patterns create the initial task definition, then I use an AwsCustomResource construct to execute a registerTaskDefinition call against that same task definition and pass it the actual task definition configuration I need in order to configure my EFS volume mounts. This ends up creating a new revision, which I then use a CDK escape hatch to apply to the ECS service. This does result in a longer first-time deployment (since CDK will wait for the ECS service to stabilize before goes and changes everything), but subsequent deployments are fine.

The reason this all works is because, while there’s no CFN support yet for EFS volume configurations in ECS, there is support for it in the SDK, which does not reject a task definition using efsVolumeConfiguration like the CDK TaskDefinition derivatives would.

I like this approach over the other workarounds I’ve seen because (a) it lets me do everything in CDK with no additional commands or manual console instructions required, (b) it lets me take advantage of all the conveniences that the ApplicationLoadBalanced(Ec2|Fargate)Service constructs provide, and © once CDK support for these capabilities is enabled, it should make refactoring very easy since all of the task definition configuration is already there alongside where I initially create the service.

Hope this helps somebody!

4reactions
airmonitorcommented, Nov 18, 2020

Now you can add mount point much easier:

task = FargateTaskDefinition(self, "Task",...)

container = task.add_container("container", ...)

container_volume_mount_point = ecs.MountPoint(
            read_only=False,
            container_path="/bitnami/wordpress",
            source_volume=efs_volume.name
        )
container.add_mount_points(container_volume_mount_point)
Read more comments on GitHub >

github_iconTop Results From Across the Web

class CfnTaskDefinition (construct) · AWS CDK
The AWS::ECS::TaskDefinition resource describes the container and volume definitions of an Amazon Elastic Container Service (Amazon ECS) task. You can specify ...
Read more >
Cloudformation Error - Encountered unsupported property ...
... the property "efsVolumeConfiguration". Currently, the only way to mount EFS volumes on Fargate tasks is via the ECS Console, SDK or CLI....
Read more >
awsecs - Go Packages
Amazon ECS Construct Library. This package contains constructs for working with Amazon Elastic Container Service (Amazon ECS).
Read more >
aws-cdk efsVolumeConfiguration is unsupported in ecs ... - GitAnswer
aws-cdk efsVolumeConfiguration is unsupported in ecs.CfnTaskDefinition - TypeScript. I'm trying to use the newish EFS mounts in an EC2 ECS cluster and the ......
Read more >
aws.ecs.TaskDefinition - Pulumi
Manages a revision of an ECS task definition to be used in aws.ecs.Service . ... efsVolumeConfiguration Changes to this property will trigger replacement....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found