cdk-fargate-fastautlscaler


Namecdk-fargate-fastautlscaler JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/aws-samples/aws-fargate-fast-autoscaler.git
SummaryA JSII construct lib to build AWS Fargate Fast Autoscaler
upload_time2020-08-08 05:32:15
maintainer
docs_urlNone
authorPahud Hsieh<hunhsieh@amazon.com>
requires_python>=3.6
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![NPM version](https://badge.fury.io/js/cdk-fargate-fastautlscaler.svg)](https://badge.fury.io/js/cdk-fargate-fastautlscaler)
[![PyPI version](https://badge.fury.io/py/cdk-fargate-fastautlscaler.svg)](https://badge.fury.io/py/cdk-fargate-fastautlscaler)
![Release](https://github.com/aws-samples/aws-fargate-fast-autoscaler/workflows/Release/badge.svg)

## aws-fargate-fast-autoscaler

**AWS Fargate Fast Autosaler** - A Serverless Implementation that Triggers your AWS Fargate autoscaling in seconds with `cdk-fargate-fastautlscaler`.

## cdk-fargate-fastautlscaler

`cdk-fargate-fastautlscaler` is a [aws/jsii](https://github.com/aws/jsii) construct library for AWS CDK.

By building your AWS CDK stacks with `cdk-fargate-fastautoscaler`, you can create your customized Fargate workload with the fast autoscaling capabilities.

![](images/fargate-fast-autoscaler.png)

# How it works

Behind the scene, our workload in PHP, NodeJS, Java or Python is running with a nginx reverse proxy within a single AWS Fargate Task exposing a `/nginx_status` endpoint for realtime connections info generation. All traffic coming through ALB to Fargate tasks will establish active connecitons with the nginx reverse proxy before it can hit our backend server.

We are running an AWS Step Function state machine to periodically invoke the AWS Lambda function and collect active connection numbers from each Fargate Task **every 3 seconds** and determine our scaling policy in the state machine followed by immediate `ecs service update` to increase the desired number of Fargate tasks.

# AWS CDK Sample

The following CDK sample creates a PHP service in AWS Fargate with the nginx as the reverse proxy.

```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.core as cdk
import aws_cdk.aws_ec2 as ec2
from aws_cdk.aws_ecs import AwsLogDriver, ContainerImage
from cdk_fargate_fastautlscaler import FargateFastAutoscaler
import path as path

app = cdk.App()

env = {
    "region": process.env.CDK_DEFAULT_REGION,
    "account": process.env.CDK_DEFAULT_ACCOUNT
}

stack = cdk.Stack(app, "FargateFastAutoscalerDemo", env=env)

vpc = ec2.Vpc.from_lookup(stack, "Vpc", is_default=True)

FargateFastAutoscaler(stack, "FargateFastAutoscaler",
    vpc=vpc,
    # create the backend PHP service
    backend_container={
        "image": ContainerImage.from_asset(path.join(__dirname, "../../sample/backend/php")),
        "cpu": 0,
        "logging": AwsLogDriver(
            stream_prefix="echo-http-req"
        )
    },
    # PHP service running on container port 2015
    backend_container_port_mapping=[{"container_port": 2015}
    ]
)
```

On deployment complete, you'll see the URL in the Outputs:

**fargate-fast-autoscaling.URL** = http://farga-exter-1GW64WGQYNE4O-1567742142.us-west-2.elb.amazonaws.com

Open this URL and you will see the Caddy web server welcome page with phpinfo.

![](images/php-welcome.png)

And if you append `/nginx_status` in the URL and reload the page, you'll see this page:

![](images/nginx-status.png)

### Start your state machine

Go to Step Function console and click **start execution** on the state machines. Leave the execution name and input column as is and click **start execution** again. Your state machine will be running. Behind the scene the step function will invoke a Lambda function to collect **Active Connections** number from nginx reverse proxy on each fargate task and determine a new desired number of fargate tasks to scale. Typically it would just take **less than 10 seconds** before it starts to scale.

![](images/stepfunc.png)

# SNS Service Integration

The **SNSScaleOut** task in the state machine leverages direct Amazon SNS service integration to publish a notification to your SNS topic. You will receive SNS notification when it starts **ServiceScaleOut** task.

Specify the `snsTopic` property to define your custom SNS topic. If not defined, the construct will create a default SNS topic.

# Disable Scale In

By default, `disableScaleIn` is set to true to prevent your workload from scale-in. If you prefer to enable scale in, set `disableScaleIn` to `false`.

## License Summary

This sample code is made available under the MIT-0 license. See the LICENSE file.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aws-samples/aws-fargate-fast-autoscaler.git",
    "name": "cdk-fargate-fastautlscaler",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Pahud Hsieh<hunhsieh@amazon.com>",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cc/80/a97cfe4db54773f0a7f01436d535c4f5b87fc4a26c12f0967e598d3c420d/cdk-fargate-fastautlscaler-0.1.2.tar.gz",
    "platform": "",
    "description": "[![NPM version](https://badge.fury.io/js/cdk-fargate-fastautlscaler.svg)](https://badge.fury.io/js/cdk-fargate-fastautlscaler)\n[![PyPI version](https://badge.fury.io/py/cdk-fargate-fastautlscaler.svg)](https://badge.fury.io/py/cdk-fargate-fastautlscaler)\n![Release](https://github.com/aws-samples/aws-fargate-fast-autoscaler/workflows/Release/badge.svg)\n\n## aws-fargate-fast-autoscaler\n\n**AWS Fargate Fast Autosaler** - A Serverless Implementation that Triggers your AWS Fargate autoscaling in seconds with `cdk-fargate-fastautlscaler`.\n\n## cdk-fargate-fastautlscaler\n\n`cdk-fargate-fastautlscaler` is a [aws/jsii](https://github.com/aws/jsii) construct library for AWS CDK.\n\nBy building your AWS CDK stacks with `cdk-fargate-fastautoscaler`, you can create your customized Fargate workload with the fast autoscaling capabilities.\n\n![](images/fargate-fast-autoscaler.png)\n\n# How it works\n\nBehind the scene, our workload in PHP, NodeJS, Java or Python is running with a nginx reverse proxy within a single AWS Fargate Task exposing a `/nginx_status` endpoint for realtime connections info generation. All traffic coming through ALB to Fargate tasks will establish active connecitons with the nginx reverse proxy before it can hit our backend server.\n\nWe are running an AWS Step Function state machine to periodically invoke the AWS Lambda function and collect active connection numbers from each Fargate Task **every 3 seconds** and determine our scaling policy in the state machine followed by immediate `ecs service update` to increase the desired number of Fargate tasks.\n\n# AWS CDK Sample\n\nThe following CDK sample creates a PHP service in AWS Fargate with the nginx as the reverse proxy.\n\n```python\n# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826\nimport aws_cdk.core as cdk\nimport aws_cdk.aws_ec2 as ec2\nfrom aws_cdk.aws_ecs import AwsLogDriver, ContainerImage\nfrom cdk_fargate_fastautlscaler import FargateFastAutoscaler\nimport path as path\n\napp = cdk.App()\n\nenv = {\n    \"region\": process.env.CDK_DEFAULT_REGION,\n    \"account\": process.env.CDK_DEFAULT_ACCOUNT\n}\n\nstack = cdk.Stack(app, \"FargateFastAutoscalerDemo\", env=env)\n\nvpc = ec2.Vpc.from_lookup(stack, \"Vpc\", is_default=True)\n\nFargateFastAutoscaler(stack, \"FargateFastAutoscaler\",\n    vpc=vpc,\n    # create the backend PHP service\n    backend_container={\n        \"image\": ContainerImage.from_asset(path.join(__dirname, \"../../sample/backend/php\")),\n        \"cpu\": 0,\n        \"logging\": AwsLogDriver(\n            stream_prefix=\"echo-http-req\"\n        )\n    },\n    # PHP service running on container port 2015\n    backend_container_port_mapping=[{\"container_port\": 2015}\n    ]\n)\n```\n\nOn deployment complete, you'll see the URL in the Outputs:\n\n**fargate-fast-autoscaling.URL** = http://farga-exter-1GW64WGQYNE4O-1567742142.us-west-2.elb.amazonaws.com\n\nOpen this URL and you will see the Caddy web server welcome page with phpinfo.\n\n![](images/php-welcome.png)\n\nAnd if you append `/nginx_status` in the URL and reload the page, you'll see this page:\n\n![](images/nginx-status.png)\n\n### Start your state machine\n\nGo to Step Function console and click **start execution** on the state machines. Leave the execution name and input column as is and click **start execution** again. Your state machine will be running. Behind the scene the step function will invoke a Lambda function to collect **Active Connections** number from nginx reverse proxy on each fargate task and determine a new desired number of fargate tasks to scale. Typically it would just take **less than 10 seconds** before it starts to scale.\n\n![](images/stepfunc.png)\n\n# SNS Service Integration\n\nThe **SNSScaleOut** task in the state machine leverages direct Amazon SNS service integration to publish a notification to your SNS topic. You will receive SNS notification when it starts **ServiceScaleOut** task.\n\nSpecify the `snsTopic` property to define your custom SNS topic. If not defined, the construct will create a default SNS topic.\n\n# Disable Scale In\n\nBy default, `disableScaleIn` is set to true to prevent your workload from scale-in. If you prefer to enable scale in, set `disableScaleIn` to `false`.\n\n## License Summary\n\nThis sample code is made available under the MIT-0 license. See the LICENSE file.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A JSII construct lib to build AWS Fargate Fast Autoscaler",
    "version": "0.1.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "5994deab951703b71f6b6aac4419d912",
                "sha256": "071e78fc9a165e1345e5480bfa2b4d628d872dcea938e279272003565960f0e0"
            },
            "downloads": -1,
            "filename": "cdk_fargate_fastautlscaler-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5994deab951703b71f6b6aac4419d912",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 36582,
            "upload_time": "2020-08-08T05:32:14",
            "upload_time_iso_8601": "2020-08-08T05:32:14.526523Z",
            "url": "https://files.pythonhosted.org/packages/dd/12/bc0ef91c9e7aeeb267517e3eceb0c2100ddb59825cca89e6757c4696e9bd/cdk_fargate_fastautlscaler-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "61aa09fc3e46a450e944b67e6d97ac6f",
                "sha256": "2be80f0b3d9498e1f4028a0ab0b4722d0ff2dd47093721ac289cc22fba95b386"
            },
            "downloads": -1,
            "filename": "cdk-fargate-fastautlscaler-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "61aa09fc3e46a450e944b67e6d97ac6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 37795,
            "upload_time": "2020-08-08T05:32:15",
            "upload_time_iso_8601": "2020-08-08T05:32:15.783998Z",
            "url": "https://files.pythonhosted.org/packages/cc/80/a97cfe4db54773f0a7f01436d535c4f5b87fc4a26c12f0967e598d3c420d/cdk-fargate-fastautlscaler-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-08 05:32:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "aws-samples",
    "error": "Could not fetch GitHub repository",
    "lcname": "cdk-fargate-fastautlscaler"
}
        
Elapsed time: 0.11383s