Firstly install and configure both the AWSCLI and ECSCLI.
For the examples below ecs
is the [options]
argument after the aws
command. It instructs aws
to run the command for Elastic Container Services
. Any commands that point to a .json
configuration file are available on github.
Detailed help for both EC2 (Elastic Compute Cloud) and ECS (Elastic Container Service) can be found at the links below:
- https://docs.aws.amazon.com/cli/latest/reference/ec2/index.html
- https://docs.aws.amazon.com/cli/latest/reference/ecs/index.html
You can dump the result if any command to a text file which is useful with the describe
commands. Single >
will overwrite the file and >>
will append. Example:
1 | C:\> aws ecr list-images --repository-name lexicon-webmvc > output.txt |
ECR - Elastic Container Registry
1 | aws ecr list-images --repository-name lexicon-webmvc |
- https://docs.aws.amazon.com/cli/latest/reference/ecr/list-images.html
- ECR CLI commands are listed here in context of the lexicon project.
Task Definitions
Example task definition ARN : arn:aws:ecs:ap-southeast-2:000000000000:task-definition/lexicon-task-definition:3
1 | aws ecs list-task-definitions --region ap-southeast-2 --status INACTIVE |
You CANNOT DELETE task definitions they have to be only deregistered if you no longer want them.
1 | aws ecs deregister-task-definition --task-definition TASK-NAME |
Register new from local .json
file. If you use an existing name it will create a new revision of the task definition. The name is defined in the .json
in the family
parameter.
1 | aws ecs register-task-definition --cli-input-json file://lexicon-task-definition.json --region ap-southeast-2 |
VPC - Virtual Private Cloud
1 | aws ec2 describe-vpcs |
The above will create your VPC along with a Route Table
, DHCP options set
, Network ACLs
and Security Groups
EC2 Instance
EC2 (Amazon Elastic Compute Cloud) is the virtual machine running in the cloud, this is a Linux variant running the Amazon Linux AMI 2.0.20190913 x86_64 ECS HVM
- where AMI stands for Amazon Machine Images
Terminated instances remain visible after termination (for approximately one hour).
1 | ~ Descibes the virtual machine instance |
- https://docs.aws.amazon.com/cli/latest/reference/ec2/terminate-instances.html
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html
To create a launch template
1 | ~ display existing launch templates |
- https://docs.aws.amazon.com/cli/latest/reference/ec2/create-launch-template.html
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html?icmpid=docs_ec2_console
- https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RequestLaunchTemplateData.html
To run instances
1 | aws ec2 run-instances --launch-template LaunchTemplateId=lt-0daef39547692deac |
- https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html
- https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-instances.html#launching-instances
Security Groups
This is used to open up ports, example allowing you to connect to SQL from SQL Server Management Studio on port 1433. The example below opens port 80.
1 | aws ec2 describe-security-groups --filters Name=vpc-id,Values=VPC_ID --region ap-southeast-2 |
Subnets
1 | aws ec2 create-subnet --generate-cli-skeleton |
Clusters
Example cluster ARN: arn:aws:ecs:ap-southeast-2:000000000000:cluster/lexicon-cluster
1 | aws ecs list-clusters |
Service
Start from task definition and keep it running.
1 | aws ecs list-services --cluster lexicon-cluster |
Tasks
1 | aws ecs run-task --task-definition lexicon-task-definition:6 --cluster lexicon-cluster |
Tags
Assign metadata to AWS resources, this is a array of key|value
so you can allocate infrastructure resources.
1 | aws ecs list-tags-for-resource --resource-arn |