Learning how to use CDK to set up an environment to CD legacy .NET apps to Windows EC2 services.
Borrowing heavily from this AWS tutorial we will start to automate the process. There will be some manual setup work, we will look to automate more as we go on.
Once the deployment has finished we will have 2 EC2 instances that are created using the Base AMI that has IIS and the CodeDeploy agent installed. You will be able to see the IIS welcome page if you hit either of the 2 public EC2 IP addreses, or better yet, the public dns of our Load Balancer.
No application has been installed yet. It's just the infra.
Our trigger to install a new app will be to upload a zip file specifically called MyWebApp2.zip
to the S3 bucket generated by the stack. So let's do that.
Once you upload the file, you will be able to see AWS CodePipeline start - it will invoke CodeDeploy to deploy the app to each server. The semantics are the default one-at-a-time
, so you can watch each start up one after the other.
To release a new version of the app, upload a new MyWebApp2.zip
to the bucket again, this will trigger CodePipeline again and both instances will be updated.
Since we are using CodeDeploy and AutoScalingGroups, this is handled gracefully. You won't see CodePipeline kicking in, but you will see CodeDeploy take care of applying the latest version of the app to the new server.
Of course, you will want to have an AWS account. There is more to automate, so for the time being I am relying on you to provide the following:
Follow the Master Image directions of the workshop to give us the AMI we will use to build out our EC2 fleet.
Contrary to the tutorial, I am allowing RDP to machines to debug as we are still learning :)
If you have followed the above you would have also have:
- A VPC (I was just using the default VPC)
- Security Group
- Keypair allowing us to RDP into the machine.
I will start to externalise this stuff, but for now head into /lib/cdk-infra.ts
and fill in your keypair, vpc, machine image and security group.
You will want to set up your CDK environment - you can see more detail about that referencing CDK Workshop.
cdk bootstrap
cdk synth
cdk deploy