public static void main()

in amazon-ecs-java-starter-kit-task/src/main/java/software/aws/ecs/java/starterkit/task/ECSTask.java [36:105]


	public static void main(String[] args) {

		String regionPassed = System.getenv("region");
		String tableName = System.getenv("workflow_details_ddb_table_name");
		String hashKey = System.getenv("workflow_details_hash_key");
		String rangeKey = System.getenv("workflow_details_range_key");
		String workflowName = System.getenv("workflow_name");
		long workflowRunId = Long.parseLong(System.getenv("workflow_run_id"));
		String taskName = System.getenv("task_name");
		String bucketName = System.getenv("s3_bucket_name");
		String objectKey = System.getenv("object_key");
		String taskMetadataEndpoint = System.getenv("ECS_CONTAINER_METADATA_URI");
		
		long startTime = System.currentTimeMillis();

		// print runtime properties of the task
		printInputParameters(regionPassed, tableName, hashKey, rangeKey, workflowName, workflowRunId, taskName, 
				bucketName, objectKey, taskMetadataEndpoint);
		String destinationKey = objectKey.concat("_").concat(UUID.randomUUID().toString());

		// Create objects
		Region region = Region.regions().stream().filter(r -> r.toString().equalsIgnoreCase(regionPassed)).findFirst()
				.orElse(Region.US_EAST_1);
		S3Client s3 = S3Client.builder().region(region).build();
		DynamoDbClient dynamoDB = DynamoDbClient.builder().region(region).build();
		DDBUtil ddbUtil = new DDBUtil();

		// get Task ARN
		String response = "";
		HttpURLConnection con = getHTTPConnectionForTaskMetadataEndpoint(taskMetadataEndpoint.concat("/task"));
		System.out.println("HTTP Connection: " + con.getURL().toString());
		try {
			response = getFullResponse(con);
			System.out.println("Response from HTTP Connection: " + response);
		} catch (IOException e) {
			e.printStackTrace();
		}
		String taskARN = getTaskARN(response);
		System.out.println("Task ARN: " + taskARN);

		// insert job running status in DynamoDB table
		String status = "Running";
		String insertTime = new Date().toString();
		ddbUtil.insertTaskStatus(dynamoDB, tableName, hashKey, rangeKey, workflowRunId, taskARN, taskName, status, insertTime);

		// perform the task - actual business logic
		boolean objectCopied = copyFile(s3, bucketName, objectKey, destinationKey);
		
		// a random sleep interval from 1 to 3 minutes
		int waitTime  = (1 + new Random().nextInt(3)) * 60000;
		System.out.printf("Task sleeping  for %s seconds \n", waitTime);
		try {
			Thread.sleep(waitTime);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		// update job completion status in DynamoDB table
		String updateTime = new Date().toString();
		if (objectCopied)
			status = "Completed";
		else
			status = "Failed";
		
		long endTime = System.currentTimeMillis();
		long execTimeinSeconds = (endTime - startTime)/1000;
		ddbUtil.updateTaskStatus(dynamoDB, tableName, hashKey, rangeKey, workflowRunId, taskARN, status, updateTime, execTimeinSeconds);
	}