Created
November 2, 2021 10:00
-
-
Save neilkuan/c8dd2288ef97e068e677bf35f7d20928 to your computer and use it in GitHub Desktop.
aws-cdk-fargate-windows-runtime.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ec2 from '@aws-cdk/aws-ec2'; | |
import * as ecs from '@aws-cdk/aws-ecs'; | |
import { App, Construct, Stack, StackProps } from '@aws-cdk/core'; | |
export class MyStack extends Stack { | |
constructor(scope: Construct, id: string, props: StackProps = {}) { | |
super(scope, id, props); | |
const vpc = ec2.Vpc.fromLookup(this, 'VPC', { isDefault: true }); | |
const cluster = new ecs.Cluster(this, 'Cluster', { | |
vpc, | |
enableFargateCapacityProviders: true, | |
}); | |
const taskdef = new ecs.TaskDefinition(this, 'TaskDef', { compatibility: ecs.Compatibility.FARGATE, memoryMiB: '2048', cpu: '1024' }); | |
taskdef.addContainer('Container', { | |
logging: ecs.LogDriver.awsLogs({ streamPrefix: 'win-iis-on-fargate' }), | |
portMappings: [{ containerPort: 80 }], | |
image: ecs.ContainerImage.fromRegistry('mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019'), | |
}); | |
(taskdef.node.defaultChild as ecs.CfnTaskDefinition).addPropertyOverride('RuntimePlatform', { | |
OperatingSystemFamily: 'WINDOWS_SERVER_2019_CORE', | |
}); | |
const fargateWindowsService = new ecs.FargateService(this, 'Service', { | |
taskDefinition: taskdef, | |
cluster, | |
assignPublicIp: true, | |
}); | |
ecs.WindowsOptimizedVersion.SERVER_2019; | |
fargateWindowsService.connections.allowFrom(ec2.Peer.ipv4(`${process.env.MYIP}/32`), ec2.Port.tcp(80)); | |
} | |
} | |
const devEnv = { | |
account: process.env.CDK_DEFAULT_ACCOUNT, | |
region: process.env.CDK_DEFAULT_REGION, | |
}; | |
const app = new App(); | |
new MyStack(app, 'my-stack-dev', { env: devEnv }); | |
app.synth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment