summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/goamz/goamz/autoscaling/autoscaling.go
blob: 8e9f8ab02d754f64c257a19561fb97e4357329c2 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
//
// autoscaling: This package provides types and functions to interact with the AWS Auto Scale API
//
// Depends on https://wiki.ubuntu.com/goamz
//

package autoscaling

import (
	"encoding/base64"
	"encoding/xml"
	"fmt"
	"log"
	"net/http"
	"net/http/httputil"
	"net/url"
	"sort"
	"strconv"
	"strings"
	"time"

	"github.com/goamz/goamz/aws"
)

const debug = false

var timeNow = time.Now

// AutoScaling contains the details of the AWS region to perform operations against.
type AutoScaling struct {
	aws.Auth
	aws.Region
}

// New creates a new AutoScaling Client.
func New(auth aws.Auth, region aws.Region) *AutoScaling {
	return &AutoScaling{auth, region}
}

// ----------------------------------------------------------------------------
// Request dispatching logic.

// Error encapsulates an error returned by the AWS Auto Scaling API.
//
// See http://goo.gl/VZGuC for more details.
type Error struct {
	// HTTP status code (200, 403, ...)
	StatusCode int
	// AutoScaling error code ("UnsupportedOperation", ...)
	Code string
	// The error type
	Type string
	// The human-oriented error message
	Message   string
	RequestId string `xml:"RequestID"`
}

func (err *Error) Error() string {
	if err.Code == "" {
		return err.Message
	}

	return fmt.Sprintf("%s (%s)", err.Message, err.Code)
}

type xmlErrors struct {
	RequestId string  `xml:"RequestId"`
	Errors    []Error `xml:"Error"`
}

func (as *AutoScaling) query(params map[string]string, resp interface{}) error {
	params["Version"] = "2011-01-01"
	data := strings.NewReader(multimap(params).Encode())

	hreq, err := http.NewRequest("POST", as.Region.AutoScalingEndpoint+"/", data)
	if err != nil {
		return err
	}

	hreq.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")

	token := as.Auth.Token()
	if token != "" {
		hreq.Header.Set("X-Amz-Security-Token", token)
	}

	signer := aws.NewV4Signer(as.Auth, "autoscaling", as.Region)
	signer.Sign(hreq)

	if debug {
		log.Printf("%v -> {\n", hreq)
	}
	r, err := http.DefaultClient.Do(hreq)

	if err != nil {
		log.Printf("Error calling Amazon %v", err)
		return err
	}

	defer r.Body.Close()

	if debug {
		dump, _ := httputil.DumpResponse(r, true)
		log.Printf("response:\n")
		log.Printf("%v\n}\n", string(dump))
	}
	if r.StatusCode != 200 {
		return buildError(r)
	}
	err = xml.NewDecoder(r.Body).Decode(resp)
	return err
}

func buildError(r *http.Response) error {
	var (
		err    Error
		errors xmlErrors
	)
	xml.NewDecoder(r.Body).Decode(&errors)
	if len(errors.Errors) > 0 {
		err = errors.Errors[0]
	}

	err.RequestId = errors.RequestId
	err.StatusCode = r.StatusCode
	if err.Message == "" {
		err.Message = r.Status
	}
	return &err
}

func multimap(p map[string]string) url.Values {
	q := make(url.Values, len(p))
	for k, v := range p {
		q[k] = []string{v}
	}
	return q
}

func makeParams(action string) map[string]string {
	params := make(map[string]string)
	params["Action"] = action
	return params
}

func addParamsList(params map[string]string, label string, ids []string) {
	for i, id := range ids {
		params[label+"."+strconv.Itoa(i+1)] = id
	}
}

// ----------------------------------------------------------------------------
// Filtering helper.

// Filter builds filtering parameters to be used in an autoscaling query which supports
// filtering.  For example:
//
//     filter := NewFilter()
//     filter.Add("architecture", "i386")
//     filter.Add("launch-index", "0")
//     resp, err := as.DescribeTags(filter,nil,nil)
//
type Filter struct {
	m map[string][]string
}

// NewFilter creates a new Filter.
func NewFilter() *Filter {
	return &Filter{make(map[string][]string)}
}

// Add appends a filtering parameter with the given name and value(s).
func (f *Filter) Add(name string, value ...string) {
	f.m[name] = append(f.m[name], value...)
}

func (f *Filter) addParams(params map[string]string) {
	if f != nil {
		a := make([]string, len(f.m))
		i := 0
		for k := range f.m {
			a[i] = k
			i++
		}
		sort.StringSlice(a).Sort()
		for i, k := range a {
			prefix := "Filters.member." + strconv.Itoa(i+1)
			params[prefix+".Name"] = k
			for j, v := range f.m[k] {
				params[prefix+".Values.member."+strconv.Itoa(j+1)] = v
			}
		}
	}
}

// ----------------------------------------------------------------------------
// Auto Scaling base types and related functions.

// SimpleResp is the basic response from most actions.
type SimpleResp struct {
	XMLName   xml.Name
	RequestId string `xml:"ResponseMetadata>RequestId"`
}

// EnabledMetric encapsulates a metric associated with an Auto Scaling Group
//
// See http://goo.gl/hXiH17 for more details
type EnabledMetric struct {
	Granularity string `xml:"Granularity"` // The granularity of the enabled metric.
	Metric      string `xml:"Metric"`      // The name of the enabled metric.
}

// Instance encapsulates an instance type as returned by the Auto Scaling API
//
// See http://goo.gl/NwBxGh and http://goo.gl/OuoqhS for more details.
type Instance struct {
	// General instance information
	AutoScalingGroupName    string `xml:"AutoScalingGroupName"`
	AvailabilityZone        string `xml:"AvailabilityZone"`
	HealthStatus            string `xml:"HealthStatus"`
	InstanceId              string `xml:"InstanceId"`
	LaunchConfigurationName string `xml:"LaunchConfigurationName"`
	LifecycleState          string `xml:"LifecycleState"`
}

// SuspenedProcess encapsulates an Auto Scaling process that has been suspended
//
// See http://goo.gl/iObPgF for more details
type SuspendedProcess struct {
	ProcessName      string `xml:"ProcessName"`
	SuspensionReason string `xml:"SuspensionReason"`
}

// Tag encapsulates tag applied to an Auto Scaling group.
//
// See http://goo.gl/MG1hqs for more details
type Tag struct {
	Key               string `xml:"Key"`
	PropagateAtLaunch bool   `xml:"PropagateAtLaunch"` // Specifies whether the new tag will be applied to instances launched after the tag is created
	ResourceId        string `xml:"ResourceId"`        // the name of the Auto Scaling group - not required if creating ASG
	ResourceType      string `xml:"ResourceType"`      // currently only auto-scaling-group is supported - not required if creating ASG
	Value             string `xml:"Value"`
}

