aws-ecs-patterns: Allow ScheduledFargateTask and ScheduledEc2Task to run on a public subnet
See original GitHub issueAllow ScheduledFargateTask
and ScheduledEc2Task
to run in a public subnet via a configuration option.
Use Case
I’m currently using the ScheduledFargateTask
class to run a number of simple tasks. The tasks need access to the internet, but there’s no need for them to be accessible from the internet. I could run the tasks on a private subnet, but this would mean I would need either a NAT Gateway (expensive) or run a NAT Instance on EC2 (maintenance/complexity overhead).
Since the tasks only run for a few minutes every week I’m willing to sacrifice the extra security that a private subnet provides in favour of a simpler/cheaper system where the tasks run on a public subnet.
However, currently ScheduledFargateTask
will only run a task if its VPC has a private subnet - if there is no private subnet available, an error is reported. I would like to be able to run my tasks on a VPC defined along the following lines:
const vpc = new ec2.Vpc(stack, 'Vpc', {
maxAzs: 1,
natGateways: 0,
subnetConfiguration: [
{ name: 'public', cidrMask: 24, subnetType: SubnetType.PUBLIC }
],
});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
Proposed Solution
Currently the addTaskDefinitionToEventTarget
method on ScheduledTaskBase
instantiates the underlying EcsTask
, but there is no way to specify the subnetSelection
property of that EcsTask
and so it defaults to { subnetType: ec2.SubnetType.PRIVATE }
.
I propose that we add a subnetSelection
property to the ScheduledTaskBaseProps
interface and supply that property when instantiating the underlying EcsTask
. This new property would default to { subnetType: ec2.SubnetType.PRIVATE }
thus retaining the existing behaviour.
Other
-
In this comment @skinny85 mentioned that this is a gap in the
ScheduledFargateTask
construct. -
In this comment @moofish32 suggested that using only a public subnet is a reasonable option in some circumstances.
-
Reading between the lines, it sounds as if others commenting on this issue might welcome this functionality.
-
👋 I may be able to implement this feature request
-
⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (5 by maintainers)
Top GitHub Comments
@SoManyHs @pkandasamy91 I checked the “I may be able to implement this feature request” checkbox in the issue description as per the contribution guidelines. Is it worth me submitting a PR for this issue or are you unlikely to accept it…?
Here’s a working solution in Python. I had to inherit from
aws_ecs_patterns.ScheduledTaskBase
instead ofaws_ecs_patterns.ScheduledFargateTask
, because the overridden method_add_task_definition_to_event_target()
would never get called.And then you can create your VPC with a public subnet only and no NAT gateways: