createAgent method

Future<CreateAgentResponse> createAgent({
  1. required String activationKey,
  2. String? agentName,
  3. List<String>? securityGroupArns,
  4. List<String>? subnetArns,
  5. List<TagListEntry>? tags,
  6. String? vpcEndpointId,
})

Activates an AWS DataSync agent that you have deployed on your host. The activation process associates your agent with your account. In the activation process, you specify information such as the AWS Region that you want to activate the agent in. You activate the agent in the AWS Region where your target locations (in Amazon S3 or Amazon EFS) reside. Your tasks are created in this AWS Region.

You can activate the agent in a VPC (virtual private cloud) or provide the agent access to a VPC endpoint so you can run tasks without going over the public internet.

You can use an agent for more than one location. If a task uses multiple agents, all of them need to have status AVAILABLE for the task to run. If you use multiple agents for a source location, the status of all the agents must be AVAILABLE for the task to run.

Agents are automatically updated by AWS on a regular basis, using a mechanism that ensures minimal interruption to your tasks.

May throw InvalidRequestException. May throw InternalException.

Parameter activationKey : Your agent activation key. You can get the activation key either by sending an HTTP GET request with redirects that enable you to get the agent IP address (port 80). Alternatively, you can get it from the AWS DataSync console.

The redirect URL returned in the response provides you the activation key for your agent in the query string parameter activationKey. It might also include other activation-related parameters; however, these are merely defaults. The arguments you pass to this API call determine the actual configuration of your agent.

For more information, see Activating an Agent in the AWS DataSync User Guide.

Parameter agentName : The name you configured for your agent. This value is a text reference that is used to identify the agent in the console.

Parameter securityGroupArns : The ARNs of the security groups used to protect your data transfer task subnets. See CreateAgentRequest$SubnetArns.

Parameter subnetArns : The Amazon Resource Names (ARNs) of the subnets in which DataSync will create elastic network interfaces for each data transfer task. The agent that runs a task must be private. When you start a task that is associated with an agent created in a VPC, or one that has access to an IP address in a VPC, then the task is also private. In this case, DataSync creates four network interfaces for each task in your subnet. For a data transfer to work, the agent must be able to route to all these four network interfaces.

Parameter tags : The key-value pair that represents the tag that you want to associate with the agent. The value can be an empty string. This value helps you manage, filter, and search for your agents.

Parameter vpcEndpointId : The ID of the VPC (virtual private cloud) endpoint that the agent has access to. This is the client-side VPC endpoint, also called a PrivateLink. If you don't have a PrivateLink VPC endpoint, see Creating a VPC Endpoint Service Configuration in the Amazon VPC User Guide.

VPC endpoint ID looks like this: vpce-01234d5aff67890e1.

Implementation

Future<CreateAgentResponse> createAgent({
  required String activationKey,
  String? agentName,
  List<String>? securityGroupArns,
  List<String>? subnetArns,
  List<TagListEntry>? tags,
  String? vpcEndpointId,
}) async {
  ArgumentError.checkNotNull(activationKey, 'activationKey');
  _s.validateStringLength(
    'activationKey',
    activationKey,
    0,
    29,
    isRequired: true,
  );
  _s.validateStringLength(
    'agentName',
    agentName,
    1,
    256,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'FmrsService.CreateAgent'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'ActivationKey': activationKey,
      if (agentName != null) 'AgentName': agentName,
      if (securityGroupArns != null) 'SecurityGroupArns': securityGroupArns,
      if (subnetArns != null) 'SubnetArns': subnetArns,
      if (tags != null) 'Tags': tags,
      if (vpcEndpointId != null) 'VpcEndpointId': vpcEndpointId,
    },
  );

  return CreateAgentResponse.fromJson(jsonResponse.body);
}