-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: add subnets
prop to GuScheduledEcsTask
#1891
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { CfnOutput, Duration } from "aws-cdk-lib"; | ||
import { Alarm, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch"; | ||
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions"; | ||
import type { ISecurityGroup, IVpc } from "aws-cdk-lib/aws-ec2"; | ||
import type { ISecurityGroup, ISubnet, IVpc } from "aws-cdk-lib/aws-ec2"; | ||
import type { IRepository } from "aws-cdk-lib/aws-ecr"; | ||
import { | ||
Cluster, | ||
|
@@ -20,6 +20,7 @@ import { Construct } from "constructs"; | |
import type { NoMonitoring } from "../cloudwatch"; | ||
import type { GuStack } from "../core"; | ||
import { AppIdentity } from "../core"; | ||
import { GuVpc, SubnetType } from "../ec2"; | ||
import { GuGetDistributablePolicyStatement } from "../iam"; | ||
|
||
/** | ||
|
@@ -112,6 +113,7 @@ export interface GuEcsTaskProps extends AppIdentity { | |
customTaskPolicies?: PolicyStatement[]; | ||
environmentOverrides?: TaskEnvironmentVariable[]; | ||
storage?: number; | ||
subnets?: ISubnet[]; | ||
} | ||
|
||
/** | ||
|
@@ -135,6 +137,8 @@ const getContainer = (config: ContainerConfiguration) => { | |
* | ||
* Note that if your task reliably completes in less than 15 minutes then you should probably use a [[`GuLambda`]] instead. This | ||
* pattern was mainly created to work around the 15 minute lambda timeout. | ||
* | ||
* If the `subnets` prop is not defined, the task will run in a private subnet by default. | ||
*/ | ||
export class GuEcsTask extends Construct { | ||
stateMachine: StateMachine; | ||
|
@@ -154,6 +158,7 @@ export class GuEcsTask extends Construct { | |
taskTimeoutInMinutes = 15, | ||
customTaskPolicies, | ||
vpc, | ||
subnets = GuVpc.subnetsFromParameter(scope, { type: SubnetType.PRIVATE, app }), | ||
monitoringConfiguration, | ||
securityGroups = [], | ||
environmentOverrides, | ||
|
@@ -200,6 +205,7 @@ export class GuEcsTask extends Construct { | |
|
||
const task = new EcsRunTask(scope, `${id}-task`, { | ||
cluster, | ||
subnets: { subnets }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can be more opinionated here, and always place the task in the private subnet (similar to how we implement EC2 apps). WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it but wondered whether there were any use cases where a consumer would want the task in the public subnet. Couldn't really come up with any. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were you imagining something like this? const privateSubnets = GuVpc.subnetsFromParameter(scope, { type: SubnetType.PRIVATE, app });
const task = new EcsRunTask(scope, `${id}-task`, {
cluster,
subnets: { subnets: privateSubnets },
...
} This would effectively make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would work. If you wanted to keep the Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All done, thanks. Have also added a couple of tests. |
||
launchTarget: new EcsFargateLaunchTarget({ | ||
platformVersion: FargatePlatformVersion.LATEST, | ||
}), | ||
|
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.
Do we know where these new mappings originate from? Feels unrelated to the change we're making in this PR, so it's surprising to see.
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.
Not quite sure - I think I deleted the snapshot file while working on this, and rerunning the test generated these mappings. 🫠