-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a new construct library for ECS (#1058)
Add a new construct library to start services on ECS, both on EC2 and Fargate-based clusters. Containers can be started from images that are publicly available on DockerHub, images in ECR repositories, and images built directly from sources that are stored in source code next to the CDK app. ECS services can be used as load balancer targets, and there are higher-level constructs available to make it easy to start a service behind a load balancer. BREAKING CHANGE: the ec2.Connections object has been changed to be able to manage multiple security groups. The relevant property has been changed from `securityGroup` to `securityGroups` (an array of security group objects).
- Loading branch information
Showing
86 changed files
with
9,392 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ pack | |
coverage | ||
.nyc_output | ||
.LAST_BUILD | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.LAST_BUILD | ||
*.snk | ||
hello-cdk-ecs/cdk.json | ||
*.snk |
3 changes: 3 additions & 0 deletions
3
examples/cdk-examples-typescript/hello-cdk-ecs-declarative/cdk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "fargate-service.yml" | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/cdk-examples-typescript/hello-cdk-ecs-declarative/fargate-service.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# applet is loaded from the local ./test-applet.js file | ||
applets: | ||
LoadBalancedFargateService: | ||
type: @aws-cdk/aws-ecs:LoadBalancedFargateServiceApplet | ||
properties: | ||
image: 'amazon/amazon-ecs-sample' | ||
cpu: "2048" | ||
memoryMiB: "1024" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import { InstanceType } from '@aws-cdk/aws-ec2'; | ||
import ecs = require('@aws-cdk/aws-ecs'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
|
||
class BonjourECS extends cdk.Stack { | ||
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { | ||
super(parent, name, props); | ||
|
||
// For better iteration speed, it might make sense to put this VPC into | ||
// a separate stack and import it here. We then have two stacks to | ||
// deploy, but VPC creation is slow so we'll only have to do that once | ||
// and can iterate quickly on consuming stacks. Not doing that for now. | ||
const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); | ||
const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc }); | ||
cluster.addDefaultAutoScalingGroupCapacity({ | ||
instanceType: new InstanceType("t2.xlarge"), | ||
instanceCount: 3, | ||
}); | ||
|
||
// Instantiate ECS Service with just cluster and image | ||
const ecsService = new ecs.LoadBalancedEc2Service(this, "Ec2Service", { | ||
cluster, | ||
memoryLimitMiB: 512, | ||
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"), | ||
}); | ||
|
||
// Output the DNS where you can access your service | ||
new cdk.Output(this, 'LoadBalancerDNS', { value: ecsService.loadBalancer.dnsName }); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
|
||
new BonjourECS(app, 'Bonjour'); | ||
|
||
app.run(); |
29 changes: 29 additions & 0 deletions
29
examples/cdk-examples-typescript/hello-cdk-fargate/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import ecs = require('@aws-cdk/aws-ecs'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
|
||
class BonjourFargate extends cdk.Stack { | ||
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { | ||
super(parent, name, props); | ||
|
||
// Create VPC and Fargate Cluster | ||
// NOTE: Limit AZs to avoid reaching resource quotas | ||
const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); | ||
const cluster = new ecs.Cluster(this, 'Cluster', { vpc }); | ||
|
||
// Instantiate Fargate Service with just cluster and image | ||
const fargateService = new ecs.LoadBalancedFargateService(this, "FargateService", { | ||
cluster, | ||
image: ecs.DockerHub.image("amazon/amazon-ecs-sample"), | ||
}); | ||
|
||
// Output the DNS where you can access your service | ||
new cdk.Output(this, 'LoadBalancerDNS', { value: fargateService.loadBalancer.dnsName }); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
|
||
new BonjourFargate(app, 'Bonjour'); | ||
|
||
app.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.