DevOps Automation: Create Windows amazon EC2 Instance & Login to VMs Using WinRM Port

By April 17, 2020 August 7th, 2020 No Comments

DevOps Automation: Create Windows amazon EC2 Instance & Login to VMs Using WinRM Port

Amazon Ec2

Developers, Sysadmins, and IT administrators have been carrying out system administration tasks or DevOps tasks ‘manually’ from time immemorial. Be it desktop machines configuration, server configuration, operating system installation, software installations, or setting up VMs; everything was manual, time-consuming, and error-prone until DevOps conquered the software development and delivery space.

With profound knowledge and deep expertise in Azure DevOps automation services, our automation experts share scripts to help you automate creation of Windows Amazon EC2 instances using DevOps and automate logins to VMs using WinRM Port.

Other similar post: How to Automate Windows remote machines logins using DevOps

When you sign up with AWS (Amazon Web Services) you sign up for an entire universe of cloud computing services. One of such services is Amazon EC2 instance – a virtual server where subscribers provision compute servers in the AWS cloud. We understand creating Windows Amazon EC2 instances is a time and cost consuming process, especially in a 3-tier architecture where software developers require multiple VMs and several thousand dollar budget. The below automation for creating EC2 instances can save your business a fortune.

Let’s begin:

Create AWS EC2 instance
Install-Module -Name AWS.Tools.Installer -Force
Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp -Force
Install-Module -Name AWSPowerShell -Force
Install-Module -name AWSPowerShell.NetCore -Force
Import-Module AWSPowerShell.NetCore
Setup credentials and login to AWS Console
Set-AWSCredential -AccessKey <YOUR-ACCESS-KEY> -SecretKey <YOUR-ACCESS-SECRET-KEY> -StoreAs awsprofile
Set-AWSCredential -ProfileName awsprofile
Initialize-AWSDefaultConfiguration -ProfileName awsprofile -Region us-east-1
$keypair = New-EC2KeyPair -KeyName KeyPair
$keypair.KeyMaterial | Out-File -Encoding ascii C:\AWS\ec2-demo-key.pem
Create Security Groups – For opening WinRM Port (inbound / outbound)
New-EC2SecurityGroup -GroupName EC2DemoSecurityGroup -GroupDescription “Security group for EC2 demo”
Get-EC2SecurityGroup -GroupNames EC2DemoSecurityGroup
Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 80; ToPort = 80; IpRanges = @(“”)}
Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 3389; ToPort = 3389; IpRanges = @(“”)}
Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 5985; ToPort = 5985; IpRanges = @(“”)}
Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 5986; ToPort = 5986; IpRanges = @(“”)}Get-EC2SecurityGroup -GroupNames EC2DemoSecurityGroup | Select -ExpandProperty:IpPermission
Fetch the available AMI ID for the provided region
Get-EC2Image -Owners amazon -Filters @{Name = “name”; Values = “Windows_Server-2016*English*”} | select imageid,name | ft –auto
Create new instances
New-EC2Instance -ImageId ami-000bf92d1a21bf9ac -MinCount 1 -MaxCount 1 -KeyName KeyPair -SecurityGroups EC2DemoSecurityGroup -InstanceType t2.micro$instance = Get-EC2Instance -Filter @{Name = “reservation-id”; Values = “r-092d7d1c85675c615”}
Fetch default passwords assigned to VMs
$password = Get-EC2PasswordData -InstanceId $instance.RunningInstance.instanceid -PemFile C:\aws\ec2-demo-key.pem -Decrypt
And you’re done!

With years of polished, niche expertise in Azure DevOps Automation services, our team of automation experts has rendered support to several SMBs in automating workloads, saving significant costs on cloud operations.

Got a workload that’s costing you additional business hours and budget? Get in touch with our DevOps automation experts for automating cloud operations.

Our Recent Posts

Database Backup & Restore

Microsoft SQL is the most widely used database management system. As a user, you put huge amount of data there. Using this popular database is easy but its maintenance and backup is not.

Automate Remote Machine login

When developers are working on several remote machines via their local user machine, frequent and regular logins to the virtual machines (VMs) are tedious and time-consuming

A multinational chain of hospitals in the USA performs an Azure database migration as a solution for higher data protection and security while meeting the regulatory compliances.

Leave a Reply