Post on 21-Mar-2017
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Norm Johanson and Steve Roberts
October 2015
DEV302
Hosting ASP.NET 5 applications in AWS
with Docker and AWS CodeDeploy
What to Expect from the Session
• Learn about ASP.NET 5 development with AWS
• Learn how to deploy ASP.NET 5-based applications
• AWS CodeDeploy
• Windows with IIS
• Docker
• Build and deploy as containers
• Run on Linux
• Deploy with AWS services:
• AWS Elastic Beanstalk
• Amazon EC2 Container Service (ECS)
Update on version 3 of the AWS SDK for .NET
• General availability released July 28th
• Fully modularized SDK
• Separate NuGet package for each service
• Depend on a common core package
• Xamarin support
• iOS & Android
• High compatibility with version 2
• http://docs.aws.amazon.com/sdkfornet/v3/apidocs/v3-
migration.html
What is ASP.NET 5?
• Open source
• Cross-platform
• Modularized
• Works on .NET 4.5.2, Mono, and the CoreCLR runtime
• New project structure
• New command-line tools
• dnvm: Version manager for the runtime
• dnu: Development utility, e.g. packaging
• dnx: Builds and runs the application
Status of ASP.NET 5
• ASP.NET 5 is on Beta 7
• Microsoft roadmap for ASP.NET 5 is RC in November
• 1.0.0 Q1 of 2016
• Supported in 3.2 beta versions of AWS SDK for .NET
• 3.1 versions are the current stable versions
Coding differences for CoreCLR
• Asynchronous service calls only
• Credentials management
• Encrypted SDK credentials store not currently supported
• Supports the shared <home>\.aws\credentials text file
• Environment variables
• AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY
• Use IAM roles for deployed applications
Pollster architecture
Web front end
(ASP.NET 5 MVC
WebApp)
Poll Feed
(MVC Web API)
Vote Processor
(MVC Web API)
Poll Creator
(MVC Web API)
Scheduling Engine
(Console Application)
Code on GitHub at :
https://github.com/awslabs/aws-sdk-net-samples
AWS services used
• Amazon DynamoDB
• Store Polls
• Amazon Simple Workflow Service
• Handle the scheduling
• Amazon Simple Notification Service
• Reporting poll results
• Amazon CloudWatchLogs
• Logging
Deployment considerations
• Application packaging
• Deployment environment needs to support ASP.NET 5
• 5 different processes to deploy
• Want to deploy services independently
• Scaling the application
First up: AWS CodeDeploy
• Deploy to Windows
• Install into IIS
• Bundle our runtime with the application
• Deployment is fully scriptable
• PowerShell or batch files
AWS CodeDeploy primitives
• Application
• Logical container for the application
• Deployment group
• EC2 instances
• Deployment
• Application bundle
• appspec.yml
PollFeed’s appspec.yml
version: 0.0
os: windows
files:
- source: \
destination: c:\inetpub\wwwroot\PollFeed
hooks:
ApplicationStop:
- location: .\approot\src\PollFeed\CodeDeployScripts\IIS_RemoveWebApp.ps1
timeout: 30
ApplicationStart:
- location: .\approot\src\PollFeed\CodeDeployScripts\IIS_SetupWebApp.ps1
timeout: 30
Compute architecture
Front end
Feed
Voter
Create
Scheduler
EC2 instances
CodeDeploy deployment group
Load balancer
Front end
Feed
Voter
Create
Scheduler
Front end
Feed
Voter
Create
Scheduler
Compute Architecture (Alternative)
Lower traffic services
Load balancer
Higher traffic services
EC2 instances
Front end
Feed
Voter
Front end
Feed
Voter
Front end
Feed
Voter
Create
Scheduler
EC2 instances
Create
Scheduler
What we learned: AWS CodeDeploy
• Can still take advantage of IIS
• Supports traditional .NET as well as CoreCLR
• Each Pollster service can be deployed independently
• Scaling
• Add new instances to deployment group
• Each instance runs all 5 Pollster services
Next up: Docker
• Containerize application
• Isolation
• Control CPU and memory
• Docker runs on Linux
Docker Crash Course
• Image
• Snapshot of your application
• Container
• Running instance of an image
• Similar but more efficient than virtual machines
• Reuse host resources until container changes them
• Instant startup
• Registry
• Registry of images for machines running Docker to pull from
• Public (Docker Hub) or private
Creating Docker images for Pollster
• Dockerfile
• Defines the files included in the images
• Defines which ports to expose
• Commands to start application
• Execute "docker build ..."
Using Docker with AWS Elastic Beanstalk
• Single container
• Suited to applications with just one process
• Multicontainer
• Suited to applications like Pollster that have multiple
processes
• Wraps EC2 Container Service and simplifies administration
AWS Elastic Beanstalk primitives
• Application
• Logical container for the application
• Application version
• Pointer to the application bundle in S3
• Environment
• The AWS resources that run the application
Compute architecture
Front end
Feed
Voter
Create
Scheduler
Elastic Beanstalk environment
Load balancer
Auto Scaling
group Front end
Feed
Voter
Create
SchedulerFront end
Feed
Voter
Create
Scheduler
EC2 instances
Dockerrun.aws.json
This is the application bundle
• Defines the images to be deployed from registry
• Defines the runtime configuration for the images
• Environment variables
• Memory
• CPU
• Port mapping
What we learned: Docker and Elastic Beanstalk
• Simple to set up
• Push images independently to the registry
• All Docker containers are restarted during deployment
• Scaling is similar to AWS CodeDeploy
• Add another machine and all processes will start on new
machine
EC2 Container Service primitives
• Task definitions• Collection of container definitions
• Each container has minimum CPU and maximum memory
• Defines port mapping and environment variables
• Service• Used for long-lived tasks like web services
• Optionally associated with a load balancer
• Cluster• EC2 instances running ECS agent
• Runs tasks and services
Compute architecture (simple)
ECS cluster
Load balancer
EC2 Container Service
(All 5 Pollster processes)
EC2 instances
Compute architecture (advanced)
Front-end
Service
(5 Tasks)
Feed
Service
(3 Tasks)
Vote
Service
(3 Tasks)
Scheduler
Service
(2 Tasks)
Creator
Service
(2 Tasks)
EC2 instances
ECS cluster
Deploying a new version
• Build new image with new tag
• Push image to registry
• Update task definition to reference new image
• Update service on cluster
What we learned: Docker and ECS
• Redeployments only affect the tasks running that image
• Lots of different scaling options
• Control over how compute resources are divided
• Trade simplicity for control
• We control compute architecture vs. Elastic Beanstalk
• Recommend CloudFormation for setup
What we learned in this session
• ASP.NET 5 opens up new deployment possibilities
• All options are equally valid
• Depends on your needs
• AWS CodeDeploy
• Scriptable deployment with full access to Windows services
• AWS Elastic Beanstalk multicontainer (Docker)
• Easy way to get started Dockerizing your application
• EC2 Container Service
• Full control over compute architecture and container scaling
Links
• GitHub for AWS SDK for .NET: https://github.com/aws/aws-sdk-net
• GitHub for Pollster and setup scripts: https://github.com/awslabs/aws-sdk-
net-samples
• AWS .NET blog: https://blogs.aws.amazon.com/net/
• AWS CodeDeploy: http://aws.amazon.com/codedeploy/
• AWS Elastic Beanstalk: http://aws.amazon.com/elasticbeanstalk/
• Amazon EC2 Container Service: http://aws.amazon.com/ecs/