-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateVolumes.ps1
More file actions
42 lines (33 loc) · 2.06 KB
/
createVolumes.ps1
File metadata and controls
42 lines (33 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
param (
$count = 1,
$size = 50,
$tagValue,
$tagKey = "Name",
$zone = "us-east-1b"
)
if ($tagValue -eq $null) {
"Provide -tagValue parameter"
return
}
Add-Type -Path (Resolve-Path ".\AWSSDK\AWSSDK.dll" | select -ExpandProperty Path)
$access_keys = Get-Content .\access-keys
$secretKeyID = $access_keys[0]
$secretAccessKeyID = $access_keys[1]
$ec2=[Amazon.AWSClientFactory]::CreateAmazonEC2Client($secretKeyID, $secretAccessKeyID)
$ec2Request = New-Object Amazon.EC2.Model.CreateVolumeRequest
$ec2Request.AvailabilityZone = $zone
$ec2Request.Size = "50"
$resourceId = @()
1..$count |
foreach {
$ec2Response = $ec2.CreateVolume($ec2Request)
$resourceId += $ec2Response.CreateVolumeResult.Volume.VolumeId
}
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = $tagKey
$tag.Value = $tagValue
$ec2TagRequest = New-Object Amazon.EC2.Model.CreateTagsRequest
$ec2TagRequest.Tag.Add($tag)
$resourceId | foreach { $ec2TagRequest.ResourceId.Add($_) }
$ec2.CreateTags($ec2TagRequest)