Skip to content
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

cloudwatch: Arn.split cannot parse AWS Batch Job queue ARN #30927

Closed
kcrimson opened this issue Jul 23, 2024 · 2 comments
Closed

cloudwatch: Arn.split cannot parse AWS Batch Job queue ARN #30927

kcrimson opened this issue Jul 23, 2024 · 2 comments
Labels
@aws-cdk/aws-batch Related to AWS Batch @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@kcrimson
Copy link

Describe the bug

I am trying to create a CloudWatch Alarm for AWS Batch queues. CDK synth produces the following CloudFormation template:

BatchWatchdogBatchWatchdogAlertsworkerm6gdlargeAlarm7BA82391:
    Type: AWS::CloudWatch::Alarm
    Properties:
      ActionsEnabled: false
      ComparisonOperator: GreaterThanOrEqualToThreshold
      DatapointsToAlarm: 3
      Dimensions:
        - Name: BatchJobQueue
          Value:
            Fn::Select:
              - 2
              - Fn::Split:
                  - /
                  - Fn::Select:
                      - 5
                      - Fn::Split:
                          - ":"
                          - Fn::Select:
                              - 1
                              - Fn::Split:
                                  - /
                                  - Fn::Select:
                                      - 5
                                      - Fn::Split:
                                          - ":"
                                          - Fn::GetAtt:
                                              - workerm6gdlargeJobQueue4AFBF4B1
                                              - JobQueueArn
      EvaluationPeriods: 5
      MetricName: TimeInQueue
      Namespace: benchmarking
      Period: 300
      Statistic: Average
      Tags:
        - Key: owner
          Value: benchmark
        - Key: project
          Value: benchmarking-batch-infrastructure
        - Key: stage
          Value: staging
      Threshold: 3600
      Unit: Seconds

Expected Behavior

What is expected is to set the value of the Alarm dimension to the AWS batch job queue name.

When I run this code as a code snippet, it extracts the resource name properly, but it generates an invalid CF template

|  Welcome to JShell -- Version 11.0.8
|  For an introduction type: /help intro

jshell> import software.amazon.awscdk.Arn;

jshell> import software.amazon.awscdk.ArnFormat

jshell> Arn.split("arn:aws:batch:us-east-1:111122223333:job-queue/JobQueueName",ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME).getResourceName();
$3 ==> "JobQueueName"

Current Behavior

When I deploy this stack, I get the following error:

Failed resources:
benchmarking-batch-infrastructure-staging-eu-central-1 | 4:11:00 PM | CREATE_FAILED        | AWS::CloudWatch::Alarm         | BatchWatchdog/BatchWatchdogAlerts/worker-m6gd.large-Alarm (BatchWatchdogBatchWatchdogAlertsworkerm6gdlargeAlarm7BA82391) Template error: Fn::Select  cannot select nonexistent value at index 5

Reproduction Steps

The Java code which creates CloudWatch alarms, looks like this:

private void createAlarm(BatchJobQueue batchJobQueue) {
        var resourceName = Arn.split(batchJobQueue.getJobQueueName(), ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME)
                .getResourceName();
        Alarm.Builder.create(this, batchJobQueue.getNode().getId() + "-Alarm")
                .actionsEnabled(false)
                .metric(Metric.Builder.create()
                        .namespace(BatchWatchDog.BENCHMARKING_METRIC_NAMESPACE)
                        .metricName(BatchWatchDog.TIME_IN_QUEUE_METRIC_NAME)
                        .dimensionsMap(Map.of(BatchWatchDog.BATCH_JOB_QUEUE_DIMENSION, resourceName))
                        .period(software.amazon.awscdk.Duration.minutes(5))
                        .unit(Unit.SECONDS)
                        .statistic(Stats.AVERAGE)
                        .build())
                .evaluationPeriods(5)
                .datapointsToAlarm(3)
                .threshold(Duration.ofHours(1).toSeconds())
                .comparisonOperator(ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD)
                .build();
    }

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.149.0

### Framework Version

_No response_

### Node.js Version

v20.15.1

### OS

Ubuntu  24.04 LTS

### Language

Java

### Language Version

Java 11

### Other information

_No response_
@kcrimson kcrimson added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 23, 2024
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Jul 23, 2024
@pahud
Copy link
Contributor

pahud commented Jul 23, 2024

Looks like you are trying to createAlarm from your Java code with a BatchJobQueue and you need to find out the resourceName of that BatchJobQueue. And you are trying to Arn.split batchJobQueue.getJobQueueName() to get the resourceName.

My questions:

  1. It's not clear what batchJobQueue.getJobQueueName() would return, I can't find this method in the CDK source. Is this your private function? Does it return a full ARN or just the job queue name? Arn.split() essentially splits the ARN, it can't handle the resource name.
  2. Before you create the Alarm, are you able to CfnOutput the resourceName variable and make sure it is exactly what you need?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 and removed needs-triage This issue or PR still needs to be triaged. labels Jul 23, 2024
@pahud pahud changed the title aws-cdk-lib: Arn.split cannot parse AWS Batch Job queue ARN cloudwatch: Arn.split cannot parse AWS Batch Job queue ARN Jul 23, 2024
@pahud pahud added @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch @aws-cdk/aws-batch Related to AWS Batch and removed aws-cdk-lib Related to the aws-cdk-lib package labels Jul 23, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 25, 2024
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-batch Related to AWS Batch @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants