-
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: construct library for ECS #1041
Changes from all commits
939452c
7302a2f
4c7127a
98749ec
6d0942f
bddfe56
3574611
a63c377
b00e0dd
80ba2e4
0980f52
8648540
2d53d89
dbdab86
ee6b427
2b16dad
16a92c0
ae881c2
0672e6a
4f93a5b
9b61b89
98bf81b
ae1d525
23072a9
e5cc7f2
047eed8
65d3f79
11541d3
fb17532
be8cb86
b8cce3a
2741608
a901912
a91bda7
51adff5
70ae682
298e0a7
1541edd
a154d09
4b46685
9875c6e
1044d1c
e7f8000
e7f7b7d
dda869d
97083dc
a3e3615
b913f0e
fd21c0d
3b4695c
187f62b
6912e3f
2bf2d57
f477d8d
b947f51
ab83d35
30cb925
c64e184
566aac3
96e3105
48cd8d4
e311293
4ffed09
97d3db3
4f9b548
e8aa186
eb4a562
e06a3ec
95b8d84
5595707
a1b78f4
6f08406
5312362
6f42026
1983858
4ea6b8b
e34d515
bf90c27
ffbad9f
d1b22bd
7840634
d1ec640
36e1ba2
178898f
b73bdad
049557e
2295ef2
f34c23c
c491a1d
430f81e
dca6972
cf528d6
ef51786
c3b543a
64b6d06
af5a2a4
51097fd
7b19dd2
9bea6be
4ab455c
be9f447
2eab513
57857a9
4cf23fc
37d3c4e
1ad3669
78d2a49
ca61a74
98345b3
35ebd9c
09a182a
2fd2e7c
9825127
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 |
---|---|---|
|
@@ -10,3 +10,5 @@ pack | |
coverage | ||
.nyc_output | ||
.LAST_BUILD | ||
*.swp | ||
./examples/cdk-examples-typescript/hello-cdk-ecs/cdk.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "../node_modules/.bin/cdk-applet-js fargate-service.yml" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# applet is loaded from the local ./test-applet.js file | ||
applet: @aws-cdk/aws-ecs:LoadBalancedFargateServiceApplet | ||
image: 'amazon/amazon-ecs-sample' | ||
cpu: "2048" | ||
memoryMiB: "1024" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"app": "node index", | ||
"context": { | ||
"availability-zones:585695036304:us-east-1": [ | ||
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. Is it normal practice in the CDK to check in account IDs? Normally we avoid publicly sharing account IDs... 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. Nope. We should definitely delete 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. Yeah this should not have been checked in. 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. Do we expect customers to check this in to their repos, or should cdk.json generally be git'ignored? Should cdk init add that to a .gitignore file? Sounds like we need a separate issue to track that 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. fyi this stuff is online for all to see |
||
"us-east-1a", | ||
"us-east-1b", | ||
"us-east-1c", | ||
"us-east-1d", | ||
"us-east-1e", | ||
"us-east-1f" | ||
], | ||
"ssm:585695036304:us-east-1:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-14c5486b", | ||
"availability-zones:585695036304:eu-west-2": [ | ||
"eu-west-2a", | ||
"eu-west-2b", | ||
"eu-west-2c" | ||
], | ||
"ssm:585695036304:eu-west-2:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-a36f8dc4", | ||
"availability-zones:585695036304:eu-west-1": [ | ||
"eu-west-1a", | ||
"eu-west-1b", | ||
"eu-west-1c" | ||
], | ||
"ssm:585695036304:eu-west-1:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-ca0135b3", | ||
"availability-zones:794715269151:us-west-2": [ | ||
"us-west-2a", | ||
"us-west-2b", | ||
"us-west-2c" | ||
], | ||
"availability-zones:993655754359:us-west-2": [ | ||
"us-west-2a", | ||
"us-west-2b", | ||
"us-west-2c" | ||
], | ||
"availability-zones:993655754359:eu-west-1": [ | ||
"eu-west-1a", | ||
"eu-west-1b", | ||
"eu-west-1c" | ||
], | ||
"ssm:794715269151:us-west-2:/aws/service/ecs/optimized-ami/amazon-linux/recommended": "{\"schema_version\":1,\"image_name\":\"amzn-ami-2018.03.g-amazon-ecs-optimized\",\"image_id\":\"ami-00430184c7bb49914\",\"os\":\"Amazon Linux\",\"ecs_runtime_version\":\"Docker version 18.06.1-ce\",\"ecs_agent_version\":\"1.20.3\"}" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
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.EcsCluster(this, 'EcsCluster', { | ||
vpc, | ||
size: 3, | ||
instanceType: new InstanceType("t2.xlarge") | ||
}); | ||
|
||
// Instantiate ECS Service with just cluster and image | ||
const ecsService = new ecs.LoadBalancedEcsService(this, "EcsService", { | ||
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(); | ||
|
||
// name, image, cpu, memory, port (with default) | ||
// | ||
// Include in constructs: | ||
// - networking - include SD, ALB | ||
// - logging - cloudwatch logs integration? talk to nathan about 3rd | ||
// party integrations - aggregated logging across the service | ||
// (instead of per task). Probably prometheus or elk? | ||
// - tracing aws-xray-fargate - CNCF opentracing standard - jaeger, | ||
// zipkin. | ||
// - so x-ray is a container that is hooked up to sidecars that come | ||
// with the application container itself | ||
// - autoscaling - application autoscaling (Fargate focused?) | ||
|
||
// const taskDefinition = new ecs.EcsTaskDefinition(this, "EcsTD", { | ||
// family: "ecs-task-definition", | ||
// }); | ||
|
||
// const container = taskDefinition.addContainer('web', { | ||
// image: ecs.DockerHub.image("amazon/amazon-ecs-sample"), | ||
// cpu: 1024, | ||
// memoryLimitMiB: 512, | ||
// essential: true | ||
// }); | ||
|
||
// container.linuxParameters.addCapabilities(ecs.Capability.All); | ||
// container.linuxParameters.dropCapabilities(ecs.Capability.Chown); | ||
|
||
// container.linuxParameters.addDevices({ | ||
// containerPath: "/dev/pudding", | ||
// hostPath: "/dev/clyde", | ||
// permissions: [ecs.DevicePermission.Read] | ||
// }); | ||
|
||
// container.linuxParameters.addTmpfs({ | ||
// containerPath: "/dev/sda", | ||
// size: 12345, | ||
// mountOptions: [ecs.TmpfsMountOption.Ro] | ||
// }); | ||
|
||
// container.linuxParameters.sharedMemorySize = 65535; | ||
// container.linuxParameters.initProcessEnabled = true; | ||
|
||
// container.addUlimits({ | ||
// name: ecs.UlimitName.Core, | ||
// softLimit: 1234, | ||
// hardLimit: 1234, | ||
// }); | ||
|
||
// container.addPortMappings({ | ||
// containerPort: 80, | ||
// // hostPort: 80, | ||
// protocol: ecs.Protocol.Tcp, | ||
// }); | ||
|
||
// container.addMountPoints({ | ||
// containerPath: '/tmp/cache', | ||
// sourceVolume: 'volume-1', | ||
// readOnly: true, | ||
// }, { | ||
// containerPath: './cache', | ||
// sourceVolume: 'volume-2', | ||
// readOnly: true, | ||
// }); | ||
|
||
// container.addVolumesFrom({ | ||
// sourceContainer: 'web', | ||
// readOnly: true, | ||
// }); | ||
|
||
// new ecs.EcsService(this, "EcsService", { | ||
// cluster, | ||
// taskDefinition, | ||
// desiredCount: 1, | ||
// }); | ||
// } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"app": "node index", | ||
"context": { | ||
"availability-zones:585695036304:us-east-1": [ | ||
"us-east-1a", | ||
"us-east-1b", | ||
"us-east-1c", | ||
"us-east-1d", | ||
"us-east-1e", | ||
"us-east-1f" | ||
], | ||
"ssm:585695036304:us-east-1:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-14c5486b", | ||
"availability-zones:585695036304:eu-west-2": [ | ||
"eu-west-2a", | ||
"eu-west-2b", | ||
"eu-west-2c" | ||
], | ||
"ssm:585695036304:eu-west-2:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-a36f8dc4", | ||
"availability-zones:585695036304:eu-west-1": [ | ||
"eu-west-1a", | ||
"eu-west-1b", | ||
"eu-west-1c" | ||
], | ||
"ssm:585695036304:eu-west-1:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-ca0135b3", | ||
"availability-zones:794715269151:us-west-2": [ | ||
"us-west-2a", | ||
"us-west-2b", | ||
"us-west-2c" | ||
], | ||
"availability-zones:993655754359:us-west-2": [ | ||
"us-west-2a", | ||
"us-west-2b", | ||
"us-west-2c" | ||
], | ||
"availability-zones:993655754359:eu-west-1": [ | ||
"eu-west-1a", | ||
"eu-west-1b", | ||
"eu-west-1c" | ||
], | ||
"ssm:794715269151:us-west-2:/aws/service/ecs/optimized-ami/amazon-linux/recommended": "{\"schema_version\":1,\"image_name\":\"amzn-ami-2018.03.g-amazon-ecs-optimized\",\"image_id\":\"ami-00430184c7bb49914\",\"os\":\"Amazon Linux\",\"ecs_runtime_version\":\"Docker version 18.06.1-ce\",\"ecs_agent_version\":\"1.20.3\"}", | ||
"availability-zones:794715269151:eu-west-1": [ | ||
"eu-west-1a", | ||
"eu-west-1b", | ||
"eu-west-1c" | ||
] | ||
} | ||
} |
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.FargateCluster(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(); |
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.
How do I get this magical cdk-applet-js file, because it is not appearing for me locally even after a build