Skip to content

Commit 05810f4

Browse files
authored
fix(batch-alpha): cannot import FargateComputeEnvironment with fromFargateComputeEnvironmentArn (#25985)
Change the superclass of the [Import](https://github.com/aws/aws-cdk/blob/104bf32798b02f8f3c3ec5aaa05e31c35b4a38da/packages/%40aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts#L1071) class instantiated by `fromFargateComputeEnvironmentArn` from `ManagedComputeEnvironmentBase` to `Resource`. This prevents errors due to the required `vpc` parameter of the old superclass [being passed](https://github.com/aws/aws-cdk/blob/104bf32798b02f8f3c3ec5aaa05e31c35b4a38da/packages/%40aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts#L1077-L1079) as `undefined`. Closes #25979. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4729d76 commit 05810f4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/@aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1068,15 +1068,17 @@ export class FargateComputeEnvironment extends ManagedComputeEnvironmentBase imp
10681068
const stack = Stack.of(scope);
10691069
const computeEnvironmentName = stack.splitArn(fargateComputeEnvironmentArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!;
10701070

1071-
class Import extends ManagedComputeEnvironmentBase implements IFargateComputeEnvironment {
1071+
class Import extends Resource implements IFargateComputeEnvironment {
10721072
public readonly computeEnvironmentArn = fargateComputeEnvironmentArn;
10731073
public readonly computeEnvironmentName = computeEnvironmentName;
10741074
public readonly enabled = true;
1075+
public readonly maxvCpus = 1;
1076+
public readonly connections = { } as any;
1077+
public readonly securityGroups = [];
1078+
public readonly tags: TagManager = new TagManager(TagType.MAP, 'AWS::Batch::ComputeEnvironment');
10751079
}
10761080

1077-
return new Import(scope, id, {
1078-
vpc: undefined as any,
1079-
});
1081+
return new Import(scope, id);
10801082
}
10811083

10821084
public readonly computeEnvironmentName: string;

packages/@aws-cdk/aws-batch-alpha/test/managed-compute-environment.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -935,4 +935,12 @@ describe('FargateComputeEnvironment', () => {
935935
ComputeEnvironmentName: 'maxPropsFargateCE',
936936
});
937937
});
938+
939+
test('can be imported from arn', () => {
940+
// WHEN
941+
const ce = FargateComputeEnvironment.fromFargateComputeEnvironmentArn(stack, 'import', 'arn:aws:batch:us-east-1:123456789012:compute-environment/ce-name');
942+
943+
// THEN
944+
expect(ce.computeEnvironmentArn).toEqual('arn:aws:batch:us-east-1:123456789012:compute-environment/ce-name');
945+
});
938946
});

0 commit comments

Comments
 (0)