-
Notifications
You must be signed in to change notification settings - Fork 13
/
ECS_autoscaling_cluster.aws
30 lines (22 loc) · 1.62 KB
/
ECS_autoscaling_cluster.aws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Title: ECS Autoscaling Cluster
# Tags: autoscaling, container, infra
# Description: Note that the AMI in this template is working only in eu-west-1 region
# MinimalVersion: v0.1.3
# First, create the ECS cluster with `awless create containercluster name={cluster.name}`.
# Then, create a policy to allow to connect to ECS
policy = create policy name=AWSEC2ContainerServiceforEC2Role effect=Allow resource="*" description="Access for ECS containers" action=[ecs:DeregisterContainerInstance,ecs:DiscoverPollEndpoint,ecs:Poll,ecs:RegisterContainerInstance,ecs:StartTelemetrySession,ecs:Submit*,ecr:GetAuthorizationToken,ecr:BatchCheckLayerAvailability,ecr:GetDownloadUrlForLayer,ecr:BatchGetImage,logs:CreateLogStream,logs:PutLogEvent]
# Set role name variable
roleName = AWSEC2ContainerServiceRole
# Create a AWS role that applies on a resource
create role name=$roleName principal-service="ec2.amazonaws.com" sleep-after=15
# Attach the policy to the role
attach policy arn=$policy role=$roleName
# Create the ECS instances launch configuration.
# The instances must be launched with a userdata file containing:
# ```sh
# #!/bin/bash
# echo ECS_CLUSTER=ecs-cluster-name >> /etc/ecs/ecs.config
# ```
launchconfig = create launchconfiguration image=ami-95f8d2f3 keypair={instance.keypair} name=ECSClusterLaunchconfig type={instance.type} userdata={instance.userdata} role=$roleName
# Create the scalinggroup
create scalinggroup desired-capacity={scalinggroup.desired-capacity} launchconfiguration=$launchconfig max-size={scalinggroup.desired-capacity} min-size={scalinggroup.desired-capacity} name=ecsClusterScalingGroup subnets={instance.subnets}