// AutoScalingGroup encapsulates an Auto Scaling Group object
//
// See http://goo.gl/fJdYhg for more details.
type AutoScalingGroup struct {
	AutoScalingGroupARN     string             `xml:"AutoScalingGroupARN"`
	AutoScalingGroupName    string             `xml:"AutoScalingGroupName"`
	AvailabilityZones       []string           `xml:"AvailabilityZones>member"`
	CreatedTime             time.Time          `xml:"CreatedTime"`
	DefaultCooldown         int                `xml:"DefaultCooldown"`
	DesiredCapacity         int                `xml:"DesiredCapacity"`
	EnabledMetrics          []EnabledMetric    `xml:"EnabledMetric>member"`
	HealthCheckGracePeriod  int                `xml:"HealthCheckGracePeriod"`
	HealthCheckType         string             `xml:"HealthCheckType"`
	Instances               []Instance         `xml:"Instances>member"`
	LaunchConfigurationName string             `xml:"LaunchConfigurationName"`
	LoadBalancerNames       []string           `xml:"LoadBalancerNames>member"`
	MaxSize                 int                `xml:"MaxSize"`
	MinSize                 int                `xml:"MinSize"`
	PlacementGroup          string             `xml:"PlacementGroup"`
	Status                  string             `xml:"Status"`
	SuspendedProcesses      []SuspendedProcess `xml:"SuspendedProcesses>member"`
	Tags                    []Tag              `xml:"Tags>member"`
	TerminationPolicies     []string           `xml:"TerminationPolicies>member"`
	VPCZoneIdentifier       string             `xml:"VPCZoneIdentifier"`
}

// CreateAutoScalingGroupParams type encapsulates options for the respective request.
//
// See http://goo.gl/3S13Bv for more details.
type CreateAutoScalingGroupParams struct {
	AutoScalingGroupName    string
	AvailabilityZones       []string
	DefaultCooldown         int
	DesiredCapacity         int
	HealthCheckGracePeriod  int
	HealthCheckType         string
	InstanceId              string
	LaunchConfigurationName string
	LoadBalancerNames       []string
	MaxSize                 int
	MinSize                 int
	PlacementGroup          string
	Tags                    []Tag
	TerminationPolicies     []string
	VPCZoneIdentifier       string
}

// AttachInstances Attach running instances to an autoscaling group
//
// See http://goo.gl/zDZbuQ for more details.
func (as *AutoScaling) AttachInstances(name string, instanceIds []string) (resp *SimpleResp, err error) {
	params := makeParams("AttachInstances")
	params["AutoScalingGroupName"] = name

	for i, id := range instanceIds {
		key := fmt.Sprintf("InstanceIds.member.%d", i+1)
		params[key] = id
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// CreateAutoScalingGroup creates an Auto Scaling Group on AWS
//
// Required params: AutoScalingGroupName, MinSize, MaxSize
//
// See http://goo.gl/3S13Bv for more details.
func (as *AutoScaling) CreateAutoScalingGroup(options *CreateAutoScalingGroupParams) (
	resp *SimpleResp, err error) {
	params := makeParams("CreateAutoScalingGroup")

	params["AutoScalingGroupName"] = options.AutoScalingGroupName
	params["MaxSize"] = strconv.Itoa(options.MaxSize)
	params["MinSize"] = strconv.Itoa(options.MinSize)
	params["DesiredCapacity"] = strconv.Itoa(options.DesiredCapacity)

	if options.DefaultCooldown > 0 {
		params["DefaultCooldown"] = strconv.Itoa(options.DefaultCooldown)
	}
	if options.HealthCheckGracePeriod > 0 {
		params["HealthCheckGracePeriod"] = strconv.Itoa(options.HealthCheckGracePeriod)
	}
	if options.HealthCheckType != "" {
		params["HealthCheckType"] = options.HealthCheckType
	}
	if options.InstanceId != "" {
		params["InstanceId"] = options.InstanceId
	}
	if options.LaunchConfigurationName != "" {
		params["LaunchConfigurationName"] = options.LaunchConfigurationName
	}
	if options.PlacementGroup != "" {
		params["PlacementGroup"] = options.PlacementGroup
	}
	if options.VPCZoneIdentifier != "" {
		params["VPCZoneIdentifier"] = options.VPCZoneIdentifier
	}
	if len(options.LoadBalancerNames) > 0 {
		addParamsList(params, "LoadBalancerNames.member", options.LoadBalancerNames)
	}
	if len(options.AvailabilityZones) > 0 {
		addParamsList(params, "AvailabilityZones.member", options.AvailabilityZones)
	}
	if len(options.TerminationPolicies) > 0 {
		addParamsList(params, "TerminationPolicies.member", options.TerminationPolicies)
	}
	for i, t := range options.Tags {
		key := "Tags.member.%d.%s"
		index := i + 1
		params[fmt.Sprintf(key, index, "Key")] = t.Key
		params[fmt.Sprintf(key, index, "Value")] = t.Value
		params[fmt.Sprintf(key, index, "PropagateAtLaunch")] = strconv.FormatBool(t.PropagateAtLaunch)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// EBS represents the AWS EBS volume data type
//
// See http://goo.gl/nDUL2h for more details
type EBS struct {
	DeleteOnTermination bool   `xml:"DeleteOnTermination"`
	Iops                int    `xml:"Iops"`
	SnapshotId          string `xml:"SnapshotId"`
	VolumeSize          int    `xml:"VolumeSize"`
	VolumeType          string `xml:"VolumeType"`
}

// BlockDeviceMapping represents the association of a block device with ebs volume.
//
// See http://goo.gl/wEGwkU for more details.
type BlockDeviceMapping struct {
	DeviceName  string `xml:"DeviceName"`
	Ebs         EBS    `xml:"Ebs"`
	NoDevice    bool   `xml:"NoDevice"`
	VirtualName string `xml:"VirtualName"`
}

// InstanceMonitoring data type
//
// See http://goo.gl/TfaPwz for more details
type InstanceMonitoring struct {
	Enabled bool `xml:"Enabled"`
}

// LaunchConfiguration encapsulates the LaunchConfiguration Data Type
//
// See http://goo.gl/TOJunp
type LaunchConfiguration struct {
	AssociatePublicIpAddress bool                 `xml:"AssociatePublicIpAddress"`
	BlockDeviceMappings      []BlockDeviceMapping `xml:"BlockDeviceMappings>member"`
	CreatedTime              time.Time            `xml:"CreatedTime"`
	EbsOptimized             bool                 `xml:"EbsOptimized"`
	IamInstanceProfile       string               `xml:"IamInstanceProfile"`
	ImageId                  string               `xml:"ImageId"`
	InstanceId               string               `xml:"InstanceId"`
	InstanceMonitoring       InstanceMonitoring   `xml:"InstanceMonitoring"`
	InstanceType             string               `xml:"InstanceType"`
	KernelId                 string               `xml:"KernelId"`
	KeyName                  string               `xml:"KeyName"`
	LaunchConfigurationARN   string               `xml:"LaunchConfigurationARN"`
	LaunchConfigurationName  string               `xml:"LaunchConfigurationName"`
	RamdiskId                string               `xml:"RamdiskId"`
	SecurityGroups           []string             `xml:"SecurityGroups>member"`
	SpotPrice                string               `xml:"SpotPrice"`
	UserData                 string               `xml:"UserData"`
}

// CreateLaunchConfiguration creates a launch configuration
//
// Required params: AutoScalingGroupName, MinSize, MaxSize
//
// See http://goo.gl/8e0BSF for more details.
func (as *AutoScaling) CreateLaunchConfiguration(lc *LaunchConfiguration) (
	resp *SimpleResp, err error) {

	var b64 = base64.StdEncoding

	params := makeParams("CreateLaunchConfiguration")
	params["LaunchConfigurationName"] = lc.LaunchConfigurationName

	if lc.AssociatePublicIpAddress {
		params["AssociatePublicIpAddress"] = strconv.FormatBool(lc.AssociatePublicIpAddress)
	}
	if lc.EbsOptimized {
		params["EbsOptimized"] = strconv.FormatBool(lc.EbsOptimized)
	}
	if lc.IamInstanceProfile != "" {
		params["IamInstanceProfile"] = lc.IamInstanceProfile
	}
	if lc.ImageId != "" {
		params["ImageId"] = lc.ImageId
	}
	if lc.InstanceId != "" {
		params["InstanceId"] = lc.InstanceId
	}
	if lc.InstanceMonitoring != (InstanceMonitoring{}) {
		params["InstanceMonitoring.Enabled"] = strconv.FormatBool(lc.InstanceMonitoring.Enabled)
	}
	if lc.InstanceType != "" {
		params["InstanceType"] = lc.InstanceType
	}
	if lc.KernelId != "" {
		params["KernelId"] = lc.KernelId
	}
	if lc.KeyName != "" {
		params["KeyName"] = lc.KeyName
	}
	if lc.RamdiskId != "" {
		params["RamdiskId"] = lc.RamdiskId
	}
	if lc.SpotPrice != "" {
		params["SpotPrice"] = lc.SpotPrice
	}
	if lc.UserData != "" {
		params["UserData"] = b64.EncodeToString([]byte(lc.UserData))
	}

	// Add our block device mappings
	for i, bdm := range lc.BlockDeviceMappings {
		key := "BlockDeviceMappings.member.%d.%s"
		index := i + 1
		params[fmt.Sprintf(key, index, "DeviceName")] = bdm.DeviceName
		params[fmt.Sprintf(key, index, "VirtualName")] = bdm.VirtualName

		if bdm.NoDevice {
			params[fmt.Sprintf(key, index, "NoDevice")] = "true"
		}

		if bdm.Ebs != (EBS{}) {
			key := "BlockDeviceMappings.member.%d.Ebs.%s"

			// Defaults to true
			params[fmt.Sprintf(key, index, "DeleteOnTermination")] = strconv.FormatBool(bdm.Ebs.DeleteOnTermination)

			if bdm.Ebs.Iops > 0 {
				params[fmt.Sprintf(key, index, "Iops")] = strconv.Itoa(bdm.Ebs.Iops)
			}
			if bdm.Ebs.SnapshotId != "" {
				params[fmt.Sprintf(key, index, "SnapshotId")] = bdm.Ebs.SnapshotId
			}
			if bdm.Ebs.VolumeSize > 0 {
				params[fmt.Sprintf(key, index, "VolumeSize")] = strconv.Itoa(bdm.Ebs.VolumeSize)
			}
			if bdm.Ebs.VolumeType != "" {
				params[fmt.Sprintf(key, index, "VolumeType")] = bdm.Ebs.VolumeType
			}
		}
	}

	if len(lc.SecurityGroups) > 0 {
		addParamsList(params, "SecurityGroups.member", lc.SecurityGroups)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// CreateOrUpdateTags creates or updates Auto Scaling Group Tags
//
// See http://goo.gl/e1UIXb for more details.
func (as *AutoScaling) CreateOrUpdateTags(tags []Tag) (resp *SimpleResp, err error) {
	params := makeParams("CreateOrUpdateTags")

	for i, t := range tags {
		key := "Tags.member.%d.%s"
		index := i + 1
		params[fmt.Sprintf(key, index, "Key")] = t.Key
		params[fmt.Sprintf(key, index, "Value")] = t.Value
		params[fmt.Sprintf(key, index, "PropagateAtLaunch")] = strconv.FormatBool(t.PropagateAtLaunch)
		params[fmt.Sprintf(key, index, "ResourceId")] = t.ResourceId
		if t.ResourceType != "" {
			params[fmt.Sprintf(key, index, "ResourceType")] = t.ResourceType
		} else {
			params[fmt.Sprintf(key, index, "ResourceType")] = "auto-scaling-group"
		}
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

type CompleteLifecycleActionParams struct {
	AutoScalingGroupName  string
	LifecycleActionResult string
	LifecycleActionToken  string
	LifecycleHookName     string
}

// CompleteLifecycleAction completes the lifecycle action for the associated token initiated under the given lifecycle hook with the specified result.
//
// Part of the basic sequence for adding a lifecycle hook to an Auto Scaling group:
// 1) Create a notification target (SQS queue || SNS Topic)
// 2) Create an IAM role to allow the ASG topublish lifecycle notifications to the designated SQS queue or SNS topic
// 3) Create the lifecycle hook. You can create a hook that acts when instances launch or when instances terminate
// 4) If necessary, record the lifecycle action heartbeat to keep the instance in a pending state
// 5) ***Complete the lifecycle action***
//
// See http://goo.gl/k4fl0p for more details
func (as *AutoScaling) CompleteLifecycleAction(options *CompleteLifecycleActionParams) (
	resp *SimpleResp, err error) {
	params := makeParams("CompleteLifecycleAction")

	params["AutoScalingGroupName"] = options.AutoScalingGroupName
	params["LifecycleActionResult"] = options.LifecycleActionResult
	params["LifecycleActionToken"] = options.LifecycleActionToken
	params["LifecycleHookName"] = options.LifecycleHookName

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeleteAutoScalingGroup deletes an Auto Scaling Group
//
// See http://goo.gl/us7VSffor for more details.
func (as *AutoScaling) DeleteAutoScalingGroup(asgName string, forceDelete bool) (
	resp *SimpleResp, err error) {
	params := makeParams("DeleteAutoScalingGroup")
	params["AutoScalingGroupName"] = asgName

	if forceDelete {
		params["ForceDelete"] = "true"
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeleteLaunchConfiguration deletes a Launch Configuration
//
// See http://goo.gl/xksfyR for more details.
func (as *AutoScaling) DeleteLaunchConfiguration(name string) (resp *SimpleResp, err error) {
	params := makeParams("DeleteLaunchConfiguration")
	params["LaunchConfigurationName"] = name

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeleteLifecycleHook eletes the specified lifecycle hook.
// If there are any outstanding lifecycle actions, they are completed first
//
// See http://goo.gl/MwX1vG for more details.
func (as *AutoScaling) DeleteLifecycleHook(asgName, lifecycleHookName string) (resp *SimpleResp, err error) {
	params := makeParams("DeleteLifecycleHook")
	params["AutoScalingGroupName"] = asgName
	params["LifecycleHookName"] = lifecycleHookName

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeleteNotificationConfiguration deletes notifications created by PutNotificationConfiguration.
//
// See http://goo.gl/jTqoYz for more details
func (as *AutoScaling) DeleteNotificationConfiguration(asgName string, topicARN string) (
	resp *SimpleResp, err error) {
	params := makeParams("DeleteNotificationConfiguration")
	params["AutoScalingGroupName"] = asgName
	params["TopicARN"] = topicARN

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeletePolicy deletes a policy created by PutScalingPolicy.
//
// policyName might be the policy name or ARN
//
// See http://goo.gl/aOQPH2 for more details
func (as *AutoScaling) DeletePolicy(asgName string, policyName string) (resp *SimpleResp, err error) {
	params := makeParams("DeletePolicy")
	params["AutoScalingGroupName"] = asgName
	params["PolicyName"] = policyName

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeleteScheduledAction deletes a scheduled action previously created using the PutScheduledUpdateGroupAction.
//
// See http://goo.gl/Zss9CH for more details
func (as *AutoScaling) DeleteScheduledAction(asgName string, scheduledActionName string) (resp *SimpleResp, err error) {
	params := makeParams("DeleteScheduledAction")
	params["AutoScalingGroupName"] = asgName
	params["ScheduledActionName"] = scheduledActionName

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DeleteTags deletes autoscaling group tags
//
// See http://goo.gl/o8HzAk for more details.
func (as *AutoScaling) DeleteTags(tags []Tag) (resp *SimpleResp, err error) {
	params := makeParams("DeleteTags")

	for i, t := range tags {
		key := "Tags.member.%d.%s"
		index := i + 1
		params[fmt.Sprintf(key, index, "Key")] = t.Key
		params[fmt.Sprintf(key, index, "Value")] = t.Value
		params[fmt.Sprintf(key, index, "PropagateAtLaunch")] = strconv.FormatBool(t.PropagateAtLaunch)
		params[fmt.Sprintf(key, index, "ResourceId")] = t.ResourceId
		params[fmt.Sprintf(key, index, "ResourceType")] = "auto-scaling-group"
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

//DescribeAccountLimits response wrapper
//
// See http://goo.gl/tKsMN0 for more details.
type DescribeAccountLimitsResp struct {
	MaxNumberOfAutoScalingGroups    int    `xml:"DescribeAccountLimitsResult>MaxNumberOfAutoScalingGroups"`
	MaxNumberOfLaunchConfigurations int    `xml:"DescribeAccountLimitsResult>MaxNumberOfLaunchConfigurations"`
	RequestId                       string `xml:"ResponseMetadata>RequestId"`
}

// DescribeAccountLimits - Returns the limits for the Auto Scaling resources currently allowed for your AWS account.
//
// See http://goo.gl/tKsMN0 for more details.
func (as *AutoScaling) DescribeAccountLimits() (resp *DescribeAccountLimitsResp, err error) {
	params := makeParams("DescribeAccountLimits")

	resp = new(DescribeAccountLimitsResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// AdjustmentType specifies whether the PutScalingPolicy ScalingAdjustment parameter is an absolute number or a percentage of the current capacity.
//
// See http://goo.gl/tCFqeL for more details
type AdjustmentType struct {
	AdjustmentType string //Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity.
}

//DescribeAdjustmentTypes response wrapper
//
// See http://goo.gl/hGx3Pc for more details.
type DescribeAdjustmentTypesResp struct {
	AdjustmentTypes []AdjustmentType `xml:"DescribeAdjustmentTypesResult>AdjustmentTypes>member"`
	RequestId       string           `xml:"ResponseMetadata>RequestId"`
}

// DescribeAdjustmentTypes returns policy adjustment types for use in the PutScalingPolicy action.
//
// See http://goo.gl/hGx3Pc for more details.
func (as *AutoScaling) DescribeAdjustmentTypes() (resp *DescribeAdjustmentTypesResp, err error) {
	params := makeParams("DescribeAdjustmentTypes")

	resp = new(DescribeAdjustmentTypesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DescribeAutoScalingGroups response wrapper
//
// See http://goo.gl/nW74Ut for more details.
type DescribeAutoScalingGroupsResp struct {
	AutoScalingGroups []AutoScalingGroup `xml:"DescribeAutoScalingGroupsResult>AutoScalingGroups>member"`
	NextToken         string             `xml:"DescribeAutoScalingGroupsResult>NextToken"`
	RequestId         string             `xml:"ResponseMetadata>RequestId"`
}

// DescribeAutoScalingGroups returns a full description of each Auto Scaling group in the given list
// If no autoscaling groups are provided, returns the details of all autoscaling groups
// Supports pagination by using the returned "NextToken" parameter for subsequent calls
//
// See http://goo.gl/nW74Ut for more details.
func (as *AutoScaling) DescribeAutoScalingGroups(names []string, maxRecords int, nextToken string) (
	resp *DescribeAutoScalingGroupsResp, err error) {
	params := makeParams("DescribeAutoScalingGroups")

	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}
	if len(names) > 0 {
		addParamsList(params, "AutoScalingGroupNames.member", names)
	}

	resp = new(DescribeAutoScalingGroupsResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DescribeAutoScalingInstances response wrapper
//
// See http://goo.gl/ckzORt for more details.
type DescribeAutoScalingInstancesResp struct {
	AutoScalingInstances []Instance `xml:"DescribeAutoScalingInstancesResult>AutoScalingInstances>member"`
	NextToken            string     `xml:"DescribeAutoScalingInstancesResult>NextToken"`
	RequestId            string     `xml:"ResponseMetadata>RequestId"`
}

// DescribeAutoScalingInstances returns a description of each Auto Scaling instance in the InstanceIds list.
// If a list is not provided, the service returns the full details of all instances up to a maximum of 50
// By default, the service returns a list of 20 items.
// Supports pagination by using the returned "NextToken" parameter for subsequent calls
//
// See http://goo.gl/ckzORt for more details.
func (as *AutoScaling) DescribeAutoScalingInstances(ids []string, maxRecords int, nextToken string) (
	resp *DescribeAutoScalingInstancesResp, err error) {
	params := makeParams("DescribeAutoScalingInstances")

	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}
	if len(ids) > 0 {
		addParamsList(params, "InstanceIds.member", ids)
	}

	resp = new(DescribeAutoScalingInstancesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DescribeAutoScalingNotificationTypes response wrapper
//
// See http://goo.gl/pmLIoE for more details.
type DescribeAutoScalingNotificationTypesResp struct {
	AutoScalingNotificationTypes []string `xml:"DescribeAutoScalingNotificationTypesResult>AutoScalingNotificationTypes>member"`
	RequestId                    string   `xml:"ResponseMetadata>RequestId"`
}

// DescribeAutoScalingNotificationTypes returns a list of all notification types that are supported by Auto Scaling
//
// See http://goo.gl/pmLIoE for more details.
func (as *AutoScaling) DescribeAutoScalingNotificationTypes() (resp *DescribeAutoScalingNotificationTypesResp, err error) {
	params := makeParams("DescribeAutoScalingNotificationTypes")

	resp = new(DescribeAutoScalingNotificationTypesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DescribeLaunchConfigurationResp defines the basic response structure for launch configuration
// requests
//
// See http://goo.gl/y31YYE for more details.
type DescribeLaunchConfigurationsResp struct {
	LaunchConfigurations []LaunchConfiguration `xml:"DescribeLaunchConfigurationsResult>LaunchConfigurations>member"`
	NextToken            string                `xml:"DescribeLaunchConfigurationsResult>NextToken"`
	RequestId            string                `xml:"ResponseMetadata>RequestId"`
}

// DescribeLaunchConfigurations returns details about the launch configurations supplied in
// the list. If the list is nil, information is returned about all launch configurations in the
// region.
//
// See http://goo.gl/y31YYE for more details.
func (as *AutoScaling) DescribeLaunchConfigurations(names []string, maxRecords int, nextToken string) (
	resp *DescribeLaunchConfigurationsResp, err error) {
	params := makeParams("DescribeLaunchConfigurations")

	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}
	if len(names) > 0 {
		addParamsList(params, "LaunchConfigurationNames.member", names)
	}

	resp = new(DescribeLaunchConfigurationsResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}

	return resp, nil
}

// DescribeLifecycleHookTypesResult wraps a DescribeLifecycleHookTypes response
//
// See http://goo.gl/qiAH31 for more details.
type DescribeLifecycleHookTypesResult struct {
	LifecycleHookTypes []string `xml:"DescribeLifecycleHookTypesResult>LifecycleHookTypes>member"`
	RequestId          string   `xml:"ResponseMetadata>RequestId"`
}

// DescribeLifecycleHookTypes describes the available types of lifecycle hooks
//
// See http://goo.gl/E9IBtY for more information
func (as *AutoScaling) DescribeLifecycleHookTypes() (
	resp *DescribeLifecycleHookTypesResult, err error) {
	params := makeParams("DescribeLifecycleHookTypes")

	resp = new(DescribeLifecycleHookTypesResult)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// LifecycleHook represents a lifecyclehook object
//
// See http://goo.gl/j62Iqu for more information
type LifecycleHook struct {
	AutoScalingGroupName  string `xml:"AutoScalingGroupName"`
	DefaultResult         string `xml:"DefaultResult"`
	GlobalTimeout         int    `xml:"GlobalTimeout"`
	HeartbeatTimeout      int    `xml:"HeartbeatTimeout"`
	LifecycleHookName     string `xml:"LifecycleHookName"`
	LifecycleTransition   string `xml:"LifecycleTransition"`
	NotificationMetadata  string `xml:"NotificationMetadata"`
	NotificationTargetARN string `xml:"NotificationTargetARN"`
	RoleARN               string `xml:"RoleARN"`
}

// DescribeLifecycleHooks wraps a DescribeLifecycleHooks response
//
// See http://goo.gl/wQkWiz for more details.
type DescribeLifecycleHooksResult struct {
	LifecycleHooks []string `xml:"DescribeLifecycleHooksResult>LifecycleHooks>member"`
	RequestId      string   `xml:"ResponseMetadata>RequestId"`
}

// DescribeLifecycleHooks describes the lifecycle hooks that currently belong to the specified Auto Scaling group
//
// See http://goo.gl/wQkWiz for more information
func (as *AutoScaling) DescribeLifecycleHooks(asgName string, hookNames []string) (
	resp *DescribeLifecycleHooksResult, err error) {
	params := makeParams("DescribeLifecycleHooks")
	params["AutoScalingGroupName"] = asgName

	if len(hookNames) > 0 {
		addParamsList(params, "LifecycleHookNames.member", hookNames)
	}

	resp = new(DescribeLifecycleHooksResult)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// MetricGranularity encapsulates the MetricGranularityType
//
// See http://goo.gl/WJ82AA for more details
type MetricGranularity struct {
	Granularity string `xml:"Granularity"`
}

//MetricCollection encapsulates the MetricCollectionType
//
// See http://goo.gl/YrEG6h for more details
type MetricCollection struct {
	Metric string `xml:"Metric"`
}

// DescribeMetricCollectionTypesResp response wrapper
//
// See http://goo.gl/UyYc3i for more details.
type DescribeMetricCollectionTypesResp struct {
	Granularities []MetricGranularity `xml:"DescribeMetricCollectionTypesResult>Granularities>member"`
	Metrics       []MetricCollection  `xml:"DescribeMetricCollectionTypesResult>Metrics>member"`
	RequestId     string              `xml:"ResponseMetadata>RequestId"`
}

// DescribeMetricCollectionTypes returns a list of metrics and a corresponding list of granularities for each metric
//
// See http://goo.gl/UyYc3i for more details.
func (as *AutoScaling) DescribeMetricCollectionTypes() (resp *DescribeMetricCollectionTypesResp, err error) {
	params := makeParams("DescribeMetricCollectionTypes")

	resp = new(DescribeMetricCollectionTypesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// NotificationConfiguration encapsulates the NotificationConfigurationType
//
// See http://goo.gl/M8xYOQ for more details
type NotificationConfiguration struct {
	AutoScalingGroupName string `xml:"AutoScalingGroupName"`
	NotificationType     string `xml:"NotificationType"`
	TopicARN             string `xml:"TopicARN"`
}

// DescribeNotificationConfigurations response wrapper
//
// See http://goo.gl/qiAH31 for more details.
type DescribeNotificationConfigurationsResp struct {
	NotificationConfigurations []NotificationConfiguration `xml:"DescribeNotificationConfigurationsResult>NotificationConfigurations>member"`
	NextToken                  string                      `xml:"DescribeNotificationConfigurationsResult>NextToken"`
	RequestId                  string                      `xml:"ResponseMetadata>RequestId"`
}

// DescribeNotificationConfigurations returns a list of notification actions associated with Auto Scaling groups for specified events.
// Supports pagination by using the returned "NextToken" parameter for subsequent calls
//
// http://goo.gl/qiAH31 for more details.
func (as *AutoScaling) DescribeNotificationConfigurations(asgNames []string, maxRecords int, nextToken string) (
	resp *DescribeNotificationConfigurationsResp, err error) {
	params := makeParams("DescribeNotificationConfigurations")

	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}
	if len(asgNames) > 0 {
		addParamsList(params, "AutoScalingGroupNames.member", asgNames)
	}

	resp = new(DescribeNotificationConfigurationsResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// Alarm encapsulates the Alarm data type.
//
// See http://goo.gl/Q0uPAB for more details
type Alarm struct {
	AlarmARN  string `xml:"AlarmARN"`
	AlarmName string `xml:"AlarmName"`
}

// ScalingPolicy encapsulates the ScalingPolicyType
//
// See http://goo.gl/BYAT18 for more details
type ScalingPolicy struct {
	AdjustmentType       string  `xml:"AdjustmentType"` // ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity
	Alarms               []Alarm `xml:"Alarms>member"`  // A list of CloudWatch Alarms related to the policy
	AutoScalingGroupName string  `xml:"AutoScalingGroupName"`
	Cooldown             int     `xml:"Cooldown"`
	MinAdjustmentStep    int     `xml:"MinAdjustmentStep"` // Changes the DesiredCapacity of ASG by at least the specified number of instances.
	PolicyARN            string  `xml:"PolicyARN"`
	PolicyName           string  `xml:"PolicyName"`
	ScalingAdjustment    int     `xml:"ScalingAdjustment"`
}

// DescribePolicies response wrapper
//
// http://goo.gl/bN7A9T for more details.
type DescribePoliciesResp struct {
	ScalingPolicies []ScalingPolicy `xml:"DescribePoliciesResult>ScalingPolicies>member"`
	NextToken       string          `xml:"DescribePoliciesResult>NextToken"`
	RequestId       string          `xml:"ResponseMetadata>RequestId"`
}

// DescribePolicies returns descriptions of what each policy does.
// Supports pagination by using the returned "NextToken" parameter for subsequent calls
//
// http://goo.gl/bN7A9Tfor more details.
func (as *AutoScaling) DescribePolicies(asgName string, policyNames []string, maxRecords int, nextToken string) (
	resp *DescribePoliciesResp, err error) {
	params := makeParams("DescribePolicies")

	if asgName != "" {
		params["AutoScalingGroupName"] = asgName
	}
	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}
	if len(policyNames) > 0 {
		addParamsList(params, "PolicyNames.member", policyNames)
	}

	resp = new(DescribePoliciesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// Activity encapsulates the Activity data type
//
// See http://goo.gl/fRaVi1 for more details
type Activity struct {
	ActivityId           string    `xml:"ActivityId"`
	AutoScalingGroupName string    `xml:"AutoScalingGroupName"`
	Cause                string    `xml:"Cause"`
	Description          string    `xml:"Description"`
	Details              string    `xml:"Details"`
	EndTime              time.Time `xml:"EndTime"`
	Progress             int       `xml:"Progress"`
	StartTime            time.Time `xml:"StartTime"`
	StatusCode           string    `xml:"StatusCode"`
	StatusMessage        string    `xml:"StatusMessage"`
}

// DescribeScalingActivities response wrapper
//
// http://goo.gl/noOXIC for more details.
type DescribeScalingActivitiesResp struct {
	Activities []Activity `xml:"DescribeScalingActivitiesResult>Activities>member"`
	NextToken  string     `xml:"DescribeScalingActivitiesResult>NextToken"`
	RequestId  string     `xml:"ResponseMetadata>RequestId"`
}

// DescribeScalingActivities returns the scaling activities for the specified Auto Scaling group.
// Supports pagination by using the returned "NextToken" parameter for subsequent calls
//
// http://goo.gl/noOXIC more details.
func (as *AutoScaling) DescribeScalingActivities(asgName string, activityIds []string, maxRecords int, nextToken string) (
	resp *DescribeScalingActivitiesResp, err error) {
	params := makeParams("DescribeScalingActivities")

	if asgName != "" {
		params["AutoScalingGroupName"] = asgName
	}
	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}
	if len(activityIds) > 0 {
		addParamsList(params, "ActivityIds.member", activityIds)
	}

	resp = new(DescribeScalingActivitiesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// ProcessType encapsulates the Auto Scaling process data type
//
// See http://goo.gl/9BvNik for more details.
type ProcessType struct {
	ProcessName string `xml:"ProcessName"`
}

// DescribeScalingProcessTypes response wrapper
//
// See http://goo.gl/rkp2tw for more details.
type DescribeScalingProcessTypesResp struct {
	Processes []ProcessType `xml:"DescribeScalingProcessTypesResult>Processes>member"`
	RequestId string        `xml:"ResponseMetadata>RequestId"`
}

// DescribeScalingProcessTypes returns scaling process types for use in the ResumeProcesses and SuspendProcesses actions.
//
// See http://goo.gl/rkp2tw for more details.
func (as *AutoScaling) DescribeScalingProcessTypes() (resp *DescribeScalingProcessTypesResp, err error) {
	params := makeParams("DescribeScalingProcessTypes")

	resp = new(DescribeScalingProcessTypesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// ScheduledUpdateGroupAction contains the information to be used in a scheduled update to an
// AutoScalingGroup
//
// See http://goo.gl/z2Kfxe for more details
type ScheduledUpdateGroupAction struct {
	AutoScalingGroupName string    `xml:"AutoScalingGroupName"`
	DesiredCapacity      int       `xml:"DesiredCapacity"`
	EndTime              time.Time `xml:"EndTime"`
	MaxSize              int       `xml:"MaxSize"`
	MinSize              int       `xml:"MinSize"`
	Recurrence           string    `xml:"Recurrence"`
	ScheduledActionARN   string    `xml:"ScheduledActionARN"`
	ScheduledActionName  string    `xml:"ScheduledActionName"`
	StartTime            time.Time `xml:"StartTime"`
	Time                 time.Time `xml:"Time"`
}

// DescribeScheduledActionsResult contains the response from a DescribeScheduledActions.
//
// See http://goo.gl/zqrJLx for more details.
type DescribeScheduledActionsResult struct {
	ScheduledUpdateGroupActions []ScheduledUpdateGroupAction `xml:"DescribeScheduledActionsResult>ScheduledUpdateGroupActions>member"`
	NextToken                   string                       `xml:"DescribeScheduledActionsResult>NextToken"`
	RequestId                   string                       `xml:"ResponseMetadata>RequestId"`
}

// ScheduledActionsRequestParams contains the items that can be specified when making
// a ScheduledActions request
type DescribeScheduledActionsParams struct {
	AutoScalingGroupName string
	EndTime              time.Time
	MaxRecords           int
	ScheduledActionNames []string
	StartTime            time.Time
	NextToken            string
}

// DescribeScheduledActions returns a list of the current scheduled actions. If the
// AutoScalingGroup name is provided it will list all the scheduled actions for that group.
//
// See http://goo.gl/zqrJLx for more details.
func (as *AutoScaling) DescribeScheduledActions(options *DescribeScheduledActionsParams) (
	resp *DescribeScheduledActionsResult, err error) {
	params := makeParams("DescribeScheduledActions")

	if options.AutoScalingGroupName != "" {
		params["AutoScalingGroupName"] = options.AutoScalingGroupName
	}
	if !options.StartTime.IsZero() {
		params["StartTime"] = options.StartTime.Format(time.RFC3339)
	}
	if !options.EndTime.IsZero() {
		params["EndTime"] = options.EndTime.Format(time.RFC3339)
	}
	if options.MaxRecords > 0 {
		params["MaxRecords"] = strconv.Itoa(options.MaxRecords)
	}
	if options.NextToken != "" {
		params["NextToken"] = options.NextToken
	}
	if len(options.ScheduledActionNames) > 0 {
		addParamsList(params, "ScheduledActionNames.member", options.ScheduledActionNames)
	}

	resp = new(DescribeScheduledActionsResult)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DescribeTags response wrapper
//
// See http://goo.gl/ZTEU3G for more details.
type DescribeTagsResp struct {
	Tags      []Tag  `xml:"DescribeTagsResult>Tags>member"`
	NextToken string `xml:"DescribeTagsResult>NextToken"`
	RequestId string `xml:"ResponseMetadata>RequestId"`
}

// DescribeTags lists the Auto Scaling group tags.
// Supports pagination by using the returned "NextToken" parameter for subsequent calls
//
// See http://goo.gl/ZTEU3G for more details.
func (as *AutoScaling) DescribeTags(filter *Filter, maxRecords int, nextToken string) (
	resp *DescribeTagsResp, err error) {
	params := makeParams("DescribeTags")

	if maxRecords != 0 {
		params["MaxRecords"] = strconv.Itoa(maxRecords)
	}
	if nextToken != "" {
		params["NextToken"] = nextToken
	}

	filter.addParams(params)

	resp = new(DescribeTagsResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DescribeTerminationPolicyTypes response wrapper
//
// See http://goo.gl/ZTEU3G for more details.
type DescribeTerminationPolicyTypesResp struct {
	TerminationPolicyTypes []string `xml:"DescribeTerminationPolicyTypesResult>TerminationPolicyTypes>member"`
	RequestId              string   `xml:"ResponseMetadata>RequestId"`
}

// DescribeTerminationPolicyTypes returns a list of all termination policies supported by Auto Scaling
//
// See http://goo.gl/ZTEU3G for more details.
func (as *AutoScaling) DescribeTerminationPolicyTypes() (resp *DescribeTerminationPolicyTypesResp, err error) {
	params := makeParams("DescribeTerminationPolicyTypes")

	resp = new(DescribeTerminationPolicyTypesResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DetachInstancesResult wraps a DetachInstances response
type DetachInstancesResult struct {
	Activities []Activity `xml:"DetachInstancesResult>Activities>member"`
	RequestId  string     `xml:"ResponseMetadata>RequestId"`
}

// DetachInstances removes an instance from an Auto Scaling group
//
// See http://goo.gl/cNwrqF for more details
func (as *AutoScaling) DetachInstances(asgName string, instanceIds []string, decrementCapacity bool) (
	resp *DetachInstancesResult, err error) {
	params := makeParams("DetachInstances")
	params["AutoScalingGroupName"] = asgName
	params["ShouldDecrementDesiredCapacity"] = strconv.FormatBool(decrementCapacity)

	if len(instanceIds) > 0 {
		addParamsList(params, "InstanceIds.member", instanceIds)
	}

	resp = new(DetachInstancesResult)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// DisableMetricsCollection disables monitoring of group metrics for the Auto Scaling group specified in asgName.
// You can specify the list of affected metrics with the metrics parameter. If no metrics are specified, all metrics are disabled
//
// See http://goo.gl/kAvzQw for more details.
func (as *AutoScaling) DisableMetricsCollection(asgName string, metrics []string) (
	resp *SimpleResp, err error) {
	params := makeParams("DisableMetricsCollection")
	params["AutoScalingGroupName"] = asgName

	if len(metrics) > 0 {
		addParamsList(params, "Metrics.member", metrics)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// EnableMetricsCollection enables monitoring of group metrics for the Auto Scaling group specified in asNmae.
// You can specify the list of affected metrics with the metrics parameter.
// Auto Scaling metrics collection can be turned on only if the InstanceMonitoring flag is set to true.
// Currently, the only legal granularity is "1Minute".
//
// See http://goo.gl/UcVDWn for more details.
func (as *AutoScaling) EnableMetricsCollection(asgName string, metrics []string, granularity string) (
	resp *SimpleResp, err error) {
	params := makeParams("EnableMetricsCollection")
	params["AutoScalingGroupName"] = asgName
	params["Granularity"] = granularity

	if len(metrics) > 0 {
		addParamsList(params, "Metrics.member", metrics)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// EnterStandbyResult wraps an EnterStandby response
type EnterStandbyResult struct {
	Activities []Activity `xml:"EnterStandbyResult>Activities>member"`
	RequestId  string     `xml:"ResponseMetadata>RequestId"`
}

// EnterStandby moves instances in an Auto Scaling group into a Standby mode.
//
// See http://goo.gl/BJ3lXs for more information
func (as *AutoScaling) EnterStandby(asgName string, instanceIds []string, decrementCapacity bool) (
	resp *EnterStandbyResult, err error) {
	params := makeParams("EnterStandby")
	params["AutoScalingGroupName"] = asgName
	params["ShouldDecrementDesiredCapacity"] = strconv.FormatBool(decrementCapacity)

	if len(instanceIds) > 0 {
		addParamsList(params, "InstanceIds.member", instanceIds)
	}

	resp = new(EnterStandbyResult)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// ExecutePolicy executes the specified policy.
//
// See http://goo.gl/BxHpFc for more details.
func (as *AutoScaling) ExecutePolicy(policyName string, asgName string, honorCooldown bool) (
	resp *SimpleResp, err error) {
	params := makeParams("ExecutePolicy")
	params["PolicyName"] = policyName

	if asgName != "" {
		params["AutoScalingGroupName"] = asgName
	}
	if honorCooldown {
		params["HonorCooldown"] = strconv.FormatBool(honorCooldown)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// ExitStandbyResult wraps an ExitStandby response
type ExitStandbyResult struct {
	Activities []Activity `xml:"ExitStandbyResult>Activities>member"`
	RequestId  string     `xml:"ResponseMetadata>RequestId"`
}

// ExitStandby moves an instance out of Standby mode.
//
// See http://goo.gl/9zQV4G for more information
func (as *AutoScaling) ExitStandby(asgName string, instanceIds []string) (
	resp *ExitStandbyResult, err error) {
	params := makeParams("ExitStandby")
	params["AutoScalingGroupName"] = asgName

	if len(instanceIds) > 0 {
		addParamsList(params, "InstanceIds.member", instanceIds)
	}

	resp = new(ExitStandbyResult)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// PutLifecycleHookParams wraps a PutLifecycleHook request
//
// See http://goo.gl/zsNqp5 for more details
type PutLifecycleHookParams struct {
	AutoScalingGroupName  string
	DefaultResult         string
	HeartbeatTimeout      int
	LifecycleHookName     string
	LifecycleTransition   string
	NotificationMetadata  string
	NotificationTargetARN string
	RoleARN               string
}

// PutLifecycleHook Creates or updates a lifecycle hook for an Auto Scaling Group.
//
// Part of the basic sequence for adding a lifecycle hook to an Auto Scaling group:
// 1) Create a notification target (SQS queue || SNS Topic)
// 2) Create an IAM role to allow the ASG topublish lifecycle notifications to the designated SQS queue or SNS topic
// 3) *** Create the lifecycle hook. You can create a hook that acts when instances launch or when instances terminate***
// 4) If necessary, record the lifecycle action heartbeat to keep the instance in a pending state
// 5) Complete the lifecycle action
//
// See http://goo.gl/9XrROq for more details.
func (as *AutoScaling) PutLifecycleHook(options *PutLifecycleHookParams) (
	resp *SimpleResp, err error) {
	params := makeParams("PutLifecycleHook")
	params["AutoScalingGroupName"] = options.AutoScalingGroupName
	params["LifecycleHookName"] = options.LifecycleHookName

	if options.DefaultResult != "" {
		params["DefaultResult"] = options.DefaultResult
	}
	if options.HeartbeatTimeout != 0 {
		params["HeartbeatTimeout"] = strconv.Itoa(options.HeartbeatTimeout)
	}
	if options.LifecycleTransition != "" {
		params["LifecycleTransition"] = options.LifecycleTransition
	}
	if options.NotificationMetadata != "" {
		params["NotificationMetadata"] = options.NotificationMetadata
	}
	if options.NotificationTargetARN != "" {
		params["NotificationTargetARN"] = options.NotificationTargetARN
	}
	if options.RoleARN != "" {
		params["RoleARN"] = options.RoleARN
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// PutNotificationConfiguration configures an Auto Scaling group to send notifications when specified events take place.
//
// See http://goo.gl/9XrROq for more details.
func (as *AutoScaling) PutNotificationConfiguration(asgName string, notificationTypes []string, topicARN string) (
	resp *SimpleResp, err error) {
	params := makeParams("PutNotificationConfiguration")
	params["AutoScalingGroupName"] = asgName
	params["TopicARN"] = topicARN

	if len(notificationTypes) > 0 {
		addParamsList(params, "NotificationTypes.member", notificationTypes)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// PutScalingPolicyParams wraps a PutScalingPolicyParams request
//
// See http://goo.gl/o0E8hl for more details.
type PutScalingPolicyParams struct {
	AutoScalingGroupName string
	PolicyName           string
	ScalingAdjustment    int
	AdjustmentType       string
	Cooldown             int
	MinAdjustmentStep    int
}

// PutScalingPolicy response wrapper
//
// See http://goo.gl/o0E8hl for more details.
type PutScalingPolicyResp struct {
	PolicyARN string `xml:"PutScalingPolicyResult>PolicyARN"`
	RequestId string `xml:"ResponseMetadata>RequestId"`
}

// PutScalingPolicy creates or updates a policy for an Auto Scaling group
//
// See http://goo.gl/o0E8hl for more details.
func (as *AutoScaling) PutScalingPolicy(options *PutScalingPolicyParams) (
	resp *PutScalingPolicyResp, err error) {
	params := makeParams("PutScalingPolicy")
	params["AutoScalingGroupName"] = options.AutoScalingGroupName
	params["PolicyName"] = options.PolicyName
	params["ScalingAdjustment"] = strconv.Itoa(options.ScalingAdjustment)
	params["AdjustmentType"] = options.AdjustmentType

	if options.Cooldown != 0 {
		params["Cooldown"] = strconv.Itoa(options.Cooldown)
	}
	if options.MinAdjustmentStep != 0 {
		params["MinAdjustmentStep"] = strconv.Itoa(options.MinAdjustmentStep)
	}

	resp = new(PutScalingPolicyResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// PutScheduledUpdateGroupActionParams contains the details of the ScheduledAction to be added.
//
// See http://goo.gl/sLPi0d for more details
type PutScheduledUpdateGroupActionParams struct {
	AutoScalingGroupName string
	DesiredCapacity      int
	EndTime              time.Time
	MaxSize              int
	MinSize              int
	Recurrence           string
	ScheduledActionName  string
	StartTime            time.Time
}

// PutScheduledUpdateGroupAction creates or updates a scheduled scaling action for an
// AutoScaling group. Scheduled actions can be made up to thirty days in advance. When updating
// a scheduled scaling action, if you leave a parameter unspecified, the corresponding value
// remains unchanged in the affected AutoScaling group.
//
// Auto Scaling supports the date and time expressed in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT
// only.
//
// See http://goo.gl/sLPi0d for more details.
func (as *AutoScaling) PutScheduledUpdateGroupAction(options *PutScheduledUpdateGroupActionParams) (
	resp *SimpleResp, err error) {
	params := makeParams("PutScheduledUpdateGroupAction")
	params["AutoScalingGroupName"] = options.AutoScalingGroupName
	params["ScheduledActionName"] = options.ScheduledActionName
	params["MinSize"] = strconv.Itoa(options.MinSize)
	params["MaxSize"] = strconv.Itoa(options.MaxSize)
	params["DesiredCapacity"] = strconv.Itoa(options.DesiredCapacity)

	if !options.StartTime.IsZero() {
		params["StartTime"] = options.StartTime.Format(time.RFC3339)
	}
	if !options.EndTime.IsZero() {
		params["EndTime"] = options.EndTime.Format(time.RFC3339)
	}
	if options.Recurrence != "" {
		params["Recurrence"] = options.Recurrence
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// RecordLifecycleActionHeartbeat ecords a heartbeat for the lifecycle action associated with a specific token.
// This extends the timeout by the length of time defined by the HeartbeatTimeout parameter of the
// PutLifecycleHook operation.
//
// Part of the basic sequence for adding a lifecycle hook to an Auto Scaling group:
// 1) Create a notification target (SQS queue || SNS Topic)
// 2) Create an IAM role to allow the ASG topublish lifecycle notifications to the designated SQS queue or SNS topic
// 3) Create the lifecycle hook. You can create a hook that acts when instances launch or when instances terminate
// 4) ***If necessary, record the lifecycle action heartbeat to keep the instance in a pending state***
// 5) Complete the lifecycle action
//
// See http://goo.gl/jc70xp for more details.
func (as *AutoScaling) RecordLifecycleActionHeartbeat(asgName, lifecycleActionToken, hookName string) (
	resp *SimpleResp, err error) {
	params := makeParams("RecordLifecycleActionHeartbeat")
	params["AutoScalingGroupName"] = asgName
	params["LifecycleActionToken"] = lifecycleActionToken
	params["LifecycleHookName"] = hookName

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// ResumeProcesses resumes the scaling processes for the scaling group. If no processes are
// provided, all processes are resumed.
//
// See http://goo.gl/XWIIg1 for more details.
func (as *AutoScaling) ResumeProcesses(asgName string, processes []string) (
	resp *SimpleResp, err error) {
	params := makeParams("ResumeProcesses")
	params["AutoScalingGroupName"] = asgName

	if len(processes) > 0 {
		addParamsList(params, "ScalingProcesses.member", processes)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// SetDesiredCapacity changes the DesiredCapacity of an AutoScaling group.
//
// See http://goo.gl/3WGZbI for more details.
func (as *AutoScaling) SetDesiredCapacity(asgName string, desiredCapacity int, honorCooldown bool) (
	resp *SimpleResp, err error) {
	params := makeParams("SetDesiredCapacity")
	params["AutoScalingGroupName"] = asgName
	params["DesiredCapacity"] = strconv.Itoa(desiredCapacity)
	params["HonorCooldown"] = strconv.FormatBool(honorCooldown)

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// SetInstanceHealth sets the health status of a specified instance that belongs to any of your Auto Scaling groups.
//
// See http://goo.gl/j4ZRxh for more details.
func (as *AutoScaling) SetInstanceHealth(id string, healthStatus string, respectGracePeriod bool) (
	resp *SimpleResp, err error) {
	params := makeParams("SetInstanceHealth")
	params["HealthStatus"] = healthStatus
	params["InstanceId"] = id
	// Default is true
	params["ShouldRespectGracePeriod"] = strconv.FormatBool(respectGracePeriod)

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// SuspendProcesses suspends the processes for the autoscaling group. If no processes are
// provided, all processes are suspended.
//
// If you suspend either of the two primary processes (Launch or Terminate), this can prevent other
// process types from functioning properly.
//
// See http://goo.gl/DUJpQy for more details.
func (as *AutoScaling) SuspendProcesses(asgName string, processes []string) (
	resp *SimpleResp, err error) {
	params := makeParams("SuspendProcesses")
	params["AutoScalingGroupName"] = asgName

	if len(processes) > 0 {
		addParamsList(params, "ScalingProcesses.member", processes)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// TerminateInstanceInAutoScalingGroupResp response wrapper
//
// See http://goo.gl/ki5hMh for more details.
type TerminateInstanceInAutoScalingGroupResp struct {
	Activity  Activity `xml:"TerminateInstanceInAutoScalingGroupResult>Activity"`
	RequestId string   `xml:"ResponseMetadata>RequestId"`
}

// TerminateInstanceInAutoScalingGroup terminates the specified instance.
// Optionally, the desired group size can be adjusted by setting decrCap to true
//
// See http://goo.gl/ki5hMh for more details.
func (as *AutoScaling) TerminateInstanceInAutoScalingGroup(id string, decrCap bool) (
	resp *TerminateInstanceInAutoScalingGroupResp, err error) {
	params := makeParams("TerminateInstanceInAutoScalingGroup")
	params["InstanceId"] = id
	params["ShouldDecrementDesiredCapacity"] = strconv.FormatBool(decrCap)

	resp = new(TerminateInstanceInAutoScalingGroupResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}

// UpdateAutoScalingGroup updates the scaling group.
//
// To update an auto scaling group with a launch configuration that has the InstanceMonitoring
// flag set to False, you must first ensure that collection of group metrics is disabled.
// Otherwise calls to UpdateAutoScalingGroup will fail.
//
// See http://goo.gl/rqrmxy for more details.
func (as *AutoScaling) UpdateAutoScalingGroup(asg *AutoScalingGroup) (resp *SimpleResp, err error) {
	params := makeParams("UpdateAutoScalingGroup")

	params["AutoScalingGroupName"] = asg.AutoScalingGroupName
	params["MaxSize"] = strconv.Itoa(asg.MaxSize)
	params["MinSize"] = strconv.Itoa(asg.MinSize)
	params["DesiredCapacity"] = strconv.Itoa(asg.DesiredCapacity)

	if asg.DefaultCooldown > 0 {
		params["DefaultCooldown"] = strconv.Itoa(asg.DefaultCooldown)
	}
	if asg.HealthCheckGracePeriod > 0 {
		params["HealthCheckGracePeriod"] = strconv.Itoa(asg.HealthCheckGracePeriod)
	}
	if asg.HealthCheckType != "" {
		params["HealthCheckType"] = asg.HealthCheckType
	}
	if asg.LaunchConfigurationName != "" {
		params["LaunchConfigurationName"] = asg.LaunchConfigurationName
	}
	if asg.PlacementGroup != "" {
		params["PlacementGroup"] = asg.PlacementGroup
	}
	if asg.VPCZoneIdentifier != "" {
		params["VPCZoneIdentifier"] = asg.VPCZoneIdentifier
	}

	if len(asg.AvailabilityZones) > 0 {
		addParamsList(params, "AvailabilityZones.member", asg.AvailabilityZones)
	}
	if len(asg.TerminationPolicies) > 0 {
		addParamsList(params, "TerminationPolicies.member", asg.TerminationPolicies)
	}

	resp = new(SimpleResp)
	if err := as.query(params, resp); err != nil {
		return nil, err
	}
	return resp, nil
}