Skip to content

Commit

Permalink
Merge branch 'main' into gh-26428
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jul 25, 2023
2 parents c74ef02 + f24ece1 commit 8f1959b
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@
"JobQueueArn"
]
},
"\",\"Parameters\":{\"foo.$\":\"$.bar\"},\"ContainerOverrides\":{\"Environment\":[{\"Name\":\"key\",\"Value\":\"value\"}],\"ResourceRequirements\":[{\"Type\":\"MEMORY\",\"Value\":\"256\"},{\"Type\":\"VCPU\",\"Value\":\"1\"}]},\"RetryStrategy\":{\"Attempts\":3},\"Timeout\":{\"AttemptDurationSeconds\":60}}}}}"
"\",\"Parameters\":{\"foo.$\":\"$.bar\"},\"ContainerOverrides\":{\"Environment\":[{\"Name\":\"key\",\"Value\":\"value\"}],\"ResourceRequirements\":[{\"Type\":\"MEMORY\",\"Value\":\"256\"},{\"Type\":\"VCPU\",\"Value\":\"1\"}]},\"RetryStrategy\":{\"Attempts\":3},\"Tags\":{\"key\":\"value\"},\"Timeout\":{\"AttemptDurationSeconds\":60}}}}}"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class RunBatchStack extends cdk.Stack {
}),
attempts: 3,
taskTimeout: sfn.Timeout.duration(cdk.Duration.seconds(60)),
tags: {
key: 'value',
},
});

const definition = new sfn.Pass(this, 'Start', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,89 @@ test('Task throws if attempt duration is less than 60 sec', () => {
/attempt duration must be greater than 60 seconds./,
);
});

test('supports passing tags', () => {
// WHEN
const task = new BatchSubmitJob(stack, 'Task', {
jobDefinitionArn: batchJobDefinition.jobDefinitionArn,
jobQueueArn: batchJobQueue.jobQueueArn,
jobName: sfn.JsonPath.stringAt('$.jobName'),
tags: {
test: 'this is a tag',
},
});

// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::batch:submitJob.sync',
],
],
},
End: true,
Parameters: {
'JobDefinition': { Ref: 'JobDefinition24FFE3ED' },
'JobName.$': '$.jobName',
'JobQueue': {
'Fn::GetAtt': [
'JobQueueEE3AD499',
'JobQueueArn',
],
},
'Tags': {
test: 'this is a tag',
},
},
});
});

test('throws if tags has invalid value', () => {
expect(() => {
const tags: { [key: string]: string } = {};
for (let i = 0; i < 100; i++) {
tags[i] = 'tag';
}
new BatchSubmitJob(stack, 'Task1', {
jobDefinitionArn: batchJobDefinition.jobDefinitionArn,
jobName: 'JobName',
jobQueueArn: batchJobQueue.jobQueueArn,
tags,
});
}).toThrow(
/Maximum tag number of entries is 50./,
);

expect(() => {
const keyTooLong = 'k'.repeat(150);
const tags: { [key: string]: string } = {};
tags[keyTooLong] = 'tag';
new BatchSubmitJob(stack, 'Task2', {
jobDefinitionArn: batchJobDefinition.jobDefinitionArn,
jobName: 'JobName',
jobQueueArn: batchJobQueue.jobQueueArn,
tags,
});
}).toThrow(
/Tag key size must be between 1 and 128/,
);

expect(() => {
const tags = { key: 'k'.repeat(300) };
new BatchSubmitJob(stack, 'Task3', {
jobDefinitionArn: batchJobDefinition.jobDefinitionArn,
jobName: 'JobName',
jobQueueArn: batchJobQueue.jobQueueArn,
tags,
});
}).toThrow(
/Tag value maximum size is 256/,
);
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Construct } from 'constructs';
import { ISecurityGroup, SubnetSelection } from '../../../aws-ec2';
import { FargateService, FargateTaskDefinition } from '../../../aws-ecs';
import { FeatureFlags } from '../../../core';
import { FeatureFlags, Token } from '../../../core';
import * as cxapi from '../../../cx-api';
import { ApplicationLoadBalancedServiceBase, ApplicationLoadBalancedServiceBaseProps } from '../base/application-load-balanced-service-base';
import { FargateServiceBaseProps } from '../base/fargate-service-base';
Expand Down Expand Up @@ -96,6 +96,19 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
throw new Error('You must specify one of: taskDefinition or image');
}

this.validateHealthyPercentage('minHealthyPercent', props.minHealthyPercent);
this.validateHealthyPercentage('maxHealthyPercent', props.maxHealthyPercent);

if (
props.minHealthyPercent &&
!Token.isUnresolved(props.minHealthyPercent) &&
props.maxHealthyPercent &&
!Token.isUnresolved(props.maxHealthyPercent) &&
props.minHealthyPercent >= props.maxHealthyPercent
) {
throw new Error('Minimum healthy percent must be less than maximum healthy percent.');
}

const desiredCount = FeatureFlags.of(this).isEnabled(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT) ? this.internalDesiredCount : this.desiredCount;

this.service = new FargateService(this, 'Service', {
Expand All @@ -120,4 +133,14 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
});
this.addServiceAsTarget(this.service);
}

/**
* Throws an error if the specified percent is not an integer or negative.
*/
private validateHealthyPercentage(name: string, value?: number) {
if (value === undefined || Token.isUnresolved(value)) { return; }
if (!Number.isInteger(value) || value < 0) {
throw new Error(`${name}: Must be a non-negative integer; received ${value}`);
}
}
}
Loading

0 comments on commit 8f1959b

Please sign in to comment.