I'm experimenting with AWS ECS and fargate, and for starters I wrote a very simple "hello world" application that just puts a file with date and time marked into an S3 bucket, packed it into a docker image and turned the whole into an ECS task.
When I run that task manually from the AWS console, everything is fine. However, what I want in the end is to launch the thing (or several of them) from another application, which is written in kotlin, using the AWS Java SDK.
I can launch the task without errors, and I see it popping up in the ECS console. Only, its status goes from provisioning to pending, and then never turns to running, instead terminating after having hung in Pending state for a while. It should terminate after finishing, just to be clear, so I'm not complaining about it shutting down. But it's definitely an issue that it doesn't do what it's supposed to do before that.
Here's what the code looks like right now that starts the entire thing:
/**
* Service methods for AWS Elastic Container Service
*/
class FargateService(
defaultSecurityGroups: List<String>,
defaultSubnets: List<String>,
private val client: AmazonECS = AmazonECSClientBuilder.standard().build(),
) {
private val defaultNetworkConfiguration = NetworkConfiguration().withAwsvpcConfiguration(
AwsVpcConfiguration().apply {
setSecurityGroups(defaultSecurityGroups)
setSubnets(defaultSubnets)
}
)
private val log = logger()
/**
* Launches a number of tasks of a certain type.
* @param taskARN: ARN of the task to launch.
* @param clusterARN: ARN of the cluster to launch the task in.
* @param number: How many of this task should be launched in this cluster.
*/
fun launchTasks(
taskARN: String,
clusterARN: String,
number: Int = 1,
networkConfiguration: NetworkConfiguration = defaultNetworkConfiguration) {
val runRequest = RunTaskRequest().apply {
cluster = clusterARN
launchType = LaunchType.FARGATE.name
taskDefinition = taskARN
count = number
}.withNetworkConfiguration(networkConfiguration)
val result = client.runTask(runRequest)
log.info(result.toString())
}
}
I'm using the exact same configuration properties as I'm using when launching the thing manually, down to subnet and security group, but the result is not the same. One thing I do not seem to be able to configure here that I have to configure when running it manually is the VPC-id itself, but since I only have one VPC, I'm not too worried about that.
Does anybody have experience with this sort of thing and sees what I'm doing wrong?