Skip to content

Commit

Permalink
feat(client-ecs): This release adds support for task scale-in protect…
Browse files Browse the repository at this point in the history
…ion with updateTaskProtection and getTaskProtection APIs. UpdateTaskProtection API can be used to protect a service managed task from being terminated by scale-in events and getTaskProtection API to get the scale-in protection status of a task.
  • Loading branch information
awstools committed Nov 10, 2022
1 parent 6bebb78 commit a5eede0
Show file tree
Hide file tree
Showing 9 changed files with 1,251 additions and 312 deletions.
104 changes: 102 additions & 2 deletions clients/client-ecs/src/ECS.ts
Expand Up @@ -106,6 +106,11 @@ import {
ExecuteCommandCommandInput,
ExecuteCommandCommandOutput,
} from "./commands/ExecuteCommandCommand";
import {
GetTaskProtectionCommand,
GetTaskProtectionCommandInput,
GetTaskProtectionCommandOutput,
} from "./commands/GetTaskProtectionCommand";
import {
ListAccountSettingsCommand,
ListAccountSettingsCommandInput,
Expand Down Expand Up @@ -236,6 +241,11 @@ import {
UpdateServicePrimaryTaskSetCommandInput,
UpdateServicePrimaryTaskSetCommandOutput,
} from "./commands/UpdateServicePrimaryTaskSetCommand";
import {
UpdateTaskProtectionCommand,
UpdateTaskProtectionCommandInput,
UpdateTaskProtectionCommandOutput,
} from "./commands/UpdateTaskProtectionCommand";
import {
UpdateTaskSetCommand,
UpdateTaskSetCommandInput,
Expand Down Expand Up @@ -418,8 +428,9 @@ export class ECS extends ECSClient {
* <p>When creating a service that uses the <code>EXTERNAL</code> deployment controller, you
* can specify only parameters that aren't controlled at the task set level. The only
* required parameter is the service name. You control your services using the <a>CreateTaskSet</a> operation. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-types.html">Amazon ECS deployment types</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
* <p>When the service scheduler launches new tasks, it determines task placement. For information
* about task placement and task placement strategies, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement.html">Amazon ECS task placement</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
* <p>When the service scheduler launches new tasks, it determines task placement. For
* information about task placement and task placement strategies, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement.html">Amazon ECS
* task placement</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
*/
public createService(
args: CreateServiceCommandInput,
Expand Down Expand Up @@ -1116,6 +1127,38 @@ export class ECS extends ECSClient {
}
}

/**
* <p>Retrieves the protection status of tasks in an Amazon ECS service.</p>
*/
public getTaskProtection(
args: GetTaskProtectionCommandInput,
options?: __HttpHandlerOptions
): Promise<GetTaskProtectionCommandOutput>;
public getTaskProtection(
args: GetTaskProtectionCommandInput,
cb: (err: any, data?: GetTaskProtectionCommandOutput) => void
): void;
public getTaskProtection(
args: GetTaskProtectionCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: GetTaskProtectionCommandOutput) => void
): void;
public getTaskProtection(
args: GetTaskProtectionCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: GetTaskProtectionCommandOutput) => void),
cb?: (err: any, data?: GetTaskProtectionCommandOutput) => void
): Promise<GetTaskProtectionCommandOutput> | void {
const command = new GetTaskProtectionCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Lists the account settings for a specified principal.</p>
*/
Expand Down Expand Up @@ -2372,6 +2415,63 @@ export class ECS extends ECSClient {
}
}

/**
* <p>Updates the protection status of a task. You can set <code>protectionEnabled</code> to
* <code>true</code> to protect your task from termination during scale-in events from
* <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html">Service
* Autoscaling</a> or <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-types.html">deployments</a>.</p>
* <p>Task-protection, by default, expires after 2 hours at which point Amazon ECS unsets the
* <code>protectionEnabled</code> property making the task eligible for termination by
* a subsequent scale-in event.</p>
* <p>You can specify a custom expiration period for task protection from 1 minute to up to
* 2,880 minutes (48 hours). To specify the custom expiration period, set the
* <code>expiresInMinutes</code> property. The <code>expiresInMinutes</code> property
* is always reset when you invoke this operation for a task that already has
* <code>protectionEnabled</code> set to <code>true</code>. You can keep extending the
* protection expiration period of a task by invoking this operation repeatedly.</p>
* <p>To learn more about Amazon ECS task protection, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-scale-in-protection.html">Task scale-in
* protection</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
* <note>
* <p>This operation is only supported for tasks belonging to an Amazon ECS service. Invoking
* this operation for a standalone task will result in an <code>TASK_NOT_VALID</code>
* failure. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/api_failures_messages.html.html">API
* failure reasons</a>.</p>
* </note>
* <important>
* <p>If you prefer to set task protection from within the container, we recommend using
* the <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-endpoint.html">Amazon ECS container
* agent endpoint</a>.</p>
* </important>
*/
public updateTaskProtection(
args: UpdateTaskProtectionCommandInput,
options?: __HttpHandlerOptions
): Promise<UpdateTaskProtectionCommandOutput>;
public updateTaskProtection(
args: UpdateTaskProtectionCommandInput,
cb: (err: any, data?: UpdateTaskProtectionCommandOutput) => void
): void;
public updateTaskProtection(
args: UpdateTaskProtectionCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: UpdateTaskProtectionCommandOutput) => void
): void;
public updateTaskProtection(
args: UpdateTaskProtectionCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: UpdateTaskProtectionCommandOutput) => void),
cb?: (err: any, data?: UpdateTaskProtectionCommandOutput) => void
): Promise<UpdateTaskProtectionCommandOutput> | void {
const command = new UpdateTaskProtectionCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Modifies a task set. This is used when a service uses the <code>EXTERNAL</code>
* deployment controller type. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-types.html">Amazon ECS Deployment
Expand Down
9 changes: 9 additions & 0 deletions clients/client-ecs/src/ECSClient.ts
Expand Up @@ -95,6 +95,7 @@ import {
DiscoverPollEndpointCommandOutput,
} from "./commands/DiscoverPollEndpointCommand";
import { ExecuteCommandCommandInput, ExecuteCommandCommandOutput } from "./commands/ExecuteCommandCommand";
import { GetTaskProtectionCommandInput, GetTaskProtectionCommandOutput } from "./commands/GetTaskProtectionCommand";
import {
ListAccountSettingsCommandInput,
ListAccountSettingsCommandOutput,
Expand Down Expand Up @@ -176,6 +177,10 @@ import {
UpdateServicePrimaryTaskSetCommandInput,
UpdateServicePrimaryTaskSetCommandOutput,
} from "./commands/UpdateServicePrimaryTaskSetCommand";
import {
UpdateTaskProtectionCommandInput,
UpdateTaskProtectionCommandOutput,
} from "./commands/UpdateTaskProtectionCommand";
import { UpdateTaskSetCommandInput, UpdateTaskSetCommandOutput } from "./commands/UpdateTaskSetCommand";
import {
ClientInputEndpointParameters,
Expand Down Expand Up @@ -207,6 +212,7 @@ export type ServiceInputTypes =
| DescribeTasksCommandInput
| DiscoverPollEndpointCommandInput
| ExecuteCommandCommandInput
| GetTaskProtectionCommandInput
| ListAccountSettingsCommandInput
| ListAttributesCommandInput
| ListClustersCommandInput
Expand Down Expand Up @@ -237,6 +243,7 @@ export type ServiceInputTypes =
| UpdateContainerInstancesStateCommandInput
| UpdateServiceCommandInput
| UpdateServicePrimaryTaskSetCommandInput
| UpdateTaskProtectionCommandInput
| UpdateTaskSetCommandInput;

export type ServiceOutputTypes =
Expand All @@ -261,6 +268,7 @@ export type ServiceOutputTypes =
| DescribeTasksCommandOutput
| DiscoverPollEndpointCommandOutput
| ExecuteCommandCommandOutput
| GetTaskProtectionCommandOutput
| ListAccountSettingsCommandOutput
| ListAttributesCommandOutput
| ListClustersCommandOutput
Expand Down Expand Up @@ -291,6 +299,7 @@ export type ServiceOutputTypes =
| UpdateContainerInstancesStateCommandOutput
| UpdateServiceCommandOutput
| UpdateServicePrimaryTaskSetCommandOutput
| UpdateTaskProtectionCommandOutput
| UpdateTaskSetCommandOutput;

export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__HttpHandlerOptions>> {
Expand Down
5 changes: 3 additions & 2 deletions clients/client-ecs/src/commands/CreateServiceCommand.ts
Expand Up @@ -106,8 +106,9 @@ export interface CreateServiceCommandOutput extends CreateServiceResponse, __Met
* <p>When creating a service that uses the <code>EXTERNAL</code> deployment controller, you
* can specify only parameters that aren't controlled at the task set level. The only
* required parameter is the service name. You control your services using the <a>CreateTaskSet</a> operation. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-types.html">Amazon ECS deployment types</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
* <p>When the service scheduler launches new tasks, it determines task placement. For information
* about task placement and task placement strategies, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement.html">Amazon ECS task placement</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
* <p>When the service scheduler launches new tasks, it determines task placement. For
* information about task placement and task placement strategies, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement.html">Amazon ECS
* task placement</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
Expand Down
114 changes: 114 additions & 0 deletions clients/client-ecs/src/commands/GetTaskProtectionCommand.ts
@@ -0,0 +1,114 @@
// smithy-typescript generated code
import { EndpointParameterInstructions, getEndpointPlugin } from "@aws-sdk/middleware-endpoint";
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

import { ECSClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../ECSClient";
import {
GetTaskProtectionRequest,
GetTaskProtectionRequestFilterSensitiveLog,
GetTaskProtectionResponse,
GetTaskProtectionResponseFilterSensitiveLog,
} from "../models/models_0";
import {
deserializeAws_json1_1GetTaskProtectionCommand,
serializeAws_json1_1GetTaskProtectionCommand,
} from "../protocols/Aws_json1_1";

export interface GetTaskProtectionCommandInput extends GetTaskProtectionRequest {}
export interface GetTaskProtectionCommandOutput extends GetTaskProtectionResponse, __MetadataBearer {}

/**
* <p>Retrieves the protection status of tasks in an Amazon ECS service.</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
* import { ECSClient, GetTaskProtectionCommand } from "@aws-sdk/client-ecs"; // ES Modules import
* // const { ECSClient, GetTaskProtectionCommand } = require("@aws-sdk/client-ecs"); // CommonJS import
* const client = new ECSClient(config);
* const command = new GetTaskProtectionCommand(input);
* const response = await client.send(command);
* ```
*
* @see {@link GetTaskProtectionCommandInput} for command's `input` shape.
* @see {@link GetTaskProtectionCommandOutput} for command's `response` shape.
* @see {@link ECSClientResolvedConfig | config} for ECSClient's `config` shape.
*
*/
export class GetTaskProtectionCommand extends $Command<
GetTaskProtectionCommandInput,
GetTaskProtectionCommandOutput,
ECSClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties

public static getEndpointParameterInstructions(): EndpointParameterInstructions {
return {
UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
Endpoint: { type: "builtInParams", name: "endpoint" },
Region: { type: "builtInParams", name: "region" },
UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
};
}

constructor(readonly input: GetTaskProtectionCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}

/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: ECSClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetTaskProtectionCommandInput, GetTaskProtectionCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.middlewareStack.use(
getEndpointPlugin(configuration, GetTaskProtectionCommand.getEndpointParameterInstructions())
);

const stack = clientStack.concat(this.middlewareStack);

const { logger } = configuration;
const clientName = "ECSClient";
const commandName = "GetTaskProtectionCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: GetTaskProtectionRequestFilterSensitiveLog,
outputFilterSensitiveLog: GetTaskProtectionResponseFilterSensitiveLog,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}

private serialize(input: GetTaskProtectionCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return serializeAws_json1_1GetTaskProtectionCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetTaskProtectionCommandOutput> {
return deserializeAws_json1_1GetTaskProtectionCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}

0 comments on commit a5eede0

Please sign in to comment.