-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(events-targets): allow all ECS TaskOverrides #32344
base: main
Are you sure you want to change the base?
Conversation
*/ | ||
export interface EphemeralStorageOverride { | ||
/** | ||
* The total amount, in GiB, of ephemeral storage to set for the task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied these docstrings from the Task Override docs: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_TaskOverride.html
@@ -50,6 +50,54 @@ export interface EcsTaskProps extends TargetBaseProps { | |||
*/ | |||
readonly containerOverrides?: ContainerOverride[]; | |||
|
|||
/** | |||
* The CPU override for the task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, copied from the upstream docs: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_TaskOverride.html
const taskCount = this.taskCount; | ||
const taskDefinitionArn = this.taskDefinition.taskDefinitionArn; | ||
const propagateTags = this.propagateTags; | ||
const tagList = this.tags; | ||
const enableExecuteCommand = this.enableExecuteCommand; | ||
const input = this.createInput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this logic is more complex now, I refactored it to a dedicated private method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #32344 +/- ##
=======================================
Coverage 80.92% 80.92%
=======================================
Files 236 236
Lines 14253 14253
Branches 2490 2490
=======================================
Hits 11534 11534
Misses 2434 2434
Partials 285 285
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! Looks good, just a few nits
* | ||
* @default - The task definition's ephemeral storage value | ||
*/ | ||
readonly ephemeralStorage?: EphemeralStorageOverride; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: since there is only one property in the EphemeralStorageOverride
interface would it be better to just support that there? Something like ephemeralStorageSizeInGiB: number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the upstream CFN object, since it's an object: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_EphemeralStorage.html
Since they made it an object in CFN, my thinking is that there might be additional properties added later on, so I followed that pattern here.
However, if you'd prefer the L2 implementation to hide this detail, I can make it a single property. Just let me know.
packages/aws-cdk-lib/aws-events-targets/test/ecs/event-rule-target.test.ts
Outdated
Show resolved
Hide resolved
@@ -47,6 +47,8 @@ rule.addTarget(new targets.EcsTask({ | |||
taskDefinition, | |||
taskCount: 1, | |||
enableExecuteCommand: true, | |||
cpu: '512', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we add assertions to ensure the CPU is overridden?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure - I've never used the assertions feature - let me look into how to do it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaythapa I spent about 4 hours today trying to get this working and, unfortunately, I'm stumped. It seems that the integration assertion logic does not support the JSON-stringified Input
parameter well. I've tried many iterations of things, but I can't extract the properties correctly.
const ruleDetails = integTest.assertions.awsApiCall('CloudWatchEvents', 'listTargetsByRule', {
Rule: rule.ruleName,
});
ruleDetails.assertAtPath('Targets.0.Input', integ.ExpectedResult.objectLike({
cpu: '512',
}));
Fails with:
{
"Status": "SUCCESS",
"Reason": "OK",
"PhysicalResourceId": "AwsApiCallCloudWatchEventslistTargetsByRule9b8ce4aebbf85138ea0a2d2c72bf5f5a",
"StackId": "arn:aws:cloudformation:us-east-1:291961553751:stack/EcsFargateTestDefaultTestDeployAssert36341BFB/cf6d79a0-e65d-11ef-818c-0affd8c950cf",
"RequestId": "4f0bc12e-8155-4cf3-a37c-80272da0b959",
"LogicalResourceId": "AwsApiCallCloudWatchEventslistTargetsByRule9b8ce4aebbf85138ea0a2d2c72bf5f5a",
"NoEcho": false,
"Data": {
"failed": true,
"assertion": "{\"status\":\"fail\",\"message\":\"!! Expected type object but received undefined\\nundefined\"}",
"apiCallResponse.Targets.0.Input.containerOverrides.0.name": "TheContainer",
"apiCallResponse.Targets.0.Input.containerOverrides.0.environment.0.name": "I_WAS_TRIGGERED",
"apiCallResponse.Targets.0.Input.containerOverrides.0.environment.0.value": "From CloudWatch Events",
"apiCallResponse.Targets.0.Input.cpu": "512",
"apiCallResponse.Targets.0.Input.memory": "512"
}
}
I also can't do an exact match on the CPU like this:
const ruleDetails = integTest.assertions.awsApiCall('CloudWatchEvents', 'listTargetsByRule', {
Rule: rule.ruleName,
});
ruleDetails.assertAtPath('Targets.0.Input.cpu', integ.ExpectedResult.exact("512"));
This also doesn't work:
const ruleDetails = integTest.assertions.awsApiCall('CloudWatchEvents', 'listTargetsByRule', {
Rule: rule.ruleName,
});
ruleDetails.expect(integ.ExpectedResult.objectLike({
Targets: Match.arrayWith([
Match.objectLike({
Input: Match.objectLike({
cpu: '512',
}),
}),
]),
}));
fails with:
"{\n!! Expected type object but received array\n \"Targets\": [\n { ... },\n { ... },\n { ... }\n ]\n}"}
I even copied the custom resource down and played with a ton of different iterations and nothing works.
I can confirm that the actual state of the integration test is correct. Could you assist me with:
a) providing the proper syntax for the integration test; or,
b) merge the PR without adding the assertion
Thanks in advance for taking a look!
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Issue #32217
Closes #32217.
Reason for this change
ECS targets can override any item in the
TaskOverride
structure via theinput
parameter, according to the docs.However, today, only the
containerOverrides
option is exposed:aws-cdk/packages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts
Lines 225 to 227 in 1b7265b
Description of changes
This PR adds all
TaskOverride
properties to theinput
parameter.Description of how you validated changes
I add unit tests. I also updated the existing integration tests to include additional overrides. I validated them in my AWS account.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license