Metadata-Version: 2.1
Name: cdk-fargate-patterns
Version: 0.0.4
Summary: CDK patterns for serverless container with AWS Fargate
Home-page: https://github.com/pahud/cdk-fargate-patterns.git
Author: Pahud Hsieh<pahudnet@gmail.com>
License: Apache-2.0
Project-URL: Source, https://github.com/pahud/cdk-fargate-patterns.git
Description: [![NPM version](https://badge.fury.io/js/cdk-fargate-patterns.svg)](https://badge.fury.io/js/cdk-fargate-patterns)
        [![PyPI version](https://badge.fury.io/py/cdk-fargate-patterns.svg)](https://badge.fury.io/py/cdk-fargate-patterns)
        [![Release](https://github.com/pahud/cdk-fargate-patterns/actions/workflows/release.yml/badge.svg)](https://github.com/pahud/cdk-fargate-patterns/actions/workflows/release.yml)
        
        # cdk-fargate-patterns
        
        CDK patterns for serverless container with AWS Fargate
        
        # `DualAlbFargateService`
        
        Inspired by *Vijay Menon* from the [AWS blog post](https://aws.amazon.com/blogs/containers/how-to-use-multiple-load-balancer-target-group-support-for-amazon-ecs-to-access-internal-and-external-service-endpoint-using-the-same-dns-name/) introduced in 2019, `DualAlbFargateService` allows you to create one or many fargate services with both internet-facing ALB and internal ALB associated with all services. With this pattern, fargate services will be allowed to intercommunicat via internal ALB while external inbound traffic will be spread across the same service tasks through internet-facing ALB.
        
        The sample below will create 3 fargate services associated with both external and internal ALBs. The internal ALB will have an alias(`internal.svc.local`) auto-configured from Route 53 so services can communite through the private ALB endpoint.
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        DualAlbFargateService(stack, "Service",
            spot=True, # FARGATE_SPOT only cluster
            tasks=[{
                "listener_port": 80,
                "task": order_task,
                "desired_count": 2,
                # customize the service autoscaling policy
                "scaling_policy": {
                    "max_capacity": 20,
                    "request_per_target": 1000,
                    "target_cpu_utilization": 50
                }
            }, {"listener_port": 8080, "task": customer_task, "desired_count": 2}, {"listener_port": 9090, "task": product_task, "desired_count": 2}
            ],
            route53_ops={
                "zone_name": zone_name, # svc.local
                "external_alb_record_name": external_alb_record_name, # external.svc.local
                "internal_alb_record_name": internal_alb_record_name
            }
        )
        ```
        
        ## Fargate Spot Support
        
        By enabling the `spot` property, 100% fargate spot tasks will be provisioned to help you save up to 70%. Check more details about [Fargate Spot](https://aws.amazon.com/about-aws/whats-new/2019/12/aws-launches-fargate-spot-save-up-to-70-for-fault-tolerant-applications/?nc1=h_ls). This is a handy catch-all flag to force all tasks to be `FARGATE_SPOT` only.
        
        To specify mixed strategy with partial `FARGATE` and partial `FARGATE_SPOT`, specify the `capacityProviderStrategy` for individual tasks like
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        DualAlbFargateService(stack, "Service",
            tasks=[{
                "listener_port": 8080,
                "task": customer_task,
                "desired_count": 2,
                "capacity_provider_stretegy": [{
                    "capacity_provider": "FARGATE",
                    "base": 1,
                    "weight": 1
                }, {
                    "capacity_provider": "FARGATE_SPOT",
                    "base": 0,
                    "weight": 3
                }
                ]
            }
            ]
        )
        ```
        
        The custom capacity provider strategy will be applied if `capacityProviderStretegy` is specified, otherwise, 100% spot will be used when `spot: true`. The default policy is 100% Fargate on-demand.
        
        ## Sample Application
        
        This repository comes with a sample applicaiton with 3 services in Golang. On deployment, the `Order` service will be exposed externally on external ALB port `80` and all requests to the `Order` service will trigger sub-requests internally to another other two services(`product` and `customer`) through the internal ALB and eventually aggregate the response back to the client.
        
        ![](images/DualAlbFargateService.svg)
        
        ## Deploy
        
        To deploy the sample application in you default VPC:
        
        ```sh
        // compile the ts to js
        $ yarn build
        $ npx cdk --app lib/integ.default.js -c use_default_vpc=1 diff
        $ npx cdk --app lib/integ.default.js -c use_default_vpc=1 deploy
        ```
        
        On deployment complete, you will see the external ALB endpoint in the CDK output. `cURL` the external HTTP endpoint and you should be able to see the aggregated response.
        
        ```sh
        $ curl http://demo-Servi-EH1OINYDWDU9-1397122594.ap-northeast-1.elb.amazonaws.com
        
        {"service":"order", "version":"1.0"}
        {"service":"product","version":"1.0"}
        {"service":"customer","version":"1.0"}
        ```
        
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: JavaScript
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Typing :: Typed
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved
Requires-Python: >=3.6
Description-Content-Type: text/markdown
