Troubleshooting AWS Batch and PrivateLink
Tags: aws, batch, privatelink
Published: 2020-04-22 13:47:06

---
title: Troubleshooting AWS Batch and PrivateLink
published: true
description: A short summary of troubleshooting issues when using AWS Batch for instances launched into private subnets, and when communication with other AWS resources is via PrivateLink
tags: #aws #batch #privatelink
---

[AWS Batch](https://aws.amazon.com/batch/) is a powerful platform for running batch jobs, but setting up can be difficult, especially if your environment uses private subnets and you want to make use of AWS [PrivateLink](https://aws.amazon.com/privatelink/).

One source of frustration is that your jobs get stuck in a 'RUNNABLE' state and don't progress.  Here are some pointers you can use for troubleshooting this issue.

Read through the [AWS Batch Troubleshooting guide](https://docs.aws.amazon.com/batch/latest/userguide/troubleshooting.html) and '[Why is my AWS Batch job stuck in RUNNABLE status](https://aws.amazon.com/premiumsupport/knowledge-center/batch-job-stuck-runnable-status/)'.  If you carefully work through these guides then they should lead you to the source of the issue.

One thing to [highlight](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html) is:

> Container instances need access to communicate with the Amazon ECS service endpoint. This can be through an interface VPC endpoint or through your container instances having public IP addresses.

If you are using a [NATGateway](https://aws.amazon.com/privatelink/), then this shouldn't be a problem, because this is a standard solution to communicating with web resources from private subnets.

However, I was configuring service access via [PrivateLink](https://aws.amazon.com/privatelink/), meaning that requests are not routed over the public internet.  Using PrivateLink brings with it additional steps for successfully running AWS Batch jobs.

#### ECS Instances not being created in the ECS cluster

Your batch job goes to RUNNABLE, but you don't see any ECS cluster instances created (refer to '[troubleshooting](https://aws.amazon.com/premiumsupport/knowledge-center/batch-job-stuck-runnable-status/)' for more on this).

- Refer to [Creating the VPC Endpoints for Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/vpc-endpoints.html).  Your containers are going to need to be able to access the following endpoints:

  - `com.amazonaws.<your region>.ecs-agent`
  - `com.amazonaws.<your region>.ecs-telemetry`
  - `com.amazonaws.<your region>.ecs`

- The Security Group associated with each endpoint need to be able to send 'all traffic' outbound requests - refer to the [troubleshooting guide](https://aws.amazon.com/premiumsupport/knowledge-center/batch-job-stuck-runnable-status/).

- The Security Group associated with the endpoint(s) needs to be able to accept TCP requests on port 443.

#### Jobs run but then fail with 'CannotPullECRContainerError'

Refer to [this guide](https://docs.aws.amazon.com/AmazonECR/latest/userguide/vpc-endpoints.html) for setting up VPC Endpoints to ECR.

The key points is that you will need two VPC Endpoints:

- `com.amazonaws.<your region>.ecr.dkr`
- `com.amazonaws.<your region>.ecr.api`

I found setup of AWS Batch with VPC Endpoints was not straightforward, but hopefully some of the pointers in this guide can save you time if you are stuck.

#### Other Resources

- [Using AWS CloudFormation to Create and Manage AWS Batch Resources](https://aws.amazon.com/blogs/compute/using-aws-cloudformation-to-create-and-manage-aws-batch-resources/)
- [Orchestrating an application process with AWS Batch using AWS CloudFormation](https://aws.amazon.com/blogs/compute/orchestrating-an-application-process-with-aws-batch-using-aws-cloudformation/)
- [Getting started with AWS Batch](https://gist.github.com/doi-t/01e5241c9595e7b8e3540f0125bd4519)