Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecs): interactive option in ContainerDefinitionOptions #28536

Merged
merged 11 commits into from
Jan 2, 2024
13 changes: 13 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ const taskDef = new ecs.TaskDefinition(this, 'TaskDef', {
taskDef.grantRun(role);
```

To deploy containerized applications that require the allocation of standard input (stdin) or a terminal (tty), you can set the `interactive` propertiy to `true` in `ContainerDefinitionOptions`.
badmintoncryer marked this conversation as resolved.
Show resolved Hide resolved

This parameter corresponds to OpenStdin in the [Create a container](https://docs.docker.com/engine/api/v1.35/#tag/Container/operation/ContainerCreate) section of the [Docker Remote API](https://docs.docker.com/engine/api/v1.35/) and the `--interactive` option to `docker run`.
badmintoncryer marked this conversation as resolved.
Show resolved Hide resolved

```ts
declare const taskDefinition: ecs.TaskDefinition;

taskDefinition.addContainer("Container", {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
interactive: true,
});
```

### Images

Images supply the software that runs inside the container. Images can be
Expand Down
10 changes: 10 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as iam from '../../aws-iam';
import * as secretsmanager from '../../aws-secretsmanager';
import * as ssm from '../../aws-ssm';
import * as cdk from '../../core';
import { IResolvable } from '../../core';
badmintoncryer marked this conversation as resolved.
Show resolved Hide resolved

/**
* Specify the secret's version id or version stage
Expand Down Expand Up @@ -251,6 +252,14 @@ export interface ContainerDefinitionOptions {
*/
readonly hostname?: string;

/**
* When this parameter is true, you can deploy containerized applications that require stdin or a tty to be allocated.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinition.html#cfn-ecs-taskdefinition-containerdefinition-interactive
* @default - false
*/
readonly interactive?: boolean | IResolvable;
badmintoncryer marked this conversation as resolved.
Show resolved Hide resolved

/**
* The amount (in MiB) of memory to present to the container.
*
Expand Down Expand Up @@ -797,6 +806,7 @@ export class ContainerDefinition extends Construct {
essential: this.essential,
hostname: this.props.hostname,
image: this.imageConfig.imageName,
interactive: this.props.interactive,
memory: this.props.memoryLimitMiB,
memoryReservation: this.props.memoryReservationMiB,
mountPoints: cdk.Lazy.any({ produce: () => this.mountPoints.map(renderMountPoint) }, { omitEmptyArray: true }),
Expand Down
26 changes: 26 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/test/container-definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2636,4 +2636,30 @@ describe('container definition', () => {
});
});
});

test('can specify interactive parameter', () => {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');

new ecs.ContainerDefinition(stack, 'Container', {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
taskDefinition,
memoryLimitMiB: 2048,
interactive: true,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Essential: true,
Image: '/aws/aws-example-app',
Memory: 2048,
Name: 'Container',
Interactive: true,
},
],
});
});
});
Loading