Ejemplo n.º 1
0
    def test_fargate_launch_type(self):
        task_definition = ecs.TaskDefinition(
            "mytaskdef",
            ContainerDefinitions=[
                ecs.ContainerDefinition(
                    Image="myimage",
                    Memory="300",
                    Name="mycontainer",
                )
            ],
            Volumes=[
                ecs.Volume(Name="my-vol"),
            ],
        )
        ecs_service = ecs.Service(
            'Service',
            Cluster='cluster',
            DesiredCount=2,
            PlacementStrategies=[ecs.PlacementStrategy(Type="random", )],
            LaunchType='FARGATE',
            NetworkConfiguration=ecs.NetworkConfiguration(
                AwsVpcConfiguration=ecs.AwsVpcConfiguration(
                    AssignPublicIp='DISABLED',
                    SecurityGroups=['sg-1234'],
                    Subnets=['subnet-1234'])),
            PlacementConstraints=[
                ecs.PlacementConstraint(Type="distinctInstance", )
            ],
            TaskDefinition=Ref(task_definition),
        )

        ecs_service.to_dict()
Ejemplo n.º 2
0
    def test_allow_placement_strategy_constraint(self):
        task_definition = ecs.TaskDefinition(
            "mytaskdef",
            ContainerDefinitions=[
                ecs.ContainerDefinition(
                    Image="myimage",
                    Memory="300",
                    Name="mycontainer",
                )
            ],
            Volumes=[
                ecs.Volume(Name="my-vol"),
            ],
        )
        ecs_service = ecs.Service(
            'Service',
            Cluster='cluster',
            DesiredCount=2,
            PlacementStrategies=[
                ecs.PlacementStrategy(
                    Type="random",
                )
            ],
            PlacementConstraints=[
                ecs.PlacementConstraint(
                    Type="distinctInstance",
                )
            ],
            TaskDefinition=Ref(task_definition),
        )

        ecs_service.to_dict()
Ejemplo n.º 3
0
        LoadBalancers=[
            ecs.LoadBalancer(ContainerName=Ref(container_name),
                             ContainerPort=Ref(container_port),
                             TargetGroupArn=Ref(target_group)),
        ],
        PlacementStrategies=[
            ecs.PlacementStrategy(Type="spread",
                                  Field="attribute:ecs.availability-zone"),
            ecs.PlacementStrategy(Type="binpack", Field="memory"),
        ],
        Role=Ref(service_role),
        TaskDefinition=Ref(task_definition),
        DeploymentConfiguration=ecs.DeploymentConfiguration(
            MaximumPercent="100", MinimumHealthyPercent="50"),
        PlacementConstraints=[
            ecs.PlacementConstraint(Type="distinctInstance")
        ],
    ))
"""
Make the service a ScalableTarget
"""
# scalable_target = t.add_resource(applicationautoscaling.ScalableTarget(
#     'ScalableTarget',
#     MaxCapacity=Ref(autoscaling_max),
#     MinCapacity=Ref(autoscaling_min),
#     ResourceId=Join("/", [
#         "service",
#         ImportValue(Sub("${EcsStack}-Cluster")),
#         GetAtt(service, "Name")
#     ]),
#     RoleARN=GetAtt(autoscale_role, "Arn"),