Developers, Sysadmins, and IT administrators have been performing system administration or DevOps activities "manually" since the dawn of time. Until DevOps took over the software development and delivery area, everything was manual, time-consuming, and error prone, whether it was desktop machine configuration, server configuration, operating system installation, programme installations, or setting up VMs.

With extensive knowledge and expertise in Azure DevOps automation services, Togglr cloud DevOps automation experts share scripts to assist you in automating the creation of Windows Amazon EC2 instances using Azure DevOps and automating VM logins using WinRM Port.

When you join up for AWS (Amazon Web Services), you are signing up for a vast array of cloud computing services. Amazon EC2 instance is one of these services, which is a virtual server that allows subscribers to provision computer servers in the AWS cloud. We recognise that generating Windows Amazon EC2 instances is a time-consuming and costly operation, especially in a three-tier design where software developers require several VMs and a large budget. 

The automation for creating EC2 instances listed below can save your company a lot of money.

Let’s get started:

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 -SecretKey -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 = @(“0.0.0.0/0”)}

Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 3389; ToPort = 3389; IpRanges = @(“0.0.0.0/0”)}

Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 5985; ToPort = 5985; IpRanges = @(“0.0.0.0/0”)}

Grant-EC2SecurityGroupIngress -GroupName EC2DemoSecurityGroup -IpPermissions @{IpProtocol = “tcp”; FromPort = 5986; ToPort = 5986; IpRanges = @(“0.0.0.0/0”)}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”}

$instance.RunningInstance.State

$instance.RunningInstance.publicdnsname

-----------------------------------------------------------------------------------------------------------------------

Fetch default passwords assigned to VMs

$password = Get-EC2PasswordData -InstanceId $instance.RunningInstance.instanceid -PemFile C:\aws\ec2-demo-key.pem -Decrypt

$password

-----------------------------------------------------------------------------------------------------------------------

And that's it!

Our team of automation experts has assisted various SMBs in automating workloads, saving considerable expenditures on cloud operations, thanks to years of polished, specific experience in Azure DevOps Automation services.

Have you got a task that's eating into your business hours and budget? For help automating cloud operations, contact our DevOps automation experts.

Note:

*For free demo visit: Test and Buy