Skip to content

Commit c37709e

Browse files
committed
Add table aws_batch_queue
1 parent 6f584fc commit c37709e

File tree

3 files changed

+375
-0
lines changed

3 files changed

+375
-0
lines changed

aws/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/aws/aws-sdk-go-v2/service/auditmanager"
3535
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
3636
"github.com/aws/aws-sdk-go-v2/service/backup"
37+
"github.com/aws/aws-sdk-go-v2/service/batch"
3738
"github.com/aws/aws-sdk-go-v2/service/cloudcontrol"
3839
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
3940
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
@@ -392,6 +393,16 @@ func BackupClient(ctx context.Context, d *plugin.QueryData) (*backup.Client, err
392393
return backup.NewFromConfig(*cfg), nil
393394
}
394395

396+
func BatchClient(ctx context.Context, d *plugin.QueryData) (*batch.Client, error) {
397+
conf, err := getClientForQuerySupportedRegion(ctx, d, AWS_BATCH_SERVICE_ID)
398+
if err != nil {
399+
return nil, err
400+
}
401+
402+
client := batch.NewFromConfig(*conf)
403+
return client, nil
404+
}
405+
395406
func CloudControlClient(ctx context.Context, d *plugin.QueryData) (*cloudcontrol.Client, error) {
396407
// CloudControl returns GeneralServiceException in a lot of situations, which
397408
// AWS SDK treats as retryable. This is frustrating because we end up retrying

aws/table_aws_batch_queue.go

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/batch"
8+
"github.com/aws/aws-sdk-go-v2/service/batch/types"
9+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
10+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
11+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
12+
)
13+
14+
func tableAwsBatchQueue(_ context.Context) *plugin.Table {
15+
return &plugin.Table{
16+
Name: "aws_batch_queue",
17+
Description: "AWS Batch Queue",
18+
Get: &plugin.GetConfig{
19+
KeyColumns: plugin.SingleColumn("queue_name"),
20+
IgnoreConfig: &plugin.IgnoreConfig{
21+
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"JobQueueNotFoundException"}),
22+
},
23+
Hydrate: getBatchQueue,
24+
Tags: map[string]string{"service": "batch", "action": "DescribeJobQueues"},
25+
},
26+
List: &plugin.ListConfig{
27+
Hydrate: listBatchQueues,
28+
Tags: map[string]string{"service": "batch", "action": "DescribeJobQueues"},
29+
},
30+
GetMatrixItemFunc: SupportedRegionMatrix(AWS_BATCH_SERVICE_ID),
31+
Columns: awsRegionalColumns([]*plugin.Column{
32+
{
33+
Name: "queue_name",
34+
Description: "The name of the job queue",
35+
Type: proto.ColumnType_STRING,
36+
Transform: transform.FromField("JobQueueName"),
37+
},
38+
{
39+
Name: "job_queue_arn",
40+
Description: "The Amazon Resource Name (ARN) of the job queue",
41+
Type: proto.ColumnType_STRING,
42+
},
43+
{
44+
Name: "state",
45+
Description: "The state of the job queue (ENABLED or DISABLED)",
46+
Type: proto.ColumnType_STRING,
47+
},
48+
{
49+
Name: "status",
50+
Description: "The status of the job queue (CREATING, UPDATING, DELETING, or DELETED)",
51+
Type: proto.ColumnType_STRING,
52+
},
53+
{
54+
Name: "priority",
55+
Description: "The priority of the job queue",
56+
Type: proto.ColumnType_INT,
57+
},
58+
{
59+
Name: "compute_environment_order",
60+
Description: "The compute environments that are attached to the job queue and the order in which job placement is preferred",
61+
Type: proto.ColumnType_JSON,
62+
},
63+
{
64+
Name: "scheduling_policy_arn",
65+
Description: "The ARN of the scheduling policy",
66+
Type: proto.ColumnType_STRING,
67+
},
68+
{
69+
Name: "status_reason",
70+
Description: "A short, human-readable string to provide additional details about the current status of the job queue",
71+
Type: proto.ColumnType_STRING,
72+
},
73+
{
74+
Name: "tags",
75+
Description: "The tags assigned to the job queue",
76+
Type: proto.ColumnType_JSON,
77+
Transform: transform.From(getBatchQueueTags),
78+
},
79+
{
80+
Name: "arn",
81+
Description: "The Amazon Resource Name (ARN) of the job queue",
82+
Type: proto.ColumnType_STRING,
83+
Transform: transform.FromField("JobQueueArn"),
84+
},
85+
{
86+
Name: "title",
87+
Description: resourceInterfaceDescription("title"),
88+
Type: proto.ColumnType_STRING,
89+
Transform: transform.FromField("JobQueueName"),
90+
},
91+
{
92+
Name: "akas",
93+
Description: resourceInterfaceDescription("akas"),
94+
Type: proto.ColumnType_JSON,
95+
Transform: transform.FromField("JobQueueArn").Transform(transform.EnsureStringArray),
96+
},
97+
}),
98+
}
99+
}
100+
101+
func listBatchQueues(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
102+
// Create service client
103+
svc, err := BatchClient(ctx, d)
104+
if err != nil {
105+
plugin.Logger(ctx).Error("aws_batch_queue.listBatchQueues", "client_error", err)
106+
return nil, err
107+
}
108+
109+
input := &batch.DescribeJobQueuesInput{
110+
MaxResults: aws.Int32(100),
111+
}
112+
113+
paginator := batch.NewDescribeJobQueuesPaginator(svc, input)
114+
for paginator.HasMorePages() {
115+
output, err := paginator.NextPage(ctx)
116+
if err != nil {
117+
plugin.Logger(ctx).Error("aws_batch_queue.listBatchQueues", "api_error", err)
118+
return nil, err
119+
}
120+
121+
for _, queue := range output.JobQueues {
122+
d.StreamListItem(ctx, queue)
123+
124+
// Context can be cancelled due to manual cancellation or the limit has been hit
125+
if d.RowsRemaining(ctx) == 0 {
126+
return nil, nil
127+
}
128+
}
129+
}
130+
131+
return nil, nil
132+
}
133+
134+
func getBatchQueue(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
135+
queueName := d.EqualsQualString("queue_name")
136+
if queueName == "" {
137+
return nil, nil
138+
}
139+
140+
// Create service client
141+
svc, err := BatchClient(ctx, d)
142+
if err != nil {
143+
plugin.Logger(ctx).Error("aws_batch_queue.getBatchQueue", "client_error", err)
144+
return nil, err
145+
}
146+
147+
input := &batch.DescribeJobQueuesInput{
148+
JobQueues: []string{queueName},
149+
}
150+
151+
output, err := svc.DescribeJobQueues(ctx, input)
152+
if err != nil {
153+
plugin.Logger(ctx).Error("aws_batch_queue.getBatchQueue", "api_error", err)
154+
return nil, err
155+
}
156+
157+
if len(output.JobQueues) == 0 {
158+
return nil, nil
159+
}
160+
161+
return output.JobQueues[0], nil
162+
}
163+
164+
func getBatchQueueTags(_ context.Context, d *transform.TransformData) (interface{}, error) {
165+
queue := d.HydrateItem.(types.JobQueueDetail)
166+
if queue.Tags == nil {
167+
return nil, nil
168+
}
169+
170+
return queue.Tags, nil
171+
}

docs/tables/aws_batch_queue.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
---
2+
title: "Steampipe Table: aws_batch_queue - Query AWS Batch Job Queues using SQL"
3+
description: "Allows users to query AWS Batch Job Queues for detailed information about queue configurations, statuses, and related attributes."
4+
folder: "Batch"
5+
---
6+
7+
# Table: aws_batch_queue
8+
9+
AWS Batch Job Queues are resources in the AWS Batch service that store jobs until the AWS Batch Scheduler runs them on a compute environment. Job queues have a priority that the scheduler uses to determine which jobs in which queue should be evaluated for execution first.
10+
11+
## Table Usage Guide
12+
13+
The `aws_batch_queue` table provides insights into job queue configurations within AWS Batch. As a DevOps engineer, explore queue-specific details through this table, including priority settings, compute environment associations, and queue statuses. Utilize it to monitor queue configurations, verify compute environment associations, and ensure appropriate job queue priorities are set.
14+
15+
## Examples
16+
17+
### Basic info
18+
19+
```sql+postgres
20+
select
21+
queue_name,
22+
state,
23+
status,
24+
priority
25+
from
26+
aws_batch_queue;
27+
```
28+
29+
```sql+sqlite
30+
select
31+
queue_name,
32+
state,
33+
status,
34+
priority
35+
from
36+
aws_batch_queue;
37+
```
38+
39+
### List enabled job queues
40+
41+
```sql+postgres
42+
select
43+
queue_name,
44+
state,
45+
priority
46+
from
47+
aws_batch_queue
48+
where
49+
state = 'ENABLED';
50+
```
51+
52+
```sql+sqlite
53+
select
54+
queue_name,
55+
state,
56+
priority
57+
from
58+
aws_batch_queue
59+
where
60+
state = 'ENABLED';
61+
```
62+
63+
### List job queues by state
64+
65+
```sql+postgres
66+
select
67+
state,
68+
count(*) as queue_count
69+
from
70+
aws_batch_queue
71+
group by
72+
state
73+
order by
74+
queue_count desc;
75+
```
76+
77+
```sql+sqlite
78+
select
79+
state,
80+
count(*) as queue_count
81+
from
82+
aws_batch_queue
83+
group by
84+
state
85+
order by
86+
queue_count desc;
87+
```
88+
89+
### Get compute environments associated with each job queue
90+
91+
```sql+postgres
92+
select
93+
queue_name,
94+
state,
95+
c->>'Order' as order_priority,
96+
c->>'ComputeEnvironment' as compute_environment
97+
from
98+
aws_batch_queue,
99+
jsonb_array_elements(compute_environment_order) as c
100+
order by
101+
queue_name,
102+
(c->>'Order')::int;
103+
```
104+
105+
```sql+sqlite
106+
select
107+
queue_name,
108+
state,
109+
json_extract(c.value, '$.Order') as order_priority,
110+
json_extract(c.value, '$.ComputeEnvironment') as compute_environment
111+
from
112+
aws_batch_queue,
113+
json_each(compute_environment_order) as c
114+
order by
115+
queue_name,
116+
CAST(json_extract(c.value, '$.Order') as integer);
117+
```
118+
119+
### Find job queues with high priority (lower number means higher priority)
120+
121+
```sql+postgres
122+
select
123+
queue_name,
124+
state,
125+
priority
126+
from
127+
aws_batch_queue
128+
where
129+
priority < 50
130+
order by
131+
priority;
132+
```
133+
134+
```sql+sqlite
135+
select
136+
queue_name,
137+
state,
138+
priority
139+
from
140+
aws_batch_queue
141+
where
142+
priority < 50
143+
order by
144+
priority;
145+
```
146+
147+
### Find job queues with scheduling policies
148+
149+
```sql+postgres
150+
select
151+
queue_name,
152+
state,
153+
scheduling_policy_arn
154+
from
155+
aws_batch_queue
156+
where
157+
scheduling_policy_arn is not null;
158+
```
159+
160+
```sql+sqlite
161+
select
162+
queue_name,
163+
state,
164+
scheduling_policy_arn
165+
from
166+
aws_batch_queue
167+
where
168+
scheduling_policy_arn is not null;
169+
```
170+
171+
### List job queues with their tags
172+
173+
```sql+postgres
174+
select
175+
queue_name,
176+
state,
177+
tags
178+
from
179+
aws_batch_queue
180+
where
181+
tags is not null;
182+
```
183+
184+
```sql+sqlite
185+
select
186+
queue_name,
187+
state,
188+
tags
189+
from
190+
aws_batch_queue
191+
where
192+
tags is not null;
193+
```

0 commit comments

Comments
 (0)