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

aws_batch_alpha: [object Object] in Cfn template synthetized image name with ECR image #25250

Closed
diego-santacruz opened this issue Apr 22, 2023 · 3 comments · Fixed by #25466
Closed
Assignees
Labels
@aws-cdk/aws-batch Related to AWS Batch bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@diego-santacruz
Copy link

Describe the bug

With the update to the new aws_batch_alpha API in 2.74 now using an ECR image synthetizes an incorrect image name in the JobDefinition: it has [object Object] instead of the intrinsic AWS::URLSuffix (i.e. amazonaws.com).

Expected Behavior

I expect the output of the code snippet below to be something like this

  "VideocvtJobCC7DC772": {
   "Type": "AWS::Batch::JobDefinition",
   "Properties": {
    "Type": "container",
    "ContainerProperties": {
     "Environment": [],
     "ExecutionRoleArn": {
      "Fn::GetAtt": [
       "VideocvtJobDefExecutionRole8D68368F",
       "Arn"
      ]
     },
     "Image": "123456789012.dkr.ecr.eu-central-1.amazonaws.com/name:my-tag",
     "ReadonlyRootFilesystem": false,
     "ResourceRequirements": [
      {
       "Type": "MEMORY",
       "Value": "4096"
      },
      {
       "Type": "VCPU",
       "Value": "1"
      }
     ]
    },
    "PlatformCapabilities": [
     "EC2"
    ],
    "RetryStrategy": {},
    "Timeout": {}
   },
   "Metadata": {
    "aws:cdk:path": "DevDSC/AryaBackendStateless/Videocvt/Job/Resource"
   }
  }

Or eventually with the following for Image above

       {
        "Fn::Join": [
         "",
         [
          "123456789012.dkr.ecr.eu-central-1.",
          {
           "Ref": "AWS::URLSuffix"
          },
          "/name:my-tag"
         ]
        ]
       }

Current Behavior

But the synthesis output is like this, note [object Object] in Image

  "VideocvtJobCC7DC772": {
   "Type": "AWS::Batch::JobDefinition",
   "Properties": {
    "Type": "container",
    "ContainerProperties": {
     "Environment": [],
     "ExecutionRoleArn": {
      "Fn::GetAtt": [
       "VideocvtJobDefExecutionRole8D68368F",
       "Arn"
      ]
     },
     "Image": "123456789012.dkr.ecr.eu-central-1.[object Object]/name:my-tag",
     "ReadonlyRootFilesystem": false,
     "ResourceRequirements": [
      {
       "Type": "MEMORY",
       "Value": "4096"
      },
      {
       "Type": "VCPU",
       "Value": "1"
      }
     ]
    },
    "PlatformCapabilities": [
     "EC2"
    ],
    "RetryStrategy": {},
    "Timeout": {}
   },
   "Metadata": {
    "aws:cdk:path": "DevDSC/AryaBackendStateless/Videocvt/Job/Resource"
   }
  }

Reproduction Steps

The following code snipped generated the faulty example above.

    const repo = ecr.Repository.fromRepositoryArn(this, 'Repo', 'arn:aws:ecr:eu-central-1:123456789012:repository/name');
    new batch.EcsJobDefinition(this, 'Job', {
      container: new batch.EcsEc2ContainerDefinition(this, 'JobDef', {
        image: ecs.ContainerImage.fromEcrRepository(repo, 'my-tag'),
        cpu: 1,
        memory: cdk.Size.gibibytes(4)
      })
    });

Possible Solution

No idea, but there seems to be a problem with the rendering of tokens.

Additional Information/Context

No response

CDK CLI Version

2.76

Framework Version

2.76

Node.js Version

v16.18.1

OS

Linux

Language

Typescript

Language Version

4.9.5

Other information

No response

@diego-santacruz diego-santacruz added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 22, 2023
@github-actions github-actions bot added the @aws-cdk/aws-batch Related to AWS Batch label Apr 22, 2023
@pahud
Copy link
Contributor

pahud commented Apr 24, 2023

Yes I can reproduce this bug. Thank you for your report.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 24, 2023
@JanTancibok
Copy link

I have same issue, more over I have wrong also first part of image name:
[object Object].dkr.ecr.[object Object].[object Object]/[object Object]:latest

code, shortened:
`
import { EcrImage } from "aws-cdk-lib/aws-ecs";
import { FargateComputeEnvironment, EcsFargateContainerDefinition, JobQueue, EcsJobDefinition } from "@aws-cdk/aws-batch-alpha";

const container: EcsFargateContainerDefinition = new EcsFargateContainerDefinition(
scope,
"dailyJobContainerDefinition",
{
image: new EcrImage(repo, this.getImageTag()),
...
}
);

return new EcsJobDefinition(scope, "dailyJobDefinition", { container, ... });`

@comcalvi comcalvi self-assigned this May 3, 2023
@mergify mergify bot closed this as completed in #25466 May 8, 2023
mergify bot pushed a commit that referenced this issue May 8, 2023
…d with `[Object object]` (#25466)

We were using `Tokenization.resolve()`, which uses a generic token resolver that does `${token1}${token2}` instead of creating an `Fn::Split` object. The only reason that token existed was to mutate the L1 object after synthesis so subclasses could fill in the `executionRole`. The `executionRole` was meant to be optional for EC2 jobs and required for Fargate jobs. Setting the `loggingConfig` being defined would force it to be defined it for EC2 Jobs. However, the `loggingConfig` was always defined, because it was set to a `Lazy` (which could result in `undefined`, but that doesn't matter: it was defined during synthesis). So the `executionRole` was always being set:

```
    this.executionRole = props.executionRole ?? (this.logDriverConfig ? createExecutionRole(this, 'ExecutionRole') : undefined);
```

This PR makes it clear that the `executionRole` is created by default.

Closes #25250

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented May 8, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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 bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
4 participants