1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ecs 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/ecs/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12) 13 14// Starts a new task using the specified task definition. You can allow Amazon ECS 15// to place tasks for you, or you can customize how Amazon ECS places tasks using 16// placement constraints and placement strategies. For more information, see 17// Scheduling Tasks 18// (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduling_tasks.html) 19// in the Amazon Elastic Container Service Developer Guide. Alternatively, you can 20// use StartTask to use your own scheduler or place tasks manually on specific 21// container instances. The Amazon ECS API follows an eventual consistency model, 22// due to the distributed nature of the system supporting the API. This means that 23// the result of an API command you run that affects your Amazon ECS resources 24// might not be immediately visible to all subsequent commands you run. Keep this 25// in mind when you carry out an API command that immediately follows a previous 26// API command. To manage eventual consistency, you can do the following: 27// 28// * 29// Confirm the state of the resource before you run a command to modify it. Run the 30// DescribeTasks command using an exponential backoff algorithm to ensure that you 31// allow enough time for the previous command to propagate through the system. To 32// do this, run the DescribeTasks command repeatedly, starting with a couple of 33// seconds of wait time and increasing gradually up to five minutes of wait 34// time. 35// 36// * Add wait time between subsequent commands, even if the DescribeTasks 37// command returns an accurate response. Apply an exponential backoff algorithm 38// starting with a couple of seconds of wait time, and increase gradually up to 39// about five minutes of wait time. 40func (c *Client) RunTask(ctx context.Context, params *RunTaskInput, optFns ...func(*Options)) (*RunTaskOutput, error) { 41 if params == nil { 42 params = &RunTaskInput{} 43 } 44 45 result, metadata, err := c.invokeOperation(ctx, "RunTask", params, optFns, addOperationRunTaskMiddlewares) 46 if err != nil { 47 return nil, err 48 } 49 50 out := result.(*RunTaskOutput) 51 out.ResultMetadata = metadata 52 return out, nil 53} 54 55type RunTaskInput struct { 56 57 // The family and revision (family:revision) or full ARN of the task definition to 58 // run. If a revision is not specified, the latest ACTIVE revision is used. 59 // 60 // This member is required. 61 TaskDefinition *string 62 63 // The capacity provider strategy to use for the task. If a 64 // capacityProviderStrategy is specified, the launchType parameter must be omitted. 65 // If no capacityProviderStrategy or launchType is specified, the 66 // defaultCapacityProviderStrategy for the cluster is used. 67 CapacityProviderStrategy []types.CapacityProviderStrategyItem 68 69 // The short name or full Amazon Resource Name (ARN) of the cluster on which to run 70 // your task. If you do not specify a cluster, the default cluster is assumed. 71 Cluster *string 72 73 // The number of instantiations of the specified task to place on your cluster. You 74 // can specify up to 10 tasks per call. 75 Count *int32 76 77 // Specifies whether to enable Amazon ECS managed tags for the task. For more 78 // information, see Tagging Your Amazon ECS Resources 79 // (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html) 80 // in the Amazon Elastic Container Service Developer Guide. 81 EnableECSManagedTags bool 82 83 // Whether or not to enable the execute command functionality for the containers in 84 // this task. If true, this enables execute command functionality on all containers 85 // in the task. 86 EnableExecuteCommand bool 87 88 // The name of the task group to associate with the task. The default value is the 89 // family name of the task definition (for example, family:my-family-name). 90 Group *string 91 92 // The launch type on which to run your task. The accepted values are FARGATE and 93 // EC2. For more information, see Amazon ECS Launch Types 94 // (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_types.html) 95 // in the Amazon Elastic Container Service Developer Guide. When a value of FARGATE 96 // is specified, your tasks are launched on AWS Fargate On-Demand infrastructure. 97 // To use Fargate Spot, you must use a capacity provider strategy with the 98 // FARGATE_SPOT capacity provider. When a value of EC2 is specified, your tasks are 99 // launched on Amazon EC2 instances registered to your cluster. If a launchType is 100 // specified, the capacityProviderStrategy parameter must be omitted. 101 LaunchType types.LaunchType 102 103 // The network configuration for the task. This parameter is required for task 104 // definitions that use the awsvpc network mode to receive their own elastic 105 // network interface, and it is not supported for other network modes. For more 106 // information, see Task Networking 107 // (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html) 108 // in the Amazon Elastic Container Service Developer Guide. 109 NetworkConfiguration *types.NetworkConfiguration 110 111 // A list of container overrides in JSON format that specify the name of a 112 // container in the specified task definition and the overrides it should receive. 113 // You can override the default command for a container (that is specified in the 114 // task definition or Docker image) with a command override. You can also override 115 // existing environment variables (that are specified in the task definition or 116 // Docker image) on a container or add new environment variables to it with an 117 // environment override. A total of 8192 characters are allowed for overrides. This 118 // limit includes the JSON formatting characters of the override structure. 119 Overrides *types.TaskOverride 120 121 // An array of placement constraint objects to use for the task. You can specify up 122 // to 10 constraints per task (including constraints in the task definition and 123 // those specified at runtime). 124 PlacementConstraints []types.PlacementConstraint 125 126 // The placement strategy objects to use for the task. You can specify a maximum of 127 // five strategy rules per task. 128 PlacementStrategy []types.PlacementStrategy 129 130 // The platform version the task should run. A platform version is only specified 131 // for tasks using the Fargate launch type. If one is not specified, the LATEST 132 // platform version is used by default. For more information, see AWS Fargate 133 // Platform Versions 134 // (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/platform_versions.html) 135 // in the Amazon Elastic Container Service Developer Guide. 136 PlatformVersion *string 137 138 // Specifies whether to propagate the tags from the task definition to the task. If 139 // no value is specified, the tags are not propagated. Tags can only be propagated 140 // to the task during task creation. To add tags to a task after task creation, use 141 // the TagResource API action. An error will be received if you specify the SERVICE 142 // option when running a task. 143 PropagateTags types.PropagateTags 144 145 // The reference ID to use for the task. 146 ReferenceId *string 147 148 // An optional tag specified when a task is started. For example, if you 149 // automatically trigger a task to run a batch process job, you could apply a 150 // unique identifier for that job to your task with the startedBy parameter. You 151 // can then identify which tasks belong to that job by filtering the results of a 152 // ListTasks call with the startedBy value. Up to 36 letters (uppercase and 153 // lowercase), numbers, hyphens, and underscores are allowed. If a task is started 154 // by an Amazon ECS service, then the startedBy parameter contains the deployment 155 // ID of the service that starts it. 156 StartedBy *string 157 158 // The metadata that you apply to the task to help you categorize and organize 159 // them. Each tag consists of a key and an optional value, both of which you 160 // define. The following basic restrictions apply to tags: 161 // 162 // * Maximum number of 163 // tags per resource - 50 164 // 165 // * For each resource, each tag key must be unique, and 166 // each tag key can have only one value. 167 // 168 // * Maximum key length - 128 Unicode 169 // characters in UTF-8 170 // 171 // * Maximum value length - 256 Unicode characters in UTF-8 172 // 173 // * 174 // If your tagging schema is used across multiple services and resources, remember 175 // that other services may have restrictions on allowed characters. Generally 176 // allowed characters are: letters, numbers, and spaces representable in UTF-8, and 177 // the following characters: + - = . _ : / @. 178 // 179 // * Tag keys and values are 180 // case-sensitive. 181 // 182 // * Do not use aws:, AWS:, or any upper or lowercase combination 183 // of such as a prefix for either keys or values as it is reserved for AWS use. You 184 // cannot edit or delete tag keys or values with this prefix. Tags with this prefix 185 // do not count against your tags per resource limit. 186 Tags []types.Tag 187} 188 189type RunTaskOutput struct { 190 191 // Any failures associated with the call. 192 Failures []types.Failure 193 194 // A full description of the tasks that were run. The tasks that were successfully 195 // placed on your cluster are described here. 196 Tasks []types.Task 197 198 // Metadata pertaining to the operation's result. 199 ResultMetadata middleware.Metadata 200} 201 202func addOperationRunTaskMiddlewares(stack *middleware.Stack, options Options) (err error) { 203 err = stack.Serialize.Add(&awsAwsjson11_serializeOpRunTask{}, middleware.After) 204 if err != nil { 205 return err 206 } 207 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpRunTask{}, middleware.After) 208 if err != nil { 209 return err 210 } 211 if err = addSetLoggerMiddleware(stack, options); err != nil { 212 return err 213 } 214 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 215 return err 216 } 217 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 218 return err 219 } 220 if err = addResolveEndpointMiddleware(stack, options); err != nil { 221 return err 222 } 223 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 224 return err 225 } 226 if err = addRetryMiddlewares(stack, options); err != nil { 227 return err 228 } 229 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 230 return err 231 } 232 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 233 return err 234 } 235 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 236 return err 237 } 238 if err = addClientUserAgent(stack); err != nil { 239 return err 240 } 241 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 242 return err 243 } 244 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 245 return err 246 } 247 if err = addOpRunTaskValidationMiddleware(stack); err != nil { 248 return err 249 } 250 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opRunTask(options.Region), middleware.Before); err != nil { 251 return err 252 } 253 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 254 return err 255 } 256 if err = addResponseErrorMiddleware(stack); err != nil { 257 return err 258 } 259 if err = addRequestResponseLogging(stack, options); err != nil { 260 return err 261 } 262 return nil 263} 264 265func newServiceMetadataMiddleware_opRunTask(region string) *awsmiddleware.RegisterServiceMetadata { 266 return &awsmiddleware.RegisterServiceMetadata{ 267 Region: region, 268 ServiceID: ServiceID, 269 SigningName: "ecs", 270 OperationName: "RunTask", 271 } 272} 273