Skip to content

Commit

Permalink
Merge pull request #6 from kvrajesh/awslabs-ecs
Browse files Browse the repository at this point in the history
Awslabs ecs
  • Loading branch information
kvrajesh authored Oct 22, 2020
2 parents e1dfa0f + ea8ba78 commit 278419b
Show file tree
Hide file tree
Showing 40 changed files with 799 additions and 3,676 deletions.

This file was deleted.

5 changes: 2 additions & 3 deletions content/ecs-spot-capacity-providers/Introduction/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ title = "Introduction"
weight = 10
+++

Introduction to Docker Containers, Amazon ECS, EC2 Spot Instances and Application Scaling
---

This self-paced workshop is designed to educate engineers that might not be familiar with Fargate, ECS, EC2 Spot, and possibly even Docker container workflow.
If you're already familiar with the below concepts or already have experience with operating ECS clusters, you can skip the introduction and proceed to [**Setup the workshop environment on AWS**](/ecs-spot-capacity-providers/workshopsetup.html) section to start the workshop.


{{% children %}}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@ Why Containers?
Benefits of Containers
---

- Containers are powerful way for developers to package and deploy their applications. They are lightweight and provide a consistent, portable software environment for applications to easily run and scale anywhere. Building and deploying microservices, running batch jobs, for machine learning applications, and moving existing applications into the cloud are just some of the popular use cases for containers. Some other benefits of containers include:

Speed
---
- Workload Isolation
- Single artifact to test from local to production, avoid drift
- Containers are a powerful way for developers to package and deploy their applications. They are lightweight and provide a consistent, portable software environment for applications to easily run and scale anywhere. Building and deploying microservices, running batch jobs, for machine learning applications, and moving existing applications into the cloud are just some of the popular use cases for containers.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ weight = 15

An Amazon ECS cluster is a logical grouping of tasks or services.

If you are running tasks or services that use the EC2 launch type, a cluster is also a grouping of container instances.

If you are using capacity providers, a cluster is also a logical grouping of capacity providers.
A Cluster can be a combination of Fargate and EC2 launch types.
- If you are running tasks or services that use the EC2 launch type, a cluster is also a grouping of container instances.
- If you are using capacity providers, a cluster is also a logical grouping of capacity providers.
- A Cluster can be a combination of Fargate and EC2 launch types.

When you first use Amazon ECS, a default cluster is created for you, but you can create multiple clusters in an account to keep your resources separate.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+++
title = "Serverless Compute"
title = "Fargate"
weight = 35
+++

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ AWS Cloud Map is a cloud resource discovery service. With Cloud Map, you can def

Cloud Map natively integrates with ECS, and as we build services in the workshop, will see this firsthand. For more information on service discovery with ECS, please see [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-discovery.html).

![Service Discovery](/images/ecs-spot-capacity-providers/cloudmapproduct.png)
![Service Discovery](/images/ecs-spot-capacity-providers/cloudmapproduct.png)
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
+++
title = "Services, Relica, and Deamon"
title = "Services"
weight = 30
+++


Services
---

Amazon ECS allows you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. This is called a service. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it and maintain the desired count of tasks in the service depending on the scheduling strategy used.

In addition to maintaining the desired count of tasks in your service, you can optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service.
In addition to maintaining the desired count of tasks in your service, you can optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service.

There are two service scheduler strategies available:

Replica
-------
The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions. For more information, see [Replica](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html#service_scheduler_replica).
- REPLICA:
- The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions. For more information, see [Replica](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html#service_scheduler_replica).

Deamon
------
The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. The service scheduler evaluates the task placement constraints for running tasks and will stop tasks that do not meet the placement constraints. When using this strategy, there is no need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies. For more information, see [Daemon](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html#service_scheduler_daemon).
- DAEMON:
- The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. The service scheduler evaluates the task placement constraints for running tasks and will stop tasks that do not meet the placement constraints. When using this strategy, there is no need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies. For more information, see [Daemon](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html#service_scheduler_daemon).
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
+++
title = "Application Scaling-Infrastructure First Approach"
title = "Application Scaling"
weight = 20
+++


Its estimating how much compute capacity your application might need and provision server components based on it. In other words, your Infrastructure will start first before you application starts which is a notion we call - Infrastructure First. However this has few challenges.
Infrastructure first approach means estimating how much compute capacity your application might need and provision server components (EC2 Instances) based on it. In other words, your Infrastructure will start first before you application starts which is a notion we call - Infrastructure First. However, this has few challenges.

In the existing architecture with EC2 ASG used for ECS Cluster, you provision the infrastructure first (i.e. EC2 ASG) which will create instances (i.e. capacity) and then run your application services/tasks on this capacity using the EC2 Launch Type. In this case, running any task/service fails if there are no instances (zero capacity) in the ASG.
In the existing architecture with EC2 Auto Scaling groups used for your ECS Cluster, you provision the infrastructure first, which will create EC2 instances and then run (schedule) the ECS tasks on this capacity using the EC2 Launch Type. In this case, running any task/service fails if there are no instances (zero capacity) in the Auto Scaling group

1. ECS is unaware of the EC2 ASGs. So there is disconnect between the application tasks resource requirements and EC2 ASG scale out/in policies. The ASG scale out/in polices are based on the tasks or instances which are already running in that cluster and does not account for the new application tasks which needs to be scheduled. This means ASG custom scaling policies may not scale out/in well as per the application requirements.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
+++
title = "Amazon EC2 Spot Instances"
weight = 15
+++

[Amazon EC2 Spot Instances] (https://aws.amazon.com/ec2/spot/) offer spare compute capacity available in the AWS Cloud at steep discounts compared to On-Demand prices. EC2 can interrupt Spot Instances with two minutes of notification when EC2 needs the capacity back. You can use Spot Instances for various fault-tolerant and flexible applications. Some examples are analytics, containerized workloads, high-performance computing (HPC), stateless web servers, rendering, CI/CD, and other test and development workloads.

### Spot Instances in Containerized workloads


Many containerized workloads are usually stateless and fault tolerant and are great fit for running on EC2 Spot Instances. In this workshop we will explore how to run containers on interruptible EC2 Spot Instances and achieve significant cost savings.
24 changes: 10 additions & 14 deletions content/ecs-spot-capacity-providers/WorkshopSetup/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ Launch the CloudFormation stack

To save time on the initial setup, a CloudFormation template will be used to create the required resources needed for the workshop.

To create the stack

1. You can view and download the CloudFormation template from GitHub [here, Change location before making it live] (https://github.com/ec2-spot-workshops/workshops/ecs-spot-capacity-providers/ecs-spot-workshop-cfn.yaml).
2. Take a moment to review the CloudFormation template so you understand the resources it will be creating.
3. Browse to the [AWS CloudFormation console] (https://console.aws.amazon.com/cloudformation). Make sure you are in AWS Region designated by the facilitators of the workshop
3. Browse to the [AWS CloudFormation console] (https://console.aws.amazon.com/cloudformation). Make sure you are in AWS region designated by the facilitators of the workshop
4. Click *Create stack*.
5. In the *Specify template* section, select *Upload a template file*. Click *Choose file* and, select the template you downloaded in step 1.
6. Click *Next*.
Expand All @@ -35,19 +33,17 @@ The *Events* tab displays each major step in the creation of the stack sorted by
The *CREATE_IN_PROGRESS* event is logged when AWS CloudFormation reports that it has begun to create the resource. The *CREATE_COMPLETE* event is logged when the resource is successfully created.
When AWS CloudFormation has successfully created the stack, you will see the *CREATE_COMPLETE* event at the top of the Events tab:

Take a moment and checkout all the resources created by this stack.
Take a moment and check out all the resources created by this stack.

![Cloud Formation Stack](/images/ecs-spot-capacity-providers/stack1.png)

The Cloud formation creates the following Resources which we will be using later during the workshop.


* One VPC with 3 public and 3 private subnets
* Application Load Balancer (ALB) with its own security group
* Target Group(TG) and an ALB listener to forward the traffic to this TG
* IAM Role for Cloud 9 Environment
* Security Group for ECS Container Instance
* EC2 Launch Template with ECS optimized AMI and required ECS config in the user data section to bootstrap the instance
* ECR Repository
The CloudFormation template creates the following resources which we will be using later during the workshop.


* One VPC with 3 public and 3 private subnets.
* Application Load Balancer (ALB) with its own security group.
* Target Group (TG) and an ALB listener to forward the traffic to this TG.
* IAM Role for the Cloud9 Environment.
* Security Group for the ECS Container Instances.
* EC2 Launch Template configured with the ECS optimized AMI, and ECS bootstrapping configuration in the user data section to bootstrap the EC2 Instances into the ECS cluster.
* ECR Repository to host our containers.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ title: "Attach the IAM role to your Workspace"
weight: 10
---

Attach the IAM role for your Workspace
---

In order to work with ECS from our workstation, we will need the appropriate permissions for our developer workstation instance.
In order to work with ECS from our new Cloud9 IDE environment, we will need the appropriate permissions.

* Find your Cloud9 EC2 instance from [here] (https://console.aws.amazon.com/ec2/v2/home?#Instances)
* Find your Cloud9 EC2 instance [here] (https://console.aws.amazon.com/ec2/v2/home?#Instances)

* Select the instance, then choose Actions / Instance Settings / Attach/Replace IAM Role
* Select the instance, then choose Actions -> Instance Settings -> Attach/Replace IAM Role
* Choose **EcsSpotWorkshop-Cloud9InstanceProfile** from the *IAM Role* drop down, and select *Apply*

![Attach IAM Role](/images/ecs-spot-capacity-providers/c9_1.png)
Expand All @@ -29,13 +26,12 @@ Use the [GetCallerIdentity] (https://docs.aws.amazon.com/cli/latest/reference/st
aws sts get-caller-identity
```

The output assumed-role name should contain:
The output assumed-role name should contain the name of the role.

```
{
"UserId": "AROAQAHCJ2QPOAJPQADXV:i-0eedc304975256fac",
"Account": "0004746XXXXX",
"Arn": "arn:aws:sts::0004746XXXXX:assumed-role/EcsSpotWorkshop-Cloud9InstanceRole/i-0eedc304975256fac"
}
```

```
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ do
done
```

***Congratulations !!!*** Now you are done with workspace setup, Proceed to Module-1 of this workshop.
***Congratulations***, your Cloud9 workspace setup is complete, and you can proceed to next steps of this workshop.
14 changes: 6 additions & 8 deletions content/ecs-spot-capacity-providers/WorkshopSetup/workspace1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ weight: 5
---


If you are running the workshop on your own, the Cloud9 workspace should be built by an IAM user with Administrator privileges, not the root account user. Please ensure you are logged in as an IAM user, not the root account user.
If you are running the workshop on your own, the Cloud9 workspace should be built by an IAM user with Administrator privileges, not the root account user. Please ensure you are logged in as an IAM user.

We will create a Cloud9 environment first to execute all the commands needed for this workshop.

1. Login into AWS console with your account credentials
1. When working on AWS provided account your facilitator provides which Region to choose.
1. On your own AWS account, select any region of your choice
1. Select **Services** and type cloud9
1. Login into AWS console with your account credentials and choose the region where you deployed the CloudFormation template.
1. Select **Services** and type Cloud9
1. Select **Create environment**
1. Name it **ecsspotworkshop**. Click " **Next Step**", keep all other defaults and click " **Next Step**". keep all other defaults and click " **Create Environment**"
1. When it comes up, customize the environment by closing the **welcome tab** and **lower work area** , and opening a new **terminal** tab in the main work area:
1. If you like this theme, you can choose it yourself by selecting **View / Themes / Solarized / Solarized Dark** in the Cloud9 workspace menu.
1. Name it **ecsspotworkshop**. Click "**Next Step**", keep all other defaults and click "**Next Step**". Leep all other defaults and click "**Create Environment**"
1. When it comes up, customize the environment by closing the **welcome tab** and **lower work area**, and opening a new **terminal** tab in the main work area:
1. If you like the dark theme seen below, you can choose it yourself by selecting **View / Themes / Solarized / Solarized Dark** in the Cloud9 workspace menu.


#### Your workspace should now look like this:
Expand Down
8 changes: 4 additions & 4 deletions content/ecs-spot-capacity-providers/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ pre: "<b>⁃ </b>"

## Overview

Welcome! In this workshop you learn how to **cost optimize** running a sample container based web application, using Amazon ECS and EC2 Spot Instances.
Welcome! In this workshop you learn how to **cost optimize** your Amazon ECS clusters using EC2 Spot Instances.

The **learning objective** of this hands-on workshop is to help understand the different options to cost optimize container workloads running on **[Amazon ECS](https://aws.amazon.com/ecs/)** using **[EC2 Spot Instances](https://aws.amazon.com/ec2/spot/)** and **[Amazon Fargate Spot](https://aws.amazon.com/fargate/)**. This workshop covers topics such as ECS Cluster Auto scaling and how to use scale efficiently with **[Capacity Providers](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-capacity-providers.html)** to spread your tasks across a mix of resources, both on AWS Fargate and AWS Fargate Spot and EC2 OnDemand and Spot Instances.
The **learning objective** of this hands-on workshop is to help understand the different options to cost optimize container workloads running on **[Amazon ECS](https://aws.amazon.com/ecs/)** using **[EC2 Spot Instances](https://aws.amazon.com/ec2/spot/)** and **[Amazon Fargate Spot](https://aws.amazon.com/fargate/)**. This workshop covers topics such as ECS cluster auto scaling and how to scale efficiently with **[Capacity Providers](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-capacity-providers.html)** to spread your tasks across a mix of resources, both on AWS Fargate and AWS Fargate Spot as well as EC2 On-Demand and Spot Instances.

{{% children showhidden="false" %}}

{{% notice info %}}
The estimated time for completing the workshop is **90 to 120 minutes**. The estimated cost will be less than **$5**.
{{% /notice %}}

These labs are designed to be completed in sequence. If you are reading this at a live AWS event, the workshop attendants will give you a high level run down of the labs. Then it's up to you to follow the instructions below to complete the labs. Don't worry if you're embarking on this journey in the comfort of your office or home, this site contains all the materials for you'll need to complete this workshop.
The workshop is designed to be completed in sequence. If you are reading this at a live AWS event, the workshop attendants will give you a high level run down of the workshop. Then it's up to you to follow the instructions below to completion. Don't worry if you're embarking on this journey in the comfort of your office or home, this site contains all the materials for you'll need to complete this workshop.


### About Spot Instances in Containerized workloads

Many containerized workloads are usually stateless and fault tolerant and are great fit for running them on EC2 Spot. In this workshop we will explore how to run containers on interruptible EC2 Spot instances and save significantly compared to running them on EC2 On-Demand instances.
Many containerized workloads are usually stateless and fault tolerant and are great fit for running on EC2 Spot Instances. In this workshop we will explore how to run containers on interruptible EC2 Spot Instances and achieve significant cost savings.
Loading

0 comments on commit 278419b

Please sign in to comment.