Skip to content

Add table aws_batch_queue #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_backup_selection": tableAwsBackupSelection(ctx),
"aws_backup_vault": tableAwsBackupVault(ctx),
"aws_backup_job": tableAwsBackupJob(ctx),
"aws_batch_queue": tableAwsBatchQueue(ctx),
"aws_cloudcontrol_resource": tableAwsCloudControlResource(ctx),
"aws_cloudformation_stack": tableAwsCloudFormationStack(ctx),
"aws_cloudformation_stack_resource": tableAwsCloudFormationStackResource(ctx),
Expand Down
15 changes: 15 additions & 0 deletions aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/auditmanager"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/backup"
"github.com/aws/aws-sdk-go-v2/service/batch"
"github.com/aws/aws-sdk-go-v2/service/cloudcontrol"
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
Expand Down Expand Up @@ -326,6 +327,20 @@ func BackupClient(ctx context.Context, d *plugin.QueryData) (*backup.Client, err
return backup.NewFromConfig(*cfg), nil
}

func BatchClient(ctx context.Context, d *plugin.QueryData) (*batch.Client, error) {
conf, err := getClientForQuerySupportedRegion(ctx, d, AWS_BATCH_SERVICE_ID)
if err != nil {
return nil, err
}

if conf == nil {
return nil, nil
}

client := batch.NewFromConfig(*conf)
return client, nil
}

func CloudControlClient(ctx context.Context, d *plugin.QueryData) (*cloudcontrol.Client, error) {
// CloudControl returns GeneralServiceException in a lot of situations, which
// AWS SDK treats as retryable. This is frustrating because we end up retrying
Expand Down
175 changes: 175 additions & 0 deletions aws/table_aws_batch_queue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package aws

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/batch"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableAwsBatchQueue(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_batch_queue",
Description: "AWS Batch Queue",
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("job_queue_name"),
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"JobQueueNotFoundException"}),
},
Hydrate: getBatchQueue,
Tags: map[string]string{"service": "batch", "action": "DescribeJobQueues"},
},
List: &plugin.ListConfig{
Hydrate: listBatchQueues,
Tags: map[string]string{"service": "batch", "action": "DescribeJobQueues"},
},
GetMatrixItemFunc: SupportedRegionMatrix(AWS_BATCH_SERVICE_ID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "job_queue_name",
Description: "The name of the job queue",
Type: proto.ColumnType_STRING,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the job queue",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("JobQueueArn"),
},
{
Name: "state",
Description: "The state of the job queue (ENABLED or DISABLED)",
Type: proto.ColumnType_STRING,
},
{
Name: "status",
Description: "The status of the job queue (CREATING, UPDATING, DELETING, or DELETED)",
Type: proto.ColumnType_STRING,
},
{
Name: "priority",
Description: "The priority of the job queue",
Type: proto.ColumnType_INT,
},
{
Name: "compute_environment_order",
Description: "The compute environments that are attached to the job queue and the order in which job placement is preferred",
Type: proto.ColumnType_JSON,
},
{
Name: "scheduling_policy_arn",
Description: "The ARN of the scheduling policy",
Type: proto.ColumnType_STRING,
},
{
Name: "status_reason",
Description: "A short, human-readable string to provide additional details about the current status of the job queue",
Type: proto.ColumnType_STRING,
},

// Standard columns for all tables
{
Name: "tags",
Description: "The tags assigned to the job queue",
Type: proto.ColumnType_JSON,
},
{
Name: "title",
Description: resourceInterfaceDescription("title"),
Type: proto.ColumnType_STRING,
Transform: transform.FromField("JobQueueName"),
},
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Transform: transform.FromField("JobQueueArn").Transform(transform.EnsureStringArray),
},
}),
}
}

func listBatchQueues(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
// Create service client
svc, err := BatchClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_batch_queue.listBatchQueues", "client_error", err)
return nil, err
}

// Unsupported region check
if svc == nil {
return nil, nil
}

// Limiting the results
maxLimit := int32(100)
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxLimit {
maxLimit = limit
}
}

input := &batch.DescribeJobQueuesInput{
MaxResults: aws.Int32(maxLimit),
}

paginator := batch.NewDescribeJobQueuesPaginator(svc, input)
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_batch_queue.listBatchQueues", "api_error", err)
return nil, err
}

for _, queue := range output.JobQueues {
d.StreamListItem(ctx, queue)

// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}

return nil, nil
}

func getBatchQueue(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
queueName := d.EqualsQualString("job_queue_name")
if queueName == "" {
return nil, nil
}

// Create service client
svc, err := BatchClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_batch_queue.getBatchQueue", "client_error", err)
return nil, err
}

// Unsupported region check
if svc == nil {
return nil, nil
}

input := &batch.DescribeJobQueuesInput{
JobQueues: []string{queueName},
}

output, err := svc.DescribeJobQueues(ctx, input)
if err != nil {
plugin.Logger(ctx).Error("aws_batch_queue.getBatchQueue", "api_error", err)
return nil, err
}

if len(output.JobQueues) == 0 {
return nil, nil
}

return output.JobQueues[0], nil
}
Loading
Loading