Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cdk-fargate-cn.ts
import cdk = require('@aws-cdk/core');
import { Vpc } from '@aws-cdk/aws-ec2';
import { Cluster, ContainerImage, TaskDefinition, Compatibility } from '@aws-cdk/aws-ecs';
import { ApplicationLoadBalancedFargateService } from '@aws-cdk/aws-ecs-patterns';
import path = require('path')
export class FargateAlbSvcStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = Vpc.fromLookup(this, 'VPC', {
isDefault: true
})
const cluster = new Cluster(this, 'Cluster', {
vpc
})
const taskDefinition = new TaskDefinition(this, 'Task', {
compatibility: Compatibility.FARGATE,
memoryMiB: '512',
cpu: '256'
})
taskDefinition
.addContainer('flask', {
image: ContainerImage.fromRegistry('pahud/amazon-ecs-flask-sample'),
// image: ContainerImage.fromAsset(path.join(__dirname, '../../python/flask-docker-app/')),
environment: {
'PLATFORM': `AWS Fargate(${this.region})`
}
})
.addPortMappings({
containerPort: 5000
})
const svc = new ApplicationLoadBalancedFargateService(this, 'FargateService', {
cluster,
taskDefinition
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment