0.0.109 • Published 5 days ago

low-cost-ecs v0.0.109

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

NPM version PyPI version Release

Low-Cost ECS

A CDK construct that provides an easy and low-cost ECS on EC2 server setup without a load balancer.

Why

ECS may often seem expensive when used for personal development purposes, due to the cost of the load balancer. The application load balancer is a great service that is easy to set up managed ACM certificates, easy scaling, and has dynamic port mappings..., but it is over-featured for running 1 ECS task.

However, to run an ECS server without a load balancer, you need to associate an Elastic IP to the host instance and install your certificate to your service every time you start up the server. This construct aims to automate these works and make it easy to deploy resources to run a low-cost ECS server.

Try it out!

The easiest way to try the construct is to clone this repository and deploy the sample Nginx server. Edit settings in examples/minimum.ts and deploy the cdk construct. Public hosted zone is required.

  1. Clone and install packages
git clone https://github.com/rajyan/low-cost-ecs.git
yarn install
  1. Edit email and domain in example.ts https://github.com/rajyan/low-cost-ecs/blob/3d1bbf7ef4b59d0f4e9d3cd9cb90584977b71c0a/examples/minimum.ts#L1-L15

  2. Deploy!

cdk deploy

Access the configured hostedZoneDomain and see that the sample Nginx server has been deployed.

Installation

To use this construct in your cdk stack as a library,

npm install low-cost-ecs
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { LowCostECS } from 'low-cost-ecs';

class SampleStack extends Stack {
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);

        const vpc = { /** Your VPC */ };
        const securityGroup = { /** Your security group */ };
        const serverTaskDefinition = { /** Your task definition */ };

        new LowCostECS(this, 'LowCostECS', {
            hostedZoneDomain: "example.com",
            email: "test@example.com",
            vpc: vpc,
            securityGroup: securityGroup,
            serverTaskDefinition: serverTaskDefinition
        });
    }
}

The required fields are hostedZoneDomain and email. You can configure your server task definition and other props. Read LowCostECSProps documentation for details.

Overview

Resources generated in this stack

  • Route53 A record
    • Forwarding to host instance Elastic IP
  • Certificate State Machine
    • Install and renew certificates to EFS using certbot-dns-route53
    • Scheduled automated renewal every 60 days
    • Email notification on certbot task failure
  • ECS on EC2 host instance
    • ECS-optimized Amazon Linux 2 AMI instance auto-scaling group
    • Automatically associated with Elastic IP on instance initialization
  • ECS Service
    • TLS/SSL certificate installation before default container startup
    • Certificate EFS mounted on default container as /etc/letsencrypt
  • Others
    • VPC with only public subnets (no NAT Gateways to decrease cost)
    • Security groups with minimum inbounds
    • IAM roles with minimum privileges

Cost

All resources except Route53 HostedZone should be included in AWS Free Tier if you are in the 12 Months Free period. After your 12 Months Free period, setting hostInstanceSpotPrice to use spot instances is recommended.

  • EC2
    • t2.micro 750 instance hours (12 Months Free Tier)
    • 30GB EBS volume (12 Months Free Tier)
  • ECS
    • No additional charge because using ECS on EC2
  • EFS
    • Usage is very small, it should be free
  • Cloud Watch
    • Usage is very small, and it should be included in the free tier
    • Enabling containerInsights will charge for custom metrics

Debugging

  • SSM Session Manager

SSM manager is pre-installed in the host instance (by ECS-optimized Amazon Linux 2 AMI) and AmazonSSMManagedInstanceCore is added to the host instance role to access and debug in your host instance.

aws ssm start-session --target $INSTANCE_ID
  • ECS Exec

Service ECS Exec is enabled, so execute commands can be used to debug your server task container.

aws ecs execute-command \
--cluster $CLUSTER_ID \
--task $TASK_ID \
--container nginx \
--command bash \
--interactive

Limitations

Because the ECS service occupies a host port, only one task can be executed at a time. The old task must be terminated before the new task launches, and this causes downtime on release.

Also, if you make changes that require recreating the service, you may need to manually terminate the task of the old service.

0.0.109

5 days ago

0.0.108

12 days ago

0.0.107

18 days ago

0.0.106

25 days ago

0.0.105

1 month ago

0.0.104

1 month ago

0.0.103

2 months ago

0.0.102

2 months ago

0.0.101

2 months ago

0.0.100

2 months ago

0.0.99

2 months ago

0.0.98

3 months ago

0.0.97

3 months ago

0.0.96

3 months ago

0.0.95

4 months ago

0.0.94

4 months ago

0.0.93

4 months ago

0.0.92

4 months ago

0.0.91

5 months ago

0.0.90

5 months ago

0.0.87

6 months ago

0.0.88

6 months ago

0.0.89

5 months ago

0.0.84

6 months ago

0.0.85

6 months ago

0.0.86

6 months ago

0.0.80

7 months ago

0.0.81

7 months ago

0.0.82

7 months ago

0.0.83

7 months ago

0.0.78

8 months ago

0.0.79

8 months ago

0.0.76

8 months ago

0.0.77

8 months ago

0.0.73

9 months ago

0.0.74

9 months ago

0.0.75

9 months ago

0.0.70

9 months ago

0.0.71

9 months ago

0.0.72

9 months ago

0.0.62

11 months ago

0.0.63

11 months ago

0.0.64

11 months ago

0.0.65

11 months ago

0.0.66

10 months ago

0.0.67

10 months ago

0.0.68

10 months ago

0.0.69

10 months ago

0.0.60

12 months ago

0.0.61

12 months ago

0.0.59

12 months ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.58

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago