Skip to main content

CDK patterns for serverless container with AWS Fargate

Project description

NPM version PyPI version Release

cdk-fargate-patterns

CDK patterns for serverless container with AWS Fargate

DualAlbFargateService

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.

By enabling the spot property, you will provision spot-only fargate tasks to help you save up to 70%. Check more details about Fargate Spot.

# 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
    }
)

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.

Deploy

To deploy the sample application in you default VPC:

// 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.

$ 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"}

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-fargate-patterns-0.0.1.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_fargate_patterns-0.0.1-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file cdk-fargate-patterns-0.0.1.tar.gz.

File metadata

  • Download URL: cdk-fargate-patterns-0.0.1.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9

File hashes

Hashes for cdk-fargate-patterns-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f19fea11f16b266bfa103f66335656f43e0af6e643e59f3eb964fab4dbc36ab0
MD5 5f9fca754831d9502e18fad1c8728f2f
BLAKE2b-256 b046ce740ae3ee26395e88e6bddf1c09b8bad2ac1e657175a7add0a272b617da

See more details on using hashes here.

File details

Details for the file cdk_fargate_patterns-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cdk_fargate_patterns-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9

File hashes

Hashes for cdk_fargate_patterns-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41092aab6c4206d9413a396fc1ed4bc85e19834a744c61fa79a2ce8d19157f04
MD5 ea26d479653ae8acf1ba3119aacf2542
BLAKE2b-256 e9cdc9a9773361520f6339e63cdc1ec775445deef4ec85f9e2d9d775266e7eac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page