Skip to content
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

Updating all Python examples for CDK release 0.38 #70

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/ecs/cluster/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:

vpc = ec2.Vpc(
self, "MyVpc",
max_a_zs=2
max_azs=2
)

asg = autoscaling.AutoScalingGroup(
Expand Down
4 changes: 2 additions & 2 deletions python/ecs/ecs-load-balanced-service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:

vpc = ec2.Vpc(
self, "MyVpc",
max_a_zs=2
max_azs=2
)

cluster = ecs.Cluster(
Expand All @@ -27,7 +27,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
ecs_service = ecs_patterns.LoadBalancedEc2Service(
self, "Ec2Service",
cluster=cluster,
memory_limit_mi_b=512,
memory_limit_mib=512,
image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
)

Expand Down
23 changes: 14 additions & 9 deletions python/ecs/ecs-service-with-advanced-alb-config/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@
# Create a cluster
vpc = ec2.Vpc(
stack, "MyVpc",
max_a_zs=2
max_azs=2
)

cluster = ecs.Cluster(
stack, 'EcsCluster',
vpc=vpc
)
cluster.add_capacity("DefaultAutoScalingGroup",
instance_type=ec2.InstanceType("t2.micro"))
instance_type=ec2.InstanceType.of(
ec2.InstanceClass.STANDARD5,
ec2.InstanceSize.MICRO))

# Create Task Definition
task_definition = ecs.Ec2TaskDefinition(
stack, "TaskDef")
container = task_definition.add_container(
"web",
image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
memory_limit_mi_b=256
memory_limit_mib=256
)
container.add_port_mappings(
port_mapping = ecs.PortMapping(
container_port=80,
host_port=8080,
protocol=ecs.Protocol.TCP
)
container.add_port_mappings(port_mapping)

# Create Service
service = ecs.Ec2Service(
Expand All @@ -54,16 +57,18 @@
open=True
)

health_check = elbv2.HealthCheck(
interval=core.Duration.seconds(60),
path="/health",
timeout=core.Duration.seconds(5)
)

# Attach ALB to ECS Service
listener.add_targets(
"ECS",
port=80,
targets=[service],
health_check={
"interval_secs": 60,
"path": "/health",
"timeout_seconds": 5
}
health_check=health_check,
)

core.CfnOutput(
Expand Down
23 changes: 12 additions & 11 deletions python/ecs/ecs-service-with-task-networking/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
aws_ec2 as ec2,
aws_ecs as ecs,
aws_elasticloadbalancingv2 as elbv2,
cdk,
core,
)

# Based on https://aws.amazon.com/blogs/compute/introducing-cloud-native-networking-for-ecs-containers/

app = cdk.App()
stack = cdk.Stack(app, "ec2-service-with-task-networking")
app = core.App()
stack = core.Stack(app, "ec2-service-with-task-networking")

# Create a cluster
vpc = ec2.Vpc(
stack, "Vpc",
max_a_zs=2
max_azs=2
)

cluster = ecs.Cluster(
Expand All @@ -26,20 +26,21 @@
# Create a task definition with its own elastic network interface
task_definition = ecs.Ec2TaskDefinition(
stack, "nginx-awsvpc",
network_mode=ecs.NetworkMode.AwsVpc
network_mode=ecs.NetworkMode.AWS_VPC,
)

web_container = task_definition.add_container(
"nginx",
image=ecs.ContainerImage.from_registry("nginx:latest"),
cpu=100,
memory_limit_mi_b=256,
memory_limit_mib=256,
essential=True
)
web_container.add_port_mappings(
port_mapping = ecs.PortMapping(
container_port=80,
protocol=ecs.Protocol.Tcp
protocol=ecs.Protocol.TCP
)
web_container.add_port_mappings(port_mapping)

# Create a security group that allows HTTP traffic on port 80 for our
# containers without modifying the security group on the instance
Expand All @@ -49,8 +50,8 @@
allow_all_outbound=False
)
security_group.add_ingress_rule(
ec2.AnyIPv4(),
ec2.TcpPort(80)
ec2.Peer.any_ipv4(),
ec2.Port.tcp(80)
)

# Create the service
Expand All @@ -61,4 +62,4 @@
security_group=security_group
)

app.run()
app.synth()
7 changes: 4 additions & 3 deletions python/ecs/ecs-service-with-task-placement/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Create a cluster
vpc = ec2.Vpc(
stack, "Vpc",
max_a_zs=2
max_azs=2
)

cluster = ecs.Cluster(
Expand All @@ -32,13 +32,14 @@
container = task_definition.add_container(
"web",
image=ecs.ContainerImage.from_registry("nginx:latest"),
memory_limit_mi_b=256,
memory_limit_mib=256,
)
container.add_port_mappings(
port_mapping = ecs.PortMapping(
container_port=80,
host_port=8080,
protocol=ecs.Protocol.TCP
)
container.add_port_mappings(port_mapping)

# Create Service
service = ecs.Ec2Service(
Expand Down
2 changes: 1 addition & 1 deletion python/ecs/fargate-load-balanced-service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
# NOTE: Limit AZs to avoid reaching resource quotas
vpc = ec2.Vpc(
self, "MyVpc",
max_a_zs=2
max_azs=2
)

cluster = ecs.Cluster(
Expand Down
2 changes: 1 addition & 1 deletion python/ecs/fargate-service-with-autoscaling/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
# Create a cluster
vpc = ec2.Vpc(
self, "Vpc",
max_a_zs=2
max_azs=2
)

cluster = ecs.Cluster(
Expand Down