- Specify Cluster configuration
- Cluster Name : Java-cluster
- EC2 instance type : m5.large
- Number of instances : 2
- Key Pair : select your key pair
-
VPC : default VPC
-
Subnets : Select 2 subnets
-
Security Group : Create a new security Group OPEN ALL PORT , it is very important
-
Role : Select a EC2 instance role to support your Task (need to create a new role)
-
Need to Open all port in Security group, for dynamic port mapping of ALB
- Create a Resources if you have error on creating IAM Role for instance, then create a role for ECS Instance Role and execute it again.
- Create a ALB
- Specify name : -alb-ecs-cluster
- Select the VPC which ECR is running on :
- Select all AZs
- Create a security group
- Speficy name : -alb-sg-default
- Open all TCP
- Configure a default target group
- Specify name : --alb-ecs-cluster-default-tg
- Select Instance as target type
- Skip target registration Don't register target instances here.
- Specify information
-
Task Definition Name : -psy-contianer-task-hello
-
Task Role : Creat a Amazon Elastic Container Service Task Role in IAM Role
-
Network Mode : Bridge
-
Task memory (MiB) : 512
-
Task CPU (unit) : 1 vcpu
- Specify container information
- Container name : java-container
- Image : (for example, .dkr.ecr.ap-southeast-1.amazonaws.com/java-workshop )
- Memory Limits (MiB) : 128
- Port mapping : 0 : 8080
- important !!! you need to specify host port as empty
- Create a Task Check a created task
- Configure service
-
Task Definition : Select a task you created in task definition (-psy-container-task-hello)
-
Cluster : select the cluster (container-workshop)
-
Service name : java-service
-
Number of tasks : 1
-
Minimum healthy percent : 50
-
Maximum percent : 200
-
Placement Templates : AZ Balanced spread
- Configure network
- Select a ALB you crated
- Specify Listner port : 80 HTTP
- Select "Create New" as target group name
- Specify Path pattern : /
- Specify Evaluation Order : 1
- Cofigure autoscaling
- None
- Specify Path Pattern : /workshop/users*
- Add ALB target group
- Add health Check : /workshop/users/all
Use : https://github.com/aws-samples/ecs-refarch-cloudformation
Lauch a whole stack. and test it(see output of CloudFormation)
- (Recommendataion) download a zip file from https://github.com/aws-asean-builders/aws-container-workshop/tree/master/lab-03/cloudformation/original
and Unzip it.
- (Optional) Clone the forked GitHub repository to your local machine.
git clone https://github.com/aws-samples/ecs-refarch-cloudformation.git
- Modify the templates.
- Upload them to an Amazon S3 bucket of your choice. Upload master.yml, template, service foders
-
master.yml
+- infrastructure/*
+- services/*
-
Either create a new CloudFormation stack by deploying the master.yaml template, or update your existing stack with your version of the templates.
-
Change master.yml to point out your file location.
- Install ecs-cli : https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI_installation.html
Create an ECS cluster with these resources:
- Create a infrastructure using Cloudformation
- Use templates/infra.yaml
cd templates
aws cloudformation deploy \
--stack-name aws-infra-ecscli \
--template-file infra.yaml \
--region ap-southeast-1 \
--capabilities CAPABILITY_IAM
aws cloudformation deploy \
--stack-name aws-ecs-ec2 \
--template-file master.yaml \
--region ap-southeast-1 \
--capabilities CAPABILITY_IAM
- Run the follow command to capture the output from the CloudFormation template as key/value pairs in the file ecs-cluster.props.
aws cloudformation describe-stacks \
--region ap-southeast-1 \
--stack-name aws-infra-ecscli \
--query 'Stacks[0].Outputs' \
--output=text | \
perl -lpe 's/\s+/=/g' | \
tee ecs-cluster.props
- Setup the environment variables using the file (ecs-cluster.props)
set -o allexport
source ecs-cluster.props
set +o allexport
- Configure ECS CLI
ecs-cli configure --cluster $ECSCluster --region ap-southeast-1
- Create the task definition parameters for each of the service:
ecs-params-create.sh greeting
- Start the greeting service up:
ecs-cli compose --verbose \
--file greeting-docker-compose.yaml \
--task-role-arn $ECSRole \
--ecs-params ecs-params_greeting.yaml \
--project-name greeting \
service up \
--target-group-arn $GreetingTargetGroupArn \
--container-name greeting-service \
--container-port 8081