14 |
19 | @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
20 |
21 |
22 |
23 |
@Html.ActionLink("Home", "Index", "Home")
24 |
@Html.ActionLink("About", "About", "Home")
25 |
@Html.ActionLink("Contact", "Contact", "Home")
26 |
27 |
28 |
29 |
30 |
31 | @RenderBody()
32 |
33 |
36 |
37 |
38 | @Scripts.Render("~/bundles/jquery")
39 | @Scripts.Render("~/bundles/bootstrap")
40 | @RenderSection("scripts", required: false)
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/Views/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "~/Views/Shared/_Layout.cshtml";
3 | }
4 |
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/AWSECSSample/AWSECSSample/favicon.ico
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/AWSECSSample/AWSECSSample/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/AWSECSSample/AWSECSSample/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/AWSECSSample/AWSECSSample/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/AWSECSSample/AWSECSSample/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/AWSECSSample/docker-compose.ci.build.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
--------------------------------------------------------------------------------
/AWSECSSample/docker-compose.dcproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | bf9890bf-074b-4198-9400-68e460bbf0c0
5 | True
6 | http://{ServiceIPAddress}
7 | awsecssample
8 | Windows
9 | 2.0
10 |
11 |
12 |
13 |
14 | docker-compose.yml
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/AWSECSSample/docker-compose.override.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 | awsecssample:
5 | ports:
6 | - "80"
7 | networks:
8 | default:
9 | external:
10 | name: nat
11 |
--------------------------------------------------------------------------------
/AWSECSSample/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 | awsecssample:
5 | image: awsecssample
6 | build:
7 | context: .\AWSECSSample
8 | dockerfile: Dockerfile
9 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check [existing open](https://github.com/aws-samples/aws-ecs-windows-aspnet/issues), or [recently closed](https://github.com/aws-samples/aws-ecs-windows-aspnet/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *master* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws-samples/aws-ecs-windows-aspnet/labels/help%20wanted) issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50 | opensource-codeofconduct@amazon.com with any additional questions or comments.
51 |
52 |
53 | ## Licensing
54 |
55 | See the [LICENSE](https://github.com/aws-samples/aws-ecs-windows-aspnet/blob/master/LICENSE) file for our project's licensing. We will ask you confirm the licensing of your contribution.
56 |
57 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
58 |
--------------------------------------------------------------------------------
/Cloudformation template/aspnetwincontainer.json:
--------------------------------------------------------------------------------
1 | {
2 | "AWSTemplateFormatVersion": "2010-09-09",
3 | "Parameters": {
4 | "KeyName": {
5 | "Type": "AWS::EC2::KeyPair::KeyName",
6 | "Description": "Name of an existing EC2 key pair to enable SSH access to the ECS instances."
7 | },
8 | "VpcId": {
9 | "Type": "AWS::EC2::VPC::Id",
10 | "Description": "Select a default VPC ID."
11 | },
12 | "SubnetID": {
13 | "Type": "List",
14 | "Description": "Select a default subnet ID in your selected VPC."
15 | },
16 | "AppName": {
17 | "Type": "String",
18 | "Description": "Select the ECS Application Name.",
19 | "Default": "awsecssample"
20 | },
21 | "ECSImageName": {
22 | "Type": "String",
23 | "Description": "Select the image uploaded in AWS ECR."
24 | },
25 | "DesiredCapacity": {
26 | "Type": "Number",
27 | "Default": "3",
28 | "Description": "Number of instances to launch in your ECS cluster."
29 | },
30 | "MaxSize": {
31 | "Type": "Number",
32 | "Default": "4",
33 | "Description": "Maximum number of instances that can be launched in your ECS cluster."
34 | },
35 | "InstanceType": {
36 | "Description": "EC2 instance type",
37 | "Type": "String",
38 | "Default": "t2.micro",
39 | "AllowedValues": [
40 | "t2.micro",
41 | "t2.small",
42 | "t2.medium",
43 | "t2.large",
44 | "m3.medium",
45 | "m3.large",
46 | "m3.xlarge",
47 | "m3.2xlarge",
48 | "m4.large",
49 | "m4.xlarge",
50 | "m4.2xlarge",
51 | "m4.4xlarge",
52 | "m4.10xlarge",
53 | "c4.large",
54 | "c4.xlarge",
55 | "c4.2xlarge",
56 | "c4.4xlarge",
57 | "c4.8xlarge",
58 | "c3.large",
59 | "c3.xlarge",
60 | "c3.2xlarge",
61 | "c3.4xlarge",
62 | "c3.8xlarge",
63 | "r3.large",
64 | "r3.xlarge",
65 | "r3.2xlarge",
66 | "r3.4xlarge",
67 | "r3.8xlarge",
68 | "i2.xlarge",
69 | "i2.2xlarge",
70 | "i2.4xlarge",
71 | "i2.8xlarge"
72 | ],
73 | "ConstraintDescription": "Please choose a valid instance type."
74 | }
75 | },
76 | "Mappings": {
77 | "AWSRegionToAMI": {
78 | "us-east-2": {
79 | "AMIID": "ami-b19fb1d4"
80 | },
81 | "us-east-1": {
82 | "AMIID": "ami-9f1182e5"
83 | },
84 | "us-west-2": {
85 | "AMIID": "ami-0b60bc73"
86 | },
87 | "us-west-1": {
88 | "AMIID": "ami-a8003bc8"
89 | },
90 | "eu-west-2": {
91 | "AMIID": "ami-3da4bb59"
92 | },
93 | "eu-west-1": {
94 | "AMIID": "ami-94d360ed"
95 | },
96 | "eu-central-1": {
97 | "AMIID": "ami-b4ed61db"
98 | },
99 | "ap-northeast-2": {
100 | "AMIID": "ami-bb3691d5"
101 | },
102 | "ap-northeast-1": {
103 | "AMIID": "ami-5ed66f38"
104 | },
105 | "ap-southeast-2": {
106 | "AMIID": "ami-918075f3"
107 | },
108 | "ap-southeast-1": {
109 | "AMIID": "ami-ec32618f"
110 | },
111 | "ca-central-1": {
112 | "AMIID": "ami-2859e24c"
113 | }
114 | }
115 | },
116 | "Resources": {
117 | "EcsSecurityGroup": {
118 | "Type": "AWS::EC2::SecurityGroup",
119 | "Properties": {
120 | "GroupDescription": "ECS Security Group",
121 | "VpcId": {
122 | "Ref": "VpcId"
123 | }
124 | }
125 | },
126 | "EcsSecurityGroupHTTPinbound": {
127 | "Type": "AWS::EC2::SecurityGroupIngress",
128 | "Properties": {
129 | "GroupId": {
130 | "Ref": "EcsSecurityGroup"
131 | },
132 | "IpProtocol": "tcp",
133 | "FromPort": "80",
134 | "ToPort": "80",
135 | "CidrIp": "0.0.0.0/0"
136 | }
137 | },
138 | "EcsSecurityGroupRDPinbound": {
139 | "Type": "AWS::EC2::SecurityGroupIngress",
140 | "Properties": {
141 | "GroupId": {
142 | "Ref": "EcsSecurityGroup"
143 | },
144 | "IpProtocol": "tcp",
145 | "FromPort": "3389",
146 | "ToPort": "3389",
147 | "CidrIp": "0.0.0.0/0"
148 | }
149 | },
150 | "EcsSecurityGroupALBports": {
151 | "Type": "AWS::EC2::SecurityGroupIngress",
152 | "Properties": {
153 | "GroupId": {
154 | "Ref": "EcsSecurityGroup"
155 | },
156 | "IpProtocol": "tcp",
157 | "FromPort": "31000",
158 | "ToPort": "61000",
159 | "SourceSecurityGroupId": {
160 | "Ref": "EcsSecurityGroup"
161 | }
162 | }
163 | },
164 | "ECSCluster": {
165 | "Type": "AWS::ECS::Cluster"
166 | },
167 | "CloudwatchLogsGroup": {
168 | "Type": "AWS::Logs::LogGroup",
169 | "Properties": {
170 | "LogGroupName": {
171 | "Fn::Join": [
172 | "-", [
173 | "ECSLogGroup",
174 | {
175 | "Ref": "AWS::StackName"
176 | }
177 | ]
178 | ]
179 | },
180 | "RetentionInDays": 14
181 | }
182 | },
183 | "taskdefinition": {
184 | "Type": "AWS::ECS::TaskDefinition",
185 | "Properties": {
186 | "ContainerDefinitions": [{
187 | "Name": {
188 | "Ref" : "AppName"
189 | },
190 | "Cpu": "200",
191 | "Essential": "true",
192 | "Image": {
193 | "Ref" : "ECSImageName"
194 | },
195 | "Memory": "2048",
196 | "LogConfiguration": {
197 | "LogDriver": "awslogs",
198 | "Options": {
199 | "awslogs-group": {
200 | "Ref": "CloudwatchLogsGroup"
201 | },
202 | "awslogs-region": {
203 | "Ref": "AWS::Region"
204 | },
205 | "awslogs-stream-prefix": {
206 | "Ref" : "AppName"
207 | }
208 | }
209 | },
210 | "PortMappings": [{
211 | "ContainerPort": 80
212 | }]
213 | }]
214 | }
215 | },
216 | "ECSALB": {
217 | "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
218 | "Properties": {
219 | "Name": "ECSALB",
220 | "Scheme": "internet-facing",
221 | "LoadBalancerAttributes": [{
222 | "Key": "idle_timeout.timeout_seconds",
223 | "Value": "30"
224 | }],
225 | "Subnets": {
226 | "Ref": "SubnetID"
227 | },
228 | "SecurityGroups": [{
229 | "Ref": "EcsSecurityGroup"
230 | }]
231 | }
232 | },
233 | "ALBListener": {
234 | "Type": "AWS::ElasticLoadBalancingV2::Listener",
235 | "DependsOn": "ECSServiceRole",
236 | "Properties": {
237 | "DefaultActions": [{
238 | "Type": "forward",
239 | "TargetGroupArn": {
240 | "Ref": "ECSTargetGroup"
241 | }
242 | }],
243 | "LoadBalancerArn": {
244 | "Ref": "ECSALB"
245 | },
246 | "Port": "80",
247 | "Protocol": "HTTP"
248 | }
249 | },
250 | "ECSALBListenerRule": {
251 | "Type": "AWS::ElasticLoadBalancingV2::ListenerRule",
252 | "DependsOn": "ALBListener",
253 | "Properties": {
254 | "Actions": [{
255 | "Type": "forward",
256 | "TargetGroupArn": {
257 | "Ref": "ECSTargetGroup"
258 | }
259 | }],
260 | "Conditions": [{
261 | "Field": "path-pattern",
262 | "Values": [
263 | "/"
264 | ]
265 | }],
266 | "ListenerArn": {
267 | "Ref": "ALBListener"
268 | },
269 | "Priority": 1
270 | }
271 | },
272 | "ECSTargetGroup": {
273 | "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
274 | "DependsOn": "ECSALB",
275 | "Properties": {
276 | "HealthCheckIntervalSeconds": 300,
277 | "HealthCheckPath": "/",
278 | "HealthCheckProtocol": "HTTP",
279 | "HealthCheckTimeoutSeconds": 5,
280 | "HealthyThresholdCount": 2,
281 | "Name": "ECSTargetGroup",
282 | "Port": 80,
283 | "Protocol": "HTTP",
284 | "UnhealthyThresholdCount": 2,
285 | "VpcId": {
286 | "Ref": "VpcId"
287 | }
288 | }
289 | },
290 | "ECSAutoScalingGroup": {
291 | "Type": "AWS::AutoScaling::AutoScalingGroup",
292 | "Properties": {
293 | "VPCZoneIdentifier": {
294 | "Ref": "SubnetID"
295 | },
296 | "LaunchConfigurationName": {
297 | "Ref": "ContainerInstances"
298 | },
299 | "MinSize": "3",
300 | "MaxSize": {
301 | "Ref": "MaxSize"
302 | },
303 | "DesiredCapacity": {
304 | "Ref": "DesiredCapacity"
305 | }
306 | },
307 | "CreationPolicy": {
308 | "ResourceSignal": {
309 | "Timeout": "PT15M"
310 | }
311 | },
312 | "UpdatePolicy": {
313 | "AutoScalingRollingUpdate": {
314 | "MinInstancesInService": "1",
315 | "MaxBatchSize": "1",
316 | "PauseTime": "PT15M",
317 | "WaitOnResourceSignals": "true"
318 | }
319 | }
320 | },
321 | "ContainerInstances": {
322 | "Type": "AWS::AutoScaling::LaunchConfiguration",
323 | "Metadata": {
324 | "AWS::CloudFormation::Init": {
325 | "config": {
326 | "files": {
327 | "c:\\cfn\\cfn-hup.conf": {
328 | "content": {
329 | "Fn::Join": [
330 | "", [
331 | "[main]\n",
332 | "stack=",
333 | {
334 | "Ref": "AWS::StackId"
335 | },
336 | "\n",
337 | "region=",
338 | {
339 | "Ref": "AWS::Region"
340 | },
341 | "\n"
342 | ]
343 | ]
344 | }
345 | },
346 | "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf": {
347 | "content": {
348 | "Fn::Join": [
349 | "", [
350 | "[cfn-auto-reloader-hook]\n",
351 | "triggers=post.update\n",
352 | "path=Resources.ContainerInstances.Metadata.AWS::CloudFormation::Init\n",
353 | "action=cfn-init.exe -v -s ",
354 | {
355 | "Ref": "AWS::StackId"
356 | },
357 | " -r ContainerInstances",
358 | " --region ",
359 | {
360 | "Ref": "AWS::Region"
361 | },
362 | "\n"
363 | ]
364 | ]
365 | }
366 | }
367 | },
368 | "services": {
369 | "windows": {
370 | "cfn-hup": {
371 | "enabled": "true",
372 | "ensureRunning": "true",
373 | "files": [
374 | "c:\\cfn\\cfn-hup.conf",
375 | "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"
376 | ]
377 | }
378 | }
379 | }
380 | }
381 | }
382 | },
383 | "Properties": {
384 | "ImageId": {
385 | "Fn::FindInMap": [
386 | "AWSRegionToAMI",
387 | {
388 | "Ref": "AWS::Region"
389 | },
390 | "AMIID"
391 | ]
392 | },
393 | "SecurityGroups": [{
394 | "Ref": "EcsSecurityGroup"
395 | }],
396 | "InstanceType": {
397 | "Ref": "InstanceType"
398 | },
399 | "IamInstanceProfile": {
400 | "Ref": "EC2InstanceProfile"
401 | },
402 | "KeyName": {
403 | "Ref": "KeyName"
404 | },
405 | "BlockDeviceMappings": [{
406 | "DeviceName": "/dev/sda1",
407 | "Ebs": {
408 | "VolumeSize": "100",
409 | "VolumeType": "gp2"
410 | }
411 | }],
412 | "AssociatePublicIpAddress": "true",
413 | "UserData": {
414 | "Fn::Base64": {
415 | "Fn::Join": [
416 | "", [
417 | " \n",
418 | " # Set agent env variables for the Machine context (durable)\n",
419 | " [Environment]::SetEnvironmentVariable(\"ECS_CLUSTER\", \"",
420 | {
421 | "Ref": "ECSCluster"
422 | },
423 | "\"",
424 | ", \"Machine\")",
425 | "\n",
426 | "$agentVersion = 'v1.16.0';",
427 | "$agentZipUri = \"https://s3.amazonaws.com/amazon-ecs-agent/ecs-agent-windows-$agentVersion.zip\";",
428 | "$agentZipMD5Uri = \"$agentZipUri.md5\";",
429 | "$ecsExeDir = \"$env:ProgramFiles\\Amazon\\ECS\";",
430 | "$zipFile = \"$env:TEMP\\ecs-agent.zip\";",
431 | "echo \"log\" >> c:\\windows\\temp\\log1.txt;",
432 | "echo $zipFile >> c:\\windows\\temp\\log1.txt;",
433 | "echo $ecsExeDir >> c:\\windows\\temp\\log1.txt;",
434 | "$md5File = \"$env:TEMP\\ecs-agent.zip.md5\";",
435 | "Invoke-RestMethod -OutFile $zipFile -Uri $agentZipUri;",
436 | "Invoke-RestMethod -OutFile $md5File -Uri $agentZipMD5Uri;",
437 | "$expectedMD5 = (Get-Content $md5File);",
438 | "$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;",
439 | "$actualMD5 = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($zipFile))).replace(\"-\", \"\");",
440 | "if($expectedMD5 -ne $actualMD5) {",
441 | "echo \"Download does not match hash.\";",
442 | "echo \"Expected: $expectedMD5 - Got: $actualMD5\";",
443 | "exit 1;",
444 | "};",
445 | "Expand-Archive -Path $zipFile -DestinationPath $ecsExeDir -Force;",
446 | "$jobname = \"ECS-Agent-Init\";",
447 | "$script = \"cd '$ecsExeDir'; .\\amazon-ecs-agent.ps1\";",
448 | "$repeat = (New-TimeSpan -Minutes 1);",
449 | "$jobpath = $env:LOCALAPPDATA + \"\\Microsoft\\Windows\\PowerShell\\ScheduledJobs\\$jobname\\ScheduledJobDefinition.xml\";",
450 | "if($(Test-Path -Path $jobpath)) {",
451 | "echo \"Job definition already present\";",
452 | "exit 0;",
453 | "}",
454 | "$scriptblock = [scriptblock]::Create(\"$script\");",
455 | "$trigger = New-JobTrigger -At (Get-Date).Date -RepeatIndefinitely -RepetitionInterval $repeat -Once;",
456 | "$options = New-ScheduledJobOption -RunElevated -ContinueIfGoingOnBattery -StartIfOnBattery;",
457 | "Register-ScheduledJob -Name $jobname -ScriptBlock $scriptblock -Trigger $trigger -ScheduledJobOption $options -RunNow;",
458 | "Add-JobTrigger -Name $jobname -Trigger (New-JobTrigger -AtStartup -RandomDelay 00:1:00);",
459 | "echo $scriptblock >> c:\\windows\\temp\\log1.txt;",
460 | "echo $trigger >> c:\\windows\\temp\\log1.txt;",
461 | "echo $options >> c:\\windows\\temp\\log1.txt;",
462 | "# end of script\n",
463 | " cfn-init.exe -v -s ",
464 | {
465 | "Ref": "AWS::StackId"
466 | },
467 | " -r ContainerInstances",
468 | " --region ",
469 | {
470 | "Ref": "AWS::Region"
471 | },
472 | "\n",
473 | " cfn-signal.exe -e $lastexitcode --stack ",
474 | {
475 | "Ref": "AWS::StackName"
476 | },
477 | " --resource ECSAutoScalingGroup ",
478 | " --region ",
479 | {
480 | "Ref": "AWS::Region"
481 | },
482 | "; \n",
483 | " \n",
484 | "true"
485 | ]
486 | ]
487 | }
488 | }
489 | }
490 | },
491 | "service": {
492 | "Type": "AWS::ECS::Service",
493 | "DependsOn": "ALBListener",
494 | "Properties": {
495 | "Cluster": {
496 | "Ref": "ECSCluster"
497 | },
498 | "DesiredCount": "3",
499 | "LoadBalancers": [{
500 | "ContainerName": "awsecssample",
501 | "ContainerPort": "80",
502 | "TargetGroupArn": {
503 | "Ref": "ECSTargetGroup"
504 | }
505 | }],
506 | "Role": {
507 | "Ref": "ECSServiceRole"
508 | },
509 | "TaskDefinition": {
510 | "Ref": "taskdefinition"
511 | }
512 | }
513 | },
514 | "ECSServiceRole": {
515 | "Type": "AWS::IAM::Role",
516 | "Properties": {
517 | "AssumeRolePolicyDocument": {
518 | "Statement": [{
519 | "Effect": "Allow",
520 | "Principal": {
521 | "Service": [
522 | "ecs.amazonaws.com"
523 | ]
524 | },
525 | "Action": [
526 | "sts:AssumeRole"
527 | ]
528 | }]
529 | },
530 | "Path": "/",
531 | "Policies": [{
532 | "PolicyName": "ecs-service",
533 | "PolicyDocument": {
534 | "Statement": [{
535 | "Effect": "Allow",
536 | "Action": [
537 | "elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
538 | "elasticloadbalancing:DeregisterTargets",
539 | "elasticloadbalancing:Describe*",
540 | "elasticloadbalancing:RegisterInstancesWithLoadBalancer",
541 | "elasticloadbalancing:RegisterTargets",
542 | "ec2:Describe*",
543 | "ec2:AuthorizeSecurityGroupIngress"
544 | ],
545 | "Resource": "*"
546 | }]
547 | }
548 | }]
549 | }
550 | },
551 | "ServiceScalingTarget": {
552 | "Type": "AWS::ApplicationAutoScaling::ScalableTarget",
553 | "DependsOn": "service",
554 | "Properties": {
555 | "MaxCapacity": 4,
556 | "MinCapacity": 3,
557 | "ResourceId": {
558 | "Fn::Join": [
559 | "", [
560 | "service/",
561 | {
562 | "Ref": "ECSCluster"
563 | },
564 | "/",
565 | {
566 | "Fn::GetAtt": [
567 | "service",
568 | "Name"
569 | ]
570 | }
571 | ]
572 | ]
573 | },
574 | "RoleARN": {
575 | "Fn::GetAtt": [
576 | "AutoscalingRole",
577 | "Arn"
578 | ]
579 | },
580 | "ScalableDimension": "ecs:service:DesiredCount",
581 | "ServiceNamespace": "ecs"
582 | }
583 | },
584 | "ServiceScalingPolicy": {
585 | "Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
586 | "Properties": {
587 | "PolicyName": "AStepPolicy",
588 | "PolicyType": "StepScaling",
589 | "ScalingTargetId": {
590 | "Ref": "ServiceScalingTarget"
591 | },
592 | "StepScalingPolicyConfiguration": {
593 | "AdjustmentType": "PercentChangeInCapacity",
594 | "Cooldown": 60,
595 | "MetricAggregationType": "Average",
596 | "StepAdjustments": [{
597 | "MetricIntervalLowerBound": 0,
598 | "ScalingAdjustment": 200
599 | }]
600 | }
601 | }
602 | },
603 | "ALB500sAlarmScaleUp": {
604 | "Type": "AWS::CloudWatch::Alarm",
605 | "Properties": {
606 | "EvaluationPeriods": "1",
607 | "Statistic": "Average",
608 | "Threshold": "10",
609 | "AlarmDescription": "Alarm if our ALB generates too many HTTP 500s.",
610 | "Period": "60",
611 | "AlarmActions": [{
612 | "Ref": "ServiceScalingPolicy"
613 | }],
614 | "Namespace": "AWS/ApplicationELB",
615 | "Dimensions": [{
616 | "Name": "ECSService",
617 | "Value": {
618 | "Ref": "service"
619 | }
620 | }],
621 | "ComparisonOperator": "GreaterThanThreshold",
622 | "MetricName": "HTTPCode_ELB_5XX_Count"
623 | }
624 | },
625 | "EC2Role": {
626 | "Type": "AWS::IAM::Role",
627 | "Properties": {
628 | "AssumeRolePolicyDocument": {
629 | "Statement": [{
630 | "Effect": "Allow",
631 | "Principal": {
632 | "Service": [
633 | "ec2.amazonaws.com"
634 | ]
635 | },
636 | "Action": [
637 | "sts:AssumeRole"
638 | ]
639 | }]
640 | },
641 | "Path": "/",
642 | "Policies": [{
643 | "PolicyName": "ecs-service",
644 | "PolicyDocument": {
645 | "Statement": [{
646 | "Effect": "Allow",
647 | "Action": "*",
648 | "Resource": "*"
649 | }]
650 | }
651 | }]
652 | }
653 | },
654 | "AutoscalingRole": {
655 | "Type": "AWS::IAM::Role",
656 | "Properties": {
657 | "AssumeRolePolicyDocument": {
658 | "Statement": [{
659 | "Effect": "Allow",
660 | "Principal": {
661 | "Service": [
662 | "application-autoscaling.amazonaws.com"
663 | ]
664 | },
665 | "Action": [
666 | "sts:AssumeRole"
667 | ]
668 | }]
669 | },
670 | "Path": "/",
671 | "Policies": [{
672 | "PolicyName": "service-autoscaling",
673 | "PolicyDocument": {
674 | "Statement": [{
675 | "Effect": "Allow",
676 | "Action": [
677 | "application-autoscaling:*",
678 | "cloudwatch:DescribeAlarms",
679 | "cloudwatch:PutMetricAlarm",
680 | "ecs:UpdateService",
681 | "ecs:DescribeServices"
682 | ],
683 | "Resource": "*"
684 | }]
685 | }
686 | }]
687 | }
688 | },
689 | "EC2InstanceProfile": {
690 | "Type": "AWS::IAM::InstanceProfile",
691 | "Properties": {
692 | "Path": "/",
693 | "Roles": [{
694 | "Ref": "EC2Role"
695 | }]
696 | }
697 | }
698 | },
699 | "Outputs": {
700 | "ecsservice": {
701 | "Value": {
702 | "Ref": "service"
703 | }
704 | },
705 | "ecscluster": {
706 | "Value": {
707 | "Ref": "ECSCluster"
708 | }
709 | },
710 | "ECSALB": {
711 | "Description": "Your ALB DNS URL",
712 | "Value": {
713 | "Fn::Join": [
714 | "", [{
715 | "Fn::GetAtt": [
716 | "ECSALB",
717 | "DNSName"
718 | ]
719 | }]
720 | ]
721 | }
722 | },
723 | "taskdef": {
724 | "Value": {
725 | "Ref": "taskdefinition"
726 | }
727 | }
728 | }
729 | }
730 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | AWS Ecs Windows Aspnet
2 | Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [TOC]
3 |
4 |
5 |
6 | # 1.Objective
7 | The aim of this article is to provide guidance to migrate an ASP.NET MVC 4.6 or older application in to AWS ECS using containers. This will also cover the step-by-step instructions, cloud formation template and ECS task definition
8 |
9 | # 2. Why ASP.NET MVC 4.6 and Windows Containers?
10 | The ASP.NET MVC 4.6 and older versions of ASP.net occupy a significant footprint in the enterprise web application space. As enterprises move towards microservices for new or existing applications, containers are one of the stepping stones for migrating from monolithic to microservices architectures. Additionally, support for Windows Containers in Windows 10, Windows Server 2016, and Visual Studio Tooling support for Docker, simplifies the containerization of ASP.NET MVC apps.
11 |
12 | # 3. Pre-requisites
13 | Ensure your development environment has the following setup as per this [Microsoft article](https://docs.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc):
14 |
15 | a) Visual Studio 2017 with latest updates
16 |
17 | b) Docker for windows – version stable 1.13.0 or 1.12 Beta 26 (or newer versions)
18 |
19 | c) Windows 10 Anniversary Update (or higher) or Windows Server 2016 (or higher)
20 |
21 | If the web application was developed in earlier version of Visual Studio, it needs to be opened in Visual Studio 2017 which migrates all the settings to IDE.
22 |
23 |
24 | The following is the sample ASP.NET MVC 4.6 application that we’ll be migrating.
25 | 
26 |
27 | When the application is run in the development environment, it renders the following output.
28 |
29 | 
30 |
31 | # 4. Containerization of ASP.NET MVC 4.6 application
32 | These are the steps we will follow to containerize the ASP.NET MVC 4.6 application:
33 | - Creation of Docker file
34 | - Building a Docker image that will run ASP.NET MVC web app
35 | - Run image locally
36 | - Test in browser
37 |
38 | ## 4a. Creation of Docker file
39 | The Visual Studio 2017 support for Docker Tooling is leveraged to create Docker file.
40 | Right click on Project and Add Docker Support
41 |
42 | 
43 |
44 | This adds a Docker file to the current project and a Docker Compose project to the Solution.
45 |
46 | The Docker file added by Visual Studio 2017 should look like this:
47 |
48 |
49 | ```
50 | FROM microsoft/aspnet
51 | ARG source
52 | WORKDIR /inetpub/wwwroot
53 | COPY ${source:-obj/Docker/publish} .
54 |
55 | ```
56 |
57 | This file pulls the ASPNET Windows container image from the public DockerHub repository and pushes the binaries of the current project onto containers. This is enough for running locally in the development environment. To be able to run on Amazon ECS and for users to access the web service through Application Load Balancer (ALB), port 80 needs to be explicity exposed on the container. Update the Dockerfile to look like this:
58 | ```
59 | FROM microsoft/aspnet
60 | ARG source
61 | WORKDIR /inetpub/wwwroot
62 | COPY ${source:-obj/Docker/publish} .
63 | EXPOSE 80
64 |
65 | ```
66 | Right Click on the ASP.NET MVC Project -> Build
67 |
68 | This completes compiling and building the ASP.NET MVC project.
69 |
70 | ## 4b. Building a Docker image that will run ASP.NET MVC web app
71 | The Docker Compose project in the Visual Studio Solution will be leveraged to build a Docker image that will run the ASP.NET MVC app. The Docker compose project added by Visual Studio 2017 should look like this.
72 |
73 | 
74 |
75 | The Docker compose.yml definition added by Visual Studio 2017 should look like this.
76 | version: '2.1'
77 |
78 |
79 | ```
80 | ==services:
81 | awsecssample:
82 | image: awsecssample
83 | build:
84 | context: .\AWSECSSample
85 | dockerfile: Dockerfile==
86 |
87 | ```
88 |
89 | The default docker-compose.yml will be leveraged for building the container image.
90 |
91 | Right click on docker-compose project -> Build.
92 |
93 | A container image is built as per the Docker file definition. It can be verified by invoking ‘Docker Images’ command in terminal.
94 |
95 | 
96 |
97 | The step of building windows container image for ASP.NET 4.6 web application is complete.
98 |
99 | ## 4c. Starting container that runs the image
100 | The ‘docker run’ command is executed from the terminal to start the container that runs the image.
101 |
102 |
103 | ```
104 | docker run -d --name aspnetcontainer awsecssample
105 | ```
106 |
107 | 
108 |
109 | ## 4d. Test in browser
110 |
111 | When the http://localhost is opened in the browser, it will not render the expected ASP.NET MVC app. With the current windows container release, we can’t browse to http://localhost. This is a known behavior in WinNat. Please refer this article for more details
112 |
113 | https://docs.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc
114 |
115 | The IP address of the container needs to be figured out by running this command.
116 |
117 | ```
118 | docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" aspnetcontainer
119 |
120 | ```
121 | 
122 |
123 | When the container IP is accessed, it renders the ASP.NET MVC 4.6 app running inside windows container.
124 | 
125 |
126 |
127 | # 5. Amazon EC2 Container Registry
128 | OK! So you’ve created and ran the Docker image locally – now, how do we run it in the cloud?
129 |
130 | Amazon ECS can access container images stored in docker hub (private / public), your organization’s container repository, or Amazon EC2 Container Registry (Amazon ECR).
131 |
132 | In this post, we’ll use Amazon ECR because it’s fast, secure, and low cost. The Amazon EC2 container registry is a fully-managed Docker container registry that makes it easy for developers to securely store, manage, and deploy Docker Container images. It is deeply integrated with Amazon ECS, simplifying development to production workflow.
133 |
134 | ## 5.1 Create an Amazon ECR repository
135 |
136 | Each container image should be stored in its own repository on Amazon ECR. Use the AWS console to create a new Amazon ECR repository for your image:
137 |
138 |
139 | 
140 |
141 | After you create the repository, the AWS console will show you pre-filled code to authenticate to the repository with Docker, tag the image, and push the image to Amazon ECR.
142 |
143 | ## 5.2 Log in to ECR
144 |
145 | The docker log in command needs to be retrieved to authenticate the Docker client into the registry.You will need to modify this code to reflect the region you created your Amazon ECR repository in.
146 |
147 | aws ecr get-login --no-include-email --region ap-southeast-2
148 |
149 | 
150 |
151 | Enter the Docker log in command from the last step:
152 | 
153 |
154 | You should see a similar input when the login is successful.
155 |
156 |
157 | ## 5.3 Tag the container image
158 | The Container image that was built in the local development environment needs to be tagged with the ECR repository. For this example, we’ll use `:latest` if you are pushing many versions of an image, consider using a numerical tag structure.
159 |
160 | ```
161 | docker tag awsecssample:latest awsaccountnumber.dkr.ecr.awsregion.amazonaws.com/containerimagename:latest
162 |
163 | ```
164 | 
165 |
166 | ## 5.4 Push the container image
167 | Run the docker push command to push the newly created image to the ECR repository.
168 |
169 | ```
170 | docker push awsaccountnumber.dkr.ecr.awsregion.amazonaws.com/awsecssample:latest
171 | ```
172 | 
173 |
174 |
175 |
176 | The container image is encrypted and compressed in the Amazon ECR repository. The actual size of this container image is around 11GB in the local development environment. In the ECR repository it’s size is around 465 MB, which is a lot of space savings!
177 |
178 | 
179 |
180 |
181 |
182 | The required permissions need to be provided to the container image so that ECS instances can start leveraging that.
183 |
184 | # 6. Instantiate the Amazon ECS Cluster
185 | Amazon ECS manages clusters of Amazon EC2 compute instances that it deploys containers on to it. Creating the cluster to run your containers is a key step in scheduling and orchestrating containers in AWS. There are three options for creating ECS Windows Cluster. The first one is to leverage the cloud formation template (.json) provided in this repository , which provisions ecs cluster and other related resources end-to-end. The second option is to leverage the Cloud formation template (.yaml) available in the ecs reference architecture for windows. Both the option one and two provisions the same exact set of resources and have follow the same reference architecture. The difference is that the first one uses. json formatted cloud formation template and the second one uses .yaml formatted template.
186 |
187 | The third option is to manually create a cluster, set up container instances, ecs agent and other dependencies mentioned in this link http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_Windows_getting_started.html. The first option of leveraging Cloud formation template for ecs windows cluster is leveraged in this guidance.
188 |
189 |
190 | ## **6.1 Reference Architecture**
191 | The ECS Task definition, ECS Cluster definition and IAM roles are modified in the default cloud formation template mentioned in section 6 is modified to create a custom stack. The customized template is attached below.
192 |
193 |
194 | ## **6.2 ECS Task Definition**
195 | The task definition for running windows container image (ASP.NET MVC) should look like this.
196 |
197 | ```
198 |
199 | "taskdefinition": {
200 | "Type": "AWS::ECS::TaskDefinition",
201 | "Properties": {
202 | "ContainerDefinitions": [{
203 | "Name": {
204 | "Ref" : "AppName"
205 | },
206 | "Cpu": "200",
207 | "Essential": "true",
208 | "Image": {
209 | "Ref" : "ECSImageName"
210 | },
211 | "Memory": "2048",
212 | "LogConfiguration": {
213 | "LogDriver": "awslogs",
214 | "Options": {
215 | "awslogs-group": {
216 | "Ref": "CloudwatchLogsGroup"
217 | },
218 | "awslogs-region": {
219 | "Ref": "AWS::Region"
220 | },
221 | "awslogs-stream-prefix": {
222 | "Ref" : "AppName"
223 | }
224 | }
225 | },
226 | "PortMappings": [{
227 | "ContainerPort": 80
228 | }]
229 | }]
230 | }
231 | }
232 |
233 | ```
234 |
235 | The above ECS task definition refers to the container image provided during cloud formation stack creation. It also allocates 2048 MB of memory and 100 units (out of 1024) of CPU for execution. The task definition also maps the host port 80 with the container port 80. It also creates custom log groups.
236 |
237 |
238 | ## **6.3 ECS Cluster creation and configuration**
239 |
240 | The custom cloud formation template created in section 6.1 is validated in the cloud formation designer. The stack creation is initiated by referring to the custom template stored in S3.
241 |
242 | 
243 |
244 | The desired capacity, instance type, key name, max size, subnetid and vpc id are provided.
245 |
246 | 
247 |
248 | The IAM role for executing cloud formation stack is left with default. Now the stack creation is initiated.
249 |
250 | 
251 |
252 |
253 | The windows container images are generally larger in size. In our case it is around 11 GB. So it takes few minutes to create and configure the entire cluster. The Cloud Formation stack creation is successful.
254 |
255 | 
256 |
257 | It creates all the resources mentioned in the section 6.1.
258 |
259 | ## **6.4 Verification**
260 | Once the windows container is up and running it can be verified in the console.
261 |
262 | 
263 |
264 | Hit the application load balancer url.
265 |
266 | 
267 |
268 | The ASP.NET MVC 4.6 application is rendered in the browser.
269 |
270 | 
271 |
272 | In this demo we walked through how you can use standard Windows developer tools, Docker, Amazon ECR, and Amazon ECS to deploy a classic .NET web server to AWS using containers. These steps can be used as a template for containerizing and running other applciations written in classic .net code.
273 |
274 | For more information on using Amazon ECS, please visit the official product page or documentation.
275 |
276 | If you found this article useful, please share. If you have questions, please use the comments below.
277 |
278 | -- Sundar Narasiman,Thomas Fuller and Arun Kannan
279 |
280 |
--------------------------------------------------------------------------------
/screenshots/pic1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic1.jpg
--------------------------------------------------------------------------------
/screenshots/pic10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic10.jpg
--------------------------------------------------------------------------------
/screenshots/pic11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic11.jpg
--------------------------------------------------------------------------------
/screenshots/pic12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic12.jpg
--------------------------------------------------------------------------------
/screenshots/pic13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic13.jpg
--------------------------------------------------------------------------------
/screenshots/pic14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic14.jpg
--------------------------------------------------------------------------------
/screenshots/pic15.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic15.jpg
--------------------------------------------------------------------------------
/screenshots/pic15new.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic15new.jpg
--------------------------------------------------------------------------------
/screenshots/pic16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic16.jpg
--------------------------------------------------------------------------------
/screenshots/pic17.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic17.jpg
--------------------------------------------------------------------------------
/screenshots/pic18.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic18.jpg
--------------------------------------------------------------------------------
/screenshots/pic19.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic19.jpg
--------------------------------------------------------------------------------
/screenshots/pic2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic2.jpg
--------------------------------------------------------------------------------
/screenshots/pic20.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic20.jpg
--------------------------------------------------------------------------------
/screenshots/pic21.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic21.jpg
--------------------------------------------------------------------------------
/screenshots/pic22.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic22.jpg
--------------------------------------------------------------------------------
/screenshots/pic3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic3.jpg
--------------------------------------------------------------------------------
/screenshots/pic4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic4.jpg
--------------------------------------------------------------------------------
/screenshots/pic5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic5.jpg
--------------------------------------------------------------------------------
/screenshots/pic6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic6.jpg
--------------------------------------------------------------------------------
/screenshots/pic7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic7.jpg
--------------------------------------------------------------------------------
/screenshots/pic8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic8.jpg
--------------------------------------------------------------------------------
/screenshots/pic9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/aws-ecs-windows-aspnet/753c913db508a650633b92883d8ec7ab7252d213/screenshots/pic9.jpg
--------------------------------------------------------------------------------