I am trying to get the logs of an AWS Batch job using the following code
import boto3
batch_client = boto3.client("batch")
batch_response = batch_client.describe_jobs(jobs=["<JOB ID HERE>"])
print(batch_response["jobs"][0]["container"]["logStreamName"])
# Fails with
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# KeyError: 'logStreamName'
It used to work till yesterday but from today (roughly Sep 9, 2020, 04:55 AM IST) it isn't. All the tasks that I have created today are missing the logStreamName
in their response.
As per https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/batch.html#Batch.Client.describe_jobs, the logStreamName
should be present in the response.
NOTE: Downgrading or upgrading boto3 version seems to have no effect. Tried on the latest 1.14.57 and an older 1.13.26
EDIT
The logs are present on cloudwatch but not present in the response (only for the new tasks). There was a new boto3 release 12 hours ago and might be affecting? The value (redacting some stuff) for the batch_response
is
{
"ResponseMetadata": {
"RequestId": "string",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"date": "string",
"content-type": "string",
"content-length": "string",
"connection": "string",
"x-amzn-requestid": "string",
"x-amz-apigw-id": "string",
"x-amzn-trace-id": "string"
},
"RetryAttempts": 0
},
"jobs": [
{
"jobName": "string",
"jobId": "string",
"jobQueue": "string",
"status": "SUCCEEDED",
"attempts": [
{
"container": {
"containerInstanceArn": "string",
"taskArn": "string",
"exitCode": 0,
"networkInterfaces": []
},
"startedAt": 1599621988773,
"stoppedAt": 1599624120887,
"statusReason": "Essential container in task exited"
}
],
"statusReason": "Essential container in task exited",
"createdAt": 1599621980433,
"startedAt": 1599621988773,
"stoppedAt": 1599624120887,
"dependsOn": [],
"jobDefinition": "string",
"parameters": {},
"container": {
"image": "string",
"vcpus": 1,
"memory": 8192,
"command": [],
"jobRoleArn": "string",
"volumes": [
{
"host": {
"sourcePath": "string"
},
"name": "string"
}
],
"environment": [
{
"name": "string",
"value": "string"
}
],
"mountPoints": [
{
"containerPath": "string",
"sourceVolume": "string"
}
],
"ulimits": [],
"exitCode": 0,
"containerInstanceArn": "string",
"taskArn": "string",
"networkInterfaces": [],
"resourceRequirements": []
}
}
]
}
AWS Support has confirmed that there was an issue which prevented the logStreamName
property from being populated in the AWS Batch DescribeJobs API, for jobs submitted between September 8, 10:42 AM and September 9, 4:07 PM PDT. They have resolved the issue.