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.

(ECS): ability to add SystemControls to Container Definition

See original GitHub issue

❓ General Issue

The Question

Hello, So I realized that the non-Cfn construct for the ContainerDefinition doesn’t have a way to add SystemControls (SystemControls) to it.

But it is available through ecs.CfnTaskDefinition.ContainerDefinitionProperty. Now, I’m mixing Cfn* classes with non-Cfn* classes and it could get a bit messy. I’ll be posting my code here and maybe someone already went through this and help me out.

ALSO is there way I can directly access arbitrary properties on resources? I was thinking of adding that SystemControls manually, but I couldn’t find the way.

Thanks.

Environment

  • CDK CLI Version: 1.118.0 (build a4f0418)
  • Module Version:@aws-cdk/aws-ecs”: “^1.118.0”
  • Node.js Version: v14.16.1
  • OS: all (Windows 10)
  • Language (Version): nodejs v14.16.1

Other information

const cloudwatchLog = new ecs.AwsLogDriver({
	logRetention: awsLogs.RetentionDays.ONE_WEEK,
	streamPrefix: 'activity-service-websockets-fargate-task'
});

const taskExecRole = new iam.Role(this, 'activity-service-task-exec-role', {
	roleName: 'activity-service-task-exec-role',
	assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
	managedPolicies: [
		iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSSMFullAccess'),
		iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchFullAccess')
	]
});

const taskDefinition = new ecs.CfnTaskDefinition(this, 'taskdef', {
	cpu: config.Environment === 'live' ? 2048 : 512,
	memory: config.Environment === 'live' ? 4096 : 1024,
	taskRoleArn: taskExecRole.roleArn
});

const dockerContainerDef = new ecs.ContainerDefinition(this, 'activity-service-websockets-container', { // this doesn't work
	image: new ecs.AssetImage('./docker'),
	logging: cloudwatchLog,
	environment: {
		LARGE_SCALE_TEST: '1'
	},
	privileged: true,
	taskDefinition // because this is of the Cfn* flavor
});

const cfnDockerContainerDef = dockerContainerDef.renderContainerDefinition();

taskDefinition.containerDefinitions = [ cfnDockerContainerDef ];
cfnDockerContainerDef.systemControls = [
	{
		namespace: 'net.ipv4.tcp_tw_reuse',
		value: '1'
	},
	{
		namespace: 'net.ipv4.tcp_tw_recycle',
		value: '1'
	},
	{
		namespace: 'net.ipv4.tcp_fin_timeout',
		value: '60'
	}
];

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
peterwoodworthcommented, Nov 12, 2021

Thanks for bringing my attention to this @schuberttobias

it’s been approved and should merge soon, so it should be out on the next CDK release

2reactions
peterwoodworthcommented, Sep 8, 2021

I’ve converted this into a feature request. I’ve been unable to find a workaround for this using L2 resources.

@Mayhem93 do you need any help with getting this to run still? Instead of using the higher level ContainerDefinition constructs, you’ll need to configure that manually in the CfnTaskDefinition

Read more comments on GitHub >

github_iconTop Results From Across the Web

ContainerDefinition - Amazon Elastic Container Service
This parameter maps to SecurityOpt in the Create a container section of the Docker Remote API and the --security-opt option to docker run...
Read more >
community.aws.ecs_taskdefinition module – register a task ...
Registers or deregisters task definitions in the Amazon Web Services (AWS) EC2 Container Service (ECS). Requirements . The below requirements are needed...
Read more >
aws-cdk.aws-ecs · PyPI
The following example creates an Amazon ECS cluster, adds capacity to it, and runs a service on it: # vpc: ec2.Vpc # Create...
Read more >
ECS deployment tutorial - Harness.io Docs
Add your Docker image to Harness. Define your ECS container and service specs in Harness. Create and deploy an ECS Rolling deployment. Once...
Read more >
aws ecs register-task-definition - Fig.io
Optionally, you can add data volumes to your containers with the volumes ... see Amazon ECS Task Definitions in the Amazon Elastic Container...
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