CDK patterns for serverless container with AWS Fargate
Project description
cdk-fargate-patterns
CDK patterns for serverless container with AWS Fargate
DualAlbFargateService
Inspired by Vijay Menon from the AWS blog post 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.
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
Built Distribution
Hashes for cdk-fargate-patterns-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09b9703668080aa9b53accb75ccf821a3585cf0a5c30ede444af4ce01d486983 |
|
MD5 | 58046875c889901a612bbf435ffd9613 |
|
BLAKE2b-256 | 87d41b845a670ebc1905d2249667bf1520167330ec1b03b2a780f08f386a436a |
Hashes for cdk_fargate_patterns-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc15634ab6b3c36089ff6b2df59f0b5895951f84019c2062c98e11668086472 |
|
MD5 | dfc3eefafdf02d263e97f6e697b0dd09 |
|
BLAKE2b-256 | ede4f7d58a60ab311674bb530c4939fb6a6327c897b5ea9a7c930172aa75629a |