Fargate
This constructs creates a Fargate based infrastructure setup to be used in Statista AWS accounts. It can be used for general purpose application constructs and does not have opinions about the used tech in the application/containers.
Infrastructure
architecture-beta
group account(logos:aws)[Account]
group vpc(logos:aws-vpc)[VPC] in account
group sg1[ELB SecurityGroup] in vpc
group sg2[App SecurityGroup] in vpc
service cloud(cloud)[Internet]
service igw[Internet Gateway] in account
service nlb(logos:aws-elb)[Network LoadBalancer] in sg1
service app(logos:aws-fargate)[Application] in sg2
cloud:R --> L:igw
igw:R --> L:nlb
nlb:R --> L:app
The Internet Gateway and VPC in the AWS Account has to be setup outside of this construct.
Customization
To customize the created infrastructure the FargateApp app class can be
extended. All methods exposed could be overridden to adapt to specific needs.
Usage Example
Create a subclass for FargateApp and implement the getContainerImage method.
Then instantiate that subclass in your stack.
import { FargateApp } from '@pit-shared/cdk/fargate'
import * as ecs from 'aws-cdk-lib/aws-ecs'
declare const scope: import('aws-cdk-lib').Stack
class MyFargateApp extends FargateApp {
protected getContainerImage(): ecs.ContainerImage {
return ecs.ContainerImage.fromAsset('.')
}
}
new MyFargateApp(scope, 'fargate-app', {
dns: {
domainName: 'example.com',
hostedZoneId: '1234',
zoneName: 'example.com',
},
network: {
vpcId: 'vpc-1234567890abcdef0',
internetGatewayId: 'igw-1234',
},
})
API
The FargateApp construct does support the following properties:
/**
* Environment variables for the deployed application.
*/
environment?: Record<string, string | ecs.Secret>
/**
* Set if Datadog integration should be used.
*/
datadog?: Datadog
/**
* The log-group to use for all stack resources.
* If none is given a new log-group will be created.
*/
logGroup?: logs.ILogGroup
/**
* The cdn secret could be provided to have a stable secret across
* multiple regions or multiple applications.
* If it's not provided, a secret is randomly created for
* this CDK stack. If it is explicitly set to null, no cdn secret
* should be used.
*/
cdnSecret?: string | null
dns: {
/**
* The hosted zone id.
*/
hostedZoneId: string
/**
* The hosted zone name.
*/
zoneName: string
/**
* The domain name of the service.
*/
domainName: string
/**
* A certificate ARN to use for the domain. If none is provided, a new
* certificate will be created automatically.
*/
certificateArn?: string
/**
* The dns routing strategy.
*
* @default "geolocation"
*/
routingStrategy?: 'geolocation' | 'latency'
/**
* If true, the CNAME record will be skipped.
* This could be useful for multiregion deployments, where only one
* CNAME record must be created globally.
*
* @default false
*/
skipCName?: boolean
}
/**
* Network configuration for the fargate service
*/
network: FargateAppCommonNetworkProps &
(FargateAppPublicNetworkProps | FargateAppPrivateNetworkProps)
service?: {
/**
* The name of the ECS container (for display purposes).
* **Note:** It's not the name of the docker container to run.
*
* @default 'AppContainer'
*/
containerName?: string
/**
* The application port.
*/
port: number
/**
* The number of cpu units used by the task.
*
* @default 256
*/
cpu?: number
/**
* The amount (in MiB) of memory used by the task.
*
* @default 512
*/
memory?: number
/**
* The desired number of tasks to run.
*
* @default 1
*/
desiredCount?: number
/**
* the container health check configuration.
*/
healthCheck?: HealthCheck
}
Additional types
The network configuration is build from these types:
FargateAppCommonNetworkProps
/**
* An suffix for the load balancer target group name.
* If the name is changed, the target group is recreated. This
* could be used to unblock some deployments.
*/
loadBalancerTargetGroupId?: string
/**
* The VPC id.
*
* @default - Take the provided VPC from the account creation.
*/
vpcId?: string
FargateAppPrivateNetworkProps
/**
* The fargate service is not reachable from the internet.
*/
private: true
FargateAppPublicNetworkProps
/**
* The fargate service is reachable from the internet.
*/
private?: false
/**
* The internet gateway id.
*/
internetGatewayId: string