Thursday 6 November 2014

Deploying in AWS using powershell

Deploy in AWS

This blog post is going to outline the trials and tribulations of getting a script working to deploy an AWS server. Fun and Games.

1. Set the region. We're currently using oregon which has our openswan server. So - Get-EC2Image -Region us-west-1

access denied. Into IAM - set up 'Richie' as a power user.

Access is working, but the script had returned 62000 lines before i cancelled it.

So we know we can connect. Make it the default region:

 Set-DefaultAWSRegion us-west-1

If we want to change to ireland as our default, then:

Clear-DefaultAWSRegion will get rid of the default.

2. Deploy an instance. The command is New-EC2Instance. Lets do it:

New-EC2Instance

here are the variables:

-ImageId is the image id. Windows 2008 server ami-e5f7bbd5

-MinCount and -MaxCount are the minimum and maximum no of instances to run (1 in each case)

-InstanceType t2.micro (we want the free one)

Heres the command:

New-EC2Instance -ImageId ami-e5f7bbd5 -MinCount 1 -MaxCount 1 -InstanceType t2.micro

but wait - i'll add in a variable because using that image id is a pain. I can get the actual name of it.

$ami = Get-EC2ImageByName Windows_2008_Base
New-EC2Instance -ImageId $ami.ImageId -MinCount 1 -MaxCount 1 -InstanceType t2.micro

lets see what happens. Into powershell ise and run the script.

Oops - turns out us-west-1 is California - not Oregon.  It deployed though.

PS C:\Users\Richie> $ami = Get-EC2ImageByName Windows_2008_Base
New-EC2Instance -ImageId $ami.ImageId -MinCount 1 -MaxCount 1 -InstanceType t2.micro


GroupNames    : {}
Groups        : {}
Instances     : {}
OwnerId       : 227910012278
RequesterId   : 
ReservationId : r-7e0d7020

Now to terminate it.

Stop-EC2Instance -Instance i-031762c9 -Terminate -Force

-instance was the instance name it created.
-Terminate means we're terminating it.
-Force means it doesnt come back with 'are you sure'

Sweet - its terminated.

Happy days - successful deployment and termination. I'll leave that now for today. Tomorrow - Azure deployments and terminations, and then maybe a bit more automation and detection.

Richie.





No comments:

Post a Comment