-
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(aws-ecs): add ScheduledEc2Task L3 construct #2336
Conversation
/** | ||
* The schedule expression used to configure the event rule. | ||
*/ | ||
readonly scheduleExpression?: string; |
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.
What is the expected syntax for schedule Expression? In the README the example says 'rate(1 minute)'
, which seems not the most intuitive syntax.
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 schedulingExpressions are values that are provided by cloudwatch events: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
I'll update the comment to reflect this though.
import { ScheduledEc2Task } from '../lib'; | ||
|
||
export = { | ||
"Can create a scheduled Ec2 Task without a service"(test: Test) { |
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 phrasing of this unit test is a bit confusing. Is this just saying that we expect this construct to be a wrapper for an ECS task rather than a service? Also are there other API on the construct we should be unit testing?
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.
Is this just saying that we expect this construct to be a wrapper for an ECS task rather than a service? - Yes
Also are there other API on the construct we should be unit testing? - Fair point, adding more unit tests.
taskDefinition.addContainer('ScheduledTaskContainer', { | ||
image: props.image, | ||
memoryLimitMiB: props.memoryLimitMiB !== undefined ? props.memoryLimitMiB : 256, | ||
logging: props.enableLogging ? this.createAWSLogDriver(this.node.id) : undefined, |
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.
enableLogging might be undefined -- you need to set the default to be true somewhere.
To be clear, this is not possible in Fargate, correct? |
Correct, to use Fargate, I would need to add a network configuration as networkmode is awsvpc. This is not currently supported by Cloudformation. |
What exactly isn't supported by CFN? We currently allow for awsvpc network mode for both Fargate Services and regular EC2 Task Definitions. |
The A Fargate scheduled task would need a Custom Resource. It would be a great addition to the CDK (need this in my projects) and I'm willing to PR for this but I'd prefer a more generic solution using what I proposed in #1850. |
CloudFormation currently only supports clusters, services and taskdefinitions: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-reference-ecs.html. TaskDefinitions contain a network mode, and for EC2, we can use none, bridge or the many others, but in order to use awsvpc, you need to create a NetworkConfiguration, which is not supported in the TaskDefinition, but is supported in the Service. For this construct, we're creating a scheduled task (that is standalone task, not backed with a service), and for Fargate to support this feature, we'd need to have a CloudFormation create the concept of a standalone Task (not Task Definition) that can take a NetworkConfiguration property. It works for ECS because we're using bridge as the NetworkMode, which does not require a NetworkConfiguration to be present. |
@pkandasamy91 Ah, right -- I was more referring to the CFN support on CWE mentioned by @jogold (thanks for the comment). Appreciate the clarification. |
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.
Generally looks good -- could you combine #2363 with this PR?
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.
Style nit about spaces, otherwise LGTM!
packages/@aws-cdk/aws-ecs/test/ec2/integ.event-task.lit.expected.json
Outdated
Show resolved
Hide resolved
Squashed all commits |
Unit tests have been updated to handle merged changes. |
I notice you made these changes on the |
Defined a new construct to enable creating a ec2 task to be run at a scheduled interval
Fixes #2352
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.