1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ec2.go 87.31 KB
一键复制 编辑 原始数据 按行查看 历史
Thom May 提交于 2015-01-09 17:24 . Update to latest goamz
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087
//
// goamz - Go packages to interact with the Amazon Web Services.
//
// https://wiki.ubuntu.com/goamz
//
// Copyright (c) 2011 Canonical Ltd.
//
// Written by Gustavo Niemeyer <gustavo.niemeyer@canonical.com>
//
package ec2
import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"encoding/xml"
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"sort"
"strconv"
"strings"
"time"
"github.com/mitchellh/goamz/aws"
)
const debug = false
// The EC2 type encapsulates operations with a specific EC2 region.
type EC2 struct {
aws.Auth
aws.Region
httpClient *http.Client
private byte // Reserve the right of using private data.
}
// New creates a new EC2.
func NewWithClient(auth aws.Auth, region aws.Region, client *http.Client) *EC2 {
return &EC2{auth, region, client, 0}
}
func New(auth aws.Auth, region aws.Region) *EC2 {
return NewWithClient(auth, region, aws.RetryingClient)
}
// ----------------------------------------------------------------------------
// Filtering helper.
// Filter builds filtering parameters to be used in an EC2 query which supports
// filtering. For example:
//
// filter := NewFilter()
// filter.Add("architecture", "i386")
// filter.Add("launch-index", "0")
// resp, err := ec2.Instances(nil, filter)
//
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 := "Filter." + strconv.Itoa(i+1)
params[prefix+".Name"] = k
for j, v := range f.m[k] {
params[prefix+".Value."+strconv.Itoa(j+1)] = v
}
}
}
}
// ----------------------------------------------------------------------------
// Request dispatching logic.
// Error encapsulates an error returned by EC2.
//
// See http://goo.gl/VZGuC for more details.
type Error struct {
// HTTP status code (200, 403, ...)
StatusCode int
// EC2 error code ("UnsupportedOperation", ...)
Code 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)
}
// For now a single error inst is being exposed. In the future it may be useful
// to provide access to all of them, but rather than doing it as an array/slice,
// use a *next pointer, so that it's backward compatible and it continues to be
// easy to handle the first error, which is what most people will want.
type xmlErrors struct {
RequestId string `xml:"RequestID"`
Errors []Error `xml:"Errors>Error"`
}
var timeNow = time.Now
func (ec2 *EC2) query(params map[string]string, resp interface{}) error {
params["Version"] = "2014-06-15"
params["Timestamp"] = timeNow().In(time.UTC).Format(time.RFC3339)
endpoint, err := url.Parse(ec2.Region.EC2Endpoint)
if err != nil {
return err
}
if endpoint.Path == "" {
endpoint.Path = "/"
}
sign(ec2.Auth, "GET", endpoint.Path, params, endpoint.Host)
endpoint.RawQuery = multimap(params).Encode()
if debug {
log.Printf("get { %v } -> {\n", endpoint.String())
}
r, err := ec2.httpClient.Get(endpoint.String())
if err != nil {
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 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 buildError(r *http.Response) error {
errors := xmlErrors{}
xml.NewDecoder(r.Body).Decode(&errors)
var err Error
if len(errors.Errors) > 0 {
err = errors.Errors[0]
}
err.RequestId = errors.RequestId
err.StatusCode = r.StatusCode
if err.Message == "" {
err.Message = err.Code
}
return &err
}
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
}
}
func addBlockDeviceParams(prename string, params map[string]string, blockdevices []BlockDeviceMapping) {
for i, k := range blockdevices {
// Fixup index since Amazon counts these from 1
prefix := prename + "BlockDeviceMapping." + strconv.Itoa(i+1) + "."
if k.DeviceName != "" {
params[prefix+"DeviceName"] = k.DeviceName
}
if k.VirtualName != "" {
params[prefix+"VirtualName"] = k.VirtualName
} else if k.NoDevice {
params[prefix+"NoDevice"] = ""
} else {
if k.SnapshotId != "" {
params[prefix+"Ebs.SnapshotId"] = k.SnapshotId
}
if k.VolumeType != "" {
params[prefix+"Ebs.VolumeType"] = k.VolumeType
}
if k.IOPS != 0 {
params[prefix+"Ebs.Iops"] = strconv.FormatInt(k.IOPS, 10)
}
if k.VolumeSize != 0 {
params[prefix+"Ebs.VolumeSize"] = strconv.FormatInt(k.VolumeSize, 10)
}
if k.DeleteOnTermination {
params[prefix+"Ebs.DeleteOnTermination"] = "true"
} else {
params[prefix+"Ebs.DeleteOnTermination"] = "false"
}
if k.Encrypted {
params[prefix+"Ebs.Encrypted"] = "true"
}
}
}
}
// ----------------------------------------------------------------------------
// Instance management functions and types.
// The RunInstances type encapsulates options for the respective request in EC2.
//
// See http://goo.gl/Mcm3b for more details.
type RunInstances struct {
ImageId string
MinCount int
MaxCount int
KeyName string
InstanceType string
SecurityGroups []SecurityGroup
IamInstanceProfile string
KernelId string
RamdiskId string
UserData []byte
AvailZone string
PlacementGroupName string
Monitoring bool
SubnetId string
AssociatePublicIpAddress bool
DisableAPITermination bool
EbsOptimized bool
ShutdownBehavior string
PrivateIPAddress string
BlockDevices []BlockDeviceMapping
Tenancy string
}
// Response to a RunInstances request.
//
// See http://goo.gl/Mcm3b for more details.
type RunInstancesResp struct {
RequestId string `xml:"requestId"`
ReservationId string `xml:"reservationId"`
OwnerId string `xml:"ownerId"`
SecurityGroups []SecurityGroup `xml:"groupSet>item"`
Instances []Instance `xml:"instancesSet>item"`
}
// BlockDevice represents the association of a block device with an instance.
type BlockDevice struct {
DeviceName string `xml:"deviceName"`
VolumeId string `xml:"ebs>volumeId"`
Status string `xml:"ebs>status"`
AttachTime string `xml:"ebs>attachTime"`
DeleteOnTermination bool `xml:"ebs>deleteOnTermination"`
}
// Instance encapsulates a running instance in EC2.
//
// See http://goo.gl/OCH8a for more details.
type Instance struct {
InstanceId string `xml:"instanceId"`
InstanceType string `xml:"instanceType"`
ImageId string `xml:"imageId"`
PrivateDNSName string `xml:"privateDnsName"`
DNSName string `xml:"dnsName"`
KeyName string `xml:"keyName"`
AMILaunchIndex int `xml:"amiLaunchIndex"`
Hypervisor string `xml:"hypervisor"`
VirtType string `xml:"virtualizationType"`
Monitoring string `xml:"monitoring>state"`
AvailZone string `xml:"placement>availabilityZone"`
Tenancy string `xml:"placement>tenancy"`
PlacementGroupName string `xml:"placement>groupName"`
State InstanceState `xml:"instanceState"`
Tags []Tag `xml:"tagSet>item"`
VpcId string `xml:"vpcId"`
SubnetId string `xml:"subnetId"`
IamInstanceProfile string `xml:"iamInstanceProfile"`
PrivateIpAddress string `xml:"privateIpAddress"`
PublicIpAddress string `xml:"ipAddress"`
Architecture string `xml:"architecture"`
LaunchTime time.Time `xml:"launchTime"`
SourceDestCheck bool `xml:"sourceDestCheck"`
SecurityGroups []SecurityGroup `xml:"groupSet>item"`
EbsOptimized string `xml:"ebsOptimized"`
BlockDevices []BlockDevice `xml:"blockDeviceMapping>item"`
}
// RunInstances starts new instances in EC2.
// If options.MinCount and options.MaxCount are both zero, a single instance
// will be started; otherwise if options.MaxCount is zero, options.MinCount
// will be used insteead.
//
// See http://goo.gl/Mcm3b for more details.
func (ec2 *EC2) RunInstances(options *RunInstances) (resp *RunInstancesResp, err error) {
params := makeParams("RunInstances")
params["ImageId"] = options.ImageId
params["InstanceType"] = options.InstanceType
var min, max int
if options.MinCount == 0 && options.MaxCount == 0 {
min = 1
max = 1
} else if options.MaxCount == 0 {
min = options.MinCount
max = min
} else {
min = options.MinCount
max = options.MaxCount
}
params["MinCount"] = strconv.Itoa(min)
params["MaxCount"] = strconv.Itoa(max)
token, err := clientToken()
if err != nil {
return nil, err
}
params["ClientToken"] = token
if options.KeyName != "" {
params["KeyName"] = options.KeyName
}
if options.KernelId != "" {
params["KernelId"] = options.KernelId
}
if options.RamdiskId != "" {
params["RamdiskId"] = options.RamdiskId
}
if options.UserData != nil {
userData := make([]byte, b64.EncodedLen(len(options.UserData)))
b64.Encode(userData, options.UserData)
params["UserData"] = string(userData)
}
if options.AvailZone != "" {
params["Placement.AvailabilityZone"] = options.AvailZone
}
if options.PlacementGroupName != "" {
params["Placement.GroupName"] = options.PlacementGroupName
}
if options.Monitoring {
params["Monitoring.Enabled"] = "true"
}
if options.Tenancy != "" {
params["Placement.Tenancy"] = options.Tenancy
}
if options.SubnetId != "" && options.AssociatePublicIpAddress {
// If we have a non-default VPC / Subnet specified, we can flag
// AssociatePublicIpAddress to get a Public IP assigned. By default these are not provided.
// You cannot specify both SubnetId and the NetworkInterface.0.* parameters though, otherwise
// you get: Network interfaces and an instance-level subnet ID may not be specified on the same request
// You also need to attach Security Groups to the NetworkInterface instead of the instance,
// to avoid: Network interfaces and an instance-level security groups may not be specified on
// the same request
params["NetworkInterface.0.DeviceIndex"] = "0"
params["NetworkInterface.0.AssociatePublicIpAddress"] = "true"
params["NetworkInterface.0.SubnetId"] = options.SubnetId
if options.PrivateIPAddress != "" {
params["NetworkInterface.0.PrivateIpAddress"] = options.PrivateIPAddress
}
i := 1
for _, g := range options.SecurityGroups {
// We only have SecurityGroupId's on NetworkInterface's, no SecurityGroup params.
if g.Id != "" {
params["NetworkInterface.0.SecurityGroupId."+strconv.Itoa(i)] = g.Id
i++
}
}
} else {
if options.SubnetId != "" {
params["SubnetId"] = options.SubnetId
}
if options.PrivateIPAddress != "" {
params["PrivateIpAddress"] = options.PrivateIPAddress
}
i, j := 1, 1
for _, g := range options.SecurityGroups {
if g.Id != "" {
params["SecurityGroupId."+strconv.Itoa(i)] = g.Id
i++
} else {
params["SecurityGroup."+strconv.Itoa(j)] = g.Name
j++
}
}
}
if options.IamInstanceProfile != "" {
params["IamInstanceProfile.Name"] = options.IamInstanceProfile
}
if options.DisableAPITermination {
params["DisableApiTermination"] = "true"
}
if options.EbsOptimized {
params["EbsOptimized"] = "true"
}
if options.ShutdownBehavior != "" {
params["InstanceInitiatedShutdownBehavior"] = options.ShutdownBehavior
}
addBlockDeviceParams("", params, options.BlockDevices)
resp = &RunInstancesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
func clientToken() (string, error) {
// Maximum EC2 client token size is 64 bytes.
// Each byte expands to two when hex encoded.
buf := make([]byte, 32)
_, err := rand.Read(buf)
if err != nil {
return "", err
}
return hex.EncodeToString(buf), nil
}
// The GetConsoleOutput type encapsulates options for the respective request in EC2.
//
// See http://goo.gl/EY70zb for more details.
type GetConsoleOutput struct {
InstanceId string
}
// Response to a GetConsoleOutput request. Note that Output is base64-encoded,
// as in the underlying AWS API.
//
// See http://goo.gl/EY70zb for more details.
type GetConsoleOutputResp struct {
RequestId string `xml:"requestId"`
InstanceId string `xml:"instanceId"`
Timestamp time.Time `xml:"timestamp"`
Output string `xml:"output"`
}
// GetConsoleOutput returns the console output for the sepcified instance. Note
// that console output is base64-encoded, as in the underlying AWS API.
//
// See http://goo.gl/EY70zb for more details.
func (ec2 *EC2) GetConsoleOutput(options *GetConsoleOutput) (resp *GetConsoleOutputResp, err error) {
params := makeParams("GetConsoleOutput")
params["InstanceId"] = options.InstanceId
resp = &GetConsoleOutputResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// Instance events and status functions and types.
// The DescribeInstanceStatus type encapsulates options for the respective request in EC2.
//
// See http://goo.gl/DFySJY for more details.
type EventsSet struct {
Code string `xml:"code"`
Description string `xml:"description"`
NotBefore string `xml:"notBefore"`
NotAfter string `xml:"notAfter"`
}
type StatusDetails struct {
Name string `xml:"name"`
Status string `xml:"status"`
ImpairedSince string `xml:"impairedSince"`
}
type Status struct {
Status string `xml:"status"`
Details []StatusDetails `xml:"details>item"`
}
type InstanceStatusSet struct {
InstanceId string `xml:"instanceId"`
AvailabilityZone string `xml:"availabilityZone"`
InstanceState InstanceState `xml:"instanceState"`
SystemStatus Status `xml:"systemStatus"`
InstanceStatus Status `xml:"instanceStatus"`
Events []EventsSet `xml:"eventsSet>item"`
}
type DescribeInstanceStatusResp struct {
RequestId string `xml:"requestId"`
InstanceStatus []InstanceStatusSet `xml:"instanceStatusSet>item"`
}
type DescribeInstanceStatus struct {
InstanceIds []string
IncludeAllInstances bool
MaxResults int64
NextToken string
}
func (ec2 *EC2) DescribeInstanceStatus(options *DescribeInstanceStatus, filter *Filter) (resp *DescribeInstanceStatusResp, err error) {
params := makeParams("DescribeInstanceStatus")
if options.IncludeAllInstances {
params["IncludeAllInstances"] = "true"
}
if len(options.InstanceIds) > 0 {
addParamsList(params, "InstanceId", options.InstanceIds)
}
if options.MaxResults > 0 {
params["MaxResults"] = strconv.FormatInt(options.MaxResults, 10)
}
if options.NextToken != "" {
params["NextToken"] = options.NextToken
}
if filter != nil {
filter.addParams(params)
}
resp = &DescribeInstanceStatusResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// Spot Instance management functions and types.
// The RequestSpotInstances type encapsulates options for the respective request in EC2.
//
// See http://goo.gl/GRZgCD for more details.
type RequestSpotInstances struct {
SpotPrice string
InstanceCount int
Type string
ImageId string
KeyName string
InstanceType string
SecurityGroups []SecurityGroup
IamInstanceProfile string
KernelId string
RamdiskId string
UserData []byte
AvailZone string
PlacementGroupName string
Monitoring bool
SubnetId string
AssociatePublicIpAddress bool
PrivateIPAddress string
BlockDevices []BlockDeviceMapping
}
type SpotInstanceSpec struct {
ImageId string
KeyName string
InstanceType string
SecurityGroups []SecurityGroup
IamInstanceProfile string
KernelId string
RamdiskId string
UserData []byte
AvailZone string
PlacementGroupName string
Monitoring bool
SubnetId string
AssociatePublicIpAddress bool
PrivateIPAddress string
BlockDevices []BlockDeviceMapping
}
type SpotLaunchSpec struct {
ImageId string `xml:"imageId"`
KeyName string `xml:"keyName"`
InstanceType string `xml:"instanceType"`
SecurityGroups []SecurityGroup `xml:"groupSet>item"`
IamInstanceProfile string `xml:"iamInstanceProfile"`
KernelId string `xml:"kernelId"`
RamdiskId string `xml:"ramdiskId"`
PlacementGroupName string `xml:"placement>groupName"`
Monitoring bool `xml:"monitoring>enabled"`
SubnetId string `xml:"subnetId"`
BlockDevices []BlockDeviceMapping `xml:"blockDeviceMapping>item"`
}
type SpotStatus struct {
Code string `xml:"code"`
UpdateTime string `xml:"updateTime"`
Message string `xml:"message"`
}
type SpotRequestResult struct {
SpotRequestId string `xml:"spotInstanceRequestId"`
SpotPrice string `xml:"spotPrice"`
Type string `xml:"type"`
AvailZone string `xml:"launchedAvailabilityZone"`
InstanceId string `xml:"instanceId"`
State string `xml:"state"`
Status SpotStatus `xml:"status"`
SpotLaunchSpec SpotLaunchSpec `xml:"launchSpecification"`
CreateTime string `xml:"createTime"`
Tags []Tag `xml:"tagSet>item"`
}
// Response to a RequestSpotInstances request.
//
// See http://goo.gl/GRZgCD for more details.
type RequestSpotInstancesResp struct {
RequestId string `xml:"requestId"`
SpotRequestResults []SpotRequestResult `xml:"spotInstanceRequestSet>item"`
}
// RequestSpotInstances requests a new spot instances in EC2.
func (ec2 *EC2) RequestSpotInstances(options *RequestSpotInstances) (resp *RequestSpotInstancesResp, err error) {
params := makeParams("RequestSpotInstances")
prefix := "LaunchSpecification" + "."
params["SpotPrice"] = options.SpotPrice
params[prefix+"ImageId"] = options.ImageId
params[prefix+"InstanceType"] = options.InstanceType
if options.InstanceCount != 0 {
params["InstanceCount"] = strconv.Itoa(options.InstanceCount)
}
if options.KeyName != "" {
params[prefix+"KeyName"] = options.KeyName
}
if options.KernelId != "" {
params[prefix+"KernelId"] = options.KernelId
}
if options.RamdiskId != "" {
params[prefix+"RamdiskId"] = options.RamdiskId
}
if options.UserData != nil {
userData := make([]byte, b64.EncodedLen(len(options.UserData)))
b64.Encode(userData, options.UserData)
params[prefix+"UserData"] = string(userData)
}
if options.AvailZone != "" {
params[prefix+"Placement.AvailabilityZone"] = options.AvailZone
}
if options.PlacementGroupName != "" {
params[prefix+"Placement.GroupName"] = options.PlacementGroupName
}
if options.Monitoring {
params[prefix+"Monitoring.Enabled"] = "true"
}
if options.SubnetId != "" && options.AssociatePublicIpAddress {
// If we have a non-default VPC / Subnet specified, we can flag
// AssociatePublicIpAddress to get a Public IP assigned. By default these are not provided.
// You cannot specify both SubnetId and the NetworkInterface.0.* parameters though, otherwise
// you get: Network interfaces and an instance-level subnet ID may not be specified on the same request
// You also need to attach Security Groups to the NetworkInterface instead of the instance,
// to avoid: Network interfaces and an instance-level security groups may not be specified on
// the same request
params[prefix+"NetworkInterface.0.DeviceIndex"] = "0"
params[prefix+"NetworkInterface.0.AssociatePublicIpAddress"] = "true"
params[prefix+"NetworkInterface.0.SubnetId"] = options.SubnetId
i := 1
for _, g := range options.SecurityGroups {
// We only have SecurityGroupId's on NetworkInterface's, no SecurityGroup params.
if g.Id != "" {
params[prefix+"NetworkInterface.0.SecurityGroupId."+strconv.Itoa(i)] = g.Id
i++
}
}
} else {
if options.SubnetId != "" {
params[prefix+"SubnetId"] = options.SubnetId
}
i, j := 1, 1
for _, g := range options.SecurityGroups {
if g.Id != "" {
params[prefix+"SecurityGroupId."+strconv.Itoa(i)] = g.Id
i++
} else {
params[prefix+"SecurityGroup."+strconv.Itoa(j)] = g.Name
j++
}
}
}
if options.IamInstanceProfile != "" {
params[prefix+"IamInstanceProfile.Name"] = options.IamInstanceProfile
}
if options.PrivateIPAddress != "" {
params[prefix+"PrivateIpAddress"] = options.PrivateIPAddress
}
addBlockDeviceParams(prefix, params, options.BlockDevices)
resp = &RequestSpotInstancesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Response to a DescribeSpotInstanceRequests request.
//
// See http://goo.gl/KsKJJk for more details.
type SpotRequestsResp struct {
RequestId string `xml:"requestId"`
SpotRequestResults []SpotRequestResult `xml:"spotInstanceRequestSet>item"`
}
// DescribeSpotInstanceRequests returns details about spot requests in EC2. Both parameters
// are optional, and if provided will limit the spot requests returned to those
// matching the given spot request ids or filtering rules.
//
// See http://goo.gl/KsKJJk for more details.
func (ec2 *EC2) DescribeSpotRequests(spotrequestIds []string, filter *Filter) (resp *SpotRequestsResp, err error) {
params := makeParams("DescribeSpotInstanceRequests")
addParamsList(params, "SpotInstanceRequestId", spotrequestIds)
filter.addParams(params)
resp = &SpotRequestsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Response to a CancelSpotInstanceRequests request.
//
// See http://goo.gl/3BKHj for more details.
type CancelSpotRequestResult struct {
SpotRequestId string `xml:"spotInstanceRequestId"`
State string `xml:"state"`
}
type CancelSpotRequestsResp struct {
RequestId string `xml:"requestId"`
CancelSpotRequestResults []CancelSpotRequestResult `xml:"spotInstanceRequestSet>item"`
}
// CancelSpotRequests requests the cancellation of spot requests when the given ids.
//
// See http://goo.gl/3BKHj for more details.
func (ec2 *EC2) CancelSpotRequests(spotrequestIds []string) (resp *CancelSpotRequestsResp, err error) {
params := makeParams("CancelSpotInstanceRequests")
addParamsList(params, "SpotInstanceRequestId", spotrequestIds)
resp = &CancelSpotRequestsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
type DescribeSpotPriceHistory struct {
InstanceType []string
ProductDescription []string
AvailabilityZone string
StartTime, EndTime time.Time
}
// Response to a DescribeSpotPriceHisotyr request.
//
// See http://goo.gl/3BKHj for more details.
type DescribeSpotPriceHistoryResp struct {
RequestId string `xml:"requestId"`
History []SpotPriceHistory `xml:"spotPriceHistorySet>item"`
}
type SpotPriceHistory struct {
InstanceType string `xml:"instanceType"`
ProductDescription string `xml:"productDescription"`
SpotPrice string `xml:"spotPrice"`
Timestamp time.Time `xml:"timestamp"`
AvailabilityZone string `xml:"availabilityZone"`
}
// DescribeSpotPriceHistory gets the spot pricing history.
//
// See http://goo.gl/3BKHj for more details.
func (ec2 *EC2) DescribeSpotPriceHistory(o *DescribeSpotPriceHistory) (resp *DescribeSpotPriceHistoryResp, err error) {
params := makeParams("DescribeSpotPriceHistory")
if o.AvailabilityZone != "" {
params["AvailabilityZone"] = o.AvailabilityZone
}
if !o.StartTime.IsZero() {
params["StartTime"] = o.StartTime.In(time.UTC).Format(time.RFC3339)
}
if !o.EndTime.IsZero() {
params["EndTime"] = o.EndTime.In(time.UTC).Format(time.RFC3339)
}
if len(o.InstanceType) > 0 {
addParamsList(params, "InstanceType", o.InstanceType)
}
if len(o.ProductDescription) > 0 {
addParamsList(params, "ProductDescription", o.ProductDescription)
}
resp = &DescribeSpotPriceHistoryResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Response to a TerminateInstances request.
//
// See http://goo.gl/3BKHj for more details.
type TerminateInstancesResp struct {
RequestId string `xml:"requestId"`
StateChanges []InstanceStateChange `xml:"instancesSet>item"`
}
// InstanceState encapsulates the state of an instance in EC2.
//
// See http://goo.gl/y3ZBq for more details.
type InstanceState struct {
Code int `xml:"code"` // Watch out, bits 15-8 have unpublished meaning.
Name string `xml:"name"`
}
// InstanceStateChange informs of the previous and current states
// for an instance when a state change is requested.
type InstanceStateChange struct {
InstanceId string `xml:"instanceId"`
CurrentState InstanceState `xml:"currentState"`
PreviousState InstanceState `xml:"previousState"`
}
// TerminateInstances requests the termination of instances when the given ids.
//
// See http://goo.gl/3BKHj for more details.
func (ec2 *EC2) TerminateInstances(instIds []string) (resp *TerminateInstancesResp, err error) {
params := makeParams("TerminateInstances")
addParamsList(params, "InstanceId", instIds)
resp = &TerminateInstancesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Response to a DescribeInstances request.
//
// See http://goo.gl/mLbmw for more details.
type InstancesResp struct {
RequestId string `xml:"requestId"`
Reservations []Reservation `xml:"reservationSet>item"`
}
// Reservation represents details about a reservation in EC2.
//
// See http://goo.gl/0ItPT for more details.
type Reservation struct {
ReservationId string `xml:"reservationId"`
OwnerId string `xml:"ownerId"`
RequesterId string `xml:"requesterId"`
SecurityGroups []SecurityGroup `xml:"groupSet>item"`
Instances []Instance `xml:"instancesSet>item"`
}
// Instances returns details about instances in EC2. Both parameters
// are optional, and if provided will limit the instances returned to those
// matching the given instance ids or filtering rules.
//
// See http://goo.gl/4No7c for more details.
func (ec2 *EC2) Instances(instIds []string, filter *Filter) (resp *InstancesResp, err error) {
params := makeParams("DescribeInstances")
addParamsList(params, "InstanceId", instIds)
filter.addParams(params)
resp = &InstancesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// Volume management
// The CreateVolume request parameters
//
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html
type CreateVolume struct {
AvailZone string
Size int64
SnapshotId string
VolumeType string
IOPS int64
Encrypted bool
}
// Response to an AttachVolume request
type AttachVolumeResp struct {
RequestId string `xml:"requestId"`
VolumeId string `xml:"volumeId"`
InstanceId string `xml:"instanceId"`
Device string `xml:"device"`
Status string `xml:"status"`
AttachTime string `xml:"attachTime"`
}
// Response to a CreateVolume request
type CreateVolumeResp struct {
RequestId string `xml:"requestId"`
VolumeId string `xml:"volumeId"`
Size int64 `xml:"size"`
SnapshotId string `xml:"snapshotId"`
AvailZone string `xml:"availabilityZone"`
Status string `xml:"status"`
CreateTime string `xml:"createTime"`
VolumeType string `xml:"volumeType"`
IOPS int64 `xml:"iops"`
Encrypted bool `xml:"encrypted"`
}
// Volume is a single volume.
type Volume struct {
VolumeId string `xml:"volumeId"`
Size string `xml:"size"`
SnapshotId string `xml:"snapshotId"`
AvailZone string `xml:"availabilityZone"`
Status string `xml:"status"`
Attachments []VolumeAttachment `xml:"attachmentSet>item"`
VolumeType string `xml:"volumeType"`
IOPS int64 `xml:"iops"`
Encrypted bool `xml:"encrypted"`
Tags []Tag `xml:"tagSet>item"`
}
type VolumeAttachment struct {
VolumeId string `xml:"volumeId"`
InstanceId string `xml:"instanceId"`
Device string `xml:"device"`
Status string `xml:"status"`
}
// Response to a DescribeVolumes request
type VolumesResp struct {
RequestId string `xml:"requestId"`
Volumes []Volume `xml:"volumeSet>item"`
}
// Attach a volume.
func (ec2 *EC2) AttachVolume(volumeId string, instanceId string, device string) (resp *AttachVolumeResp, err error) {
params := makeParams("AttachVolume")
params["VolumeId"] = volumeId
params["InstanceId"] = instanceId
params["Device"] = device
resp = &AttachVolumeResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Create a new volume.
func (ec2 *EC2) CreateVolume(options *CreateVolume) (resp *CreateVolumeResp, err error) {
params := makeParams("CreateVolume")
params["AvailabilityZone"] = options.AvailZone
if options.Size > 0 {
params["Size"] = strconv.FormatInt(options.Size, 10)
}
if options.SnapshotId != "" {
params["SnapshotId"] = options.SnapshotId
}
if options.VolumeType != "" {
params["VolumeType"] = options.VolumeType
}
if options.IOPS > 0 {
params["Iops"] = strconv.FormatInt(options.IOPS, 10)
}
if options.Encrypted {
params["Encrypted"] = "true"
}
resp = &CreateVolumeResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Delete an EBS volume.
func (ec2 *EC2) DeleteVolume(id string) (resp *SimpleResp, err error) {
params := makeParams("DeleteVolume")
params["VolumeId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Detaches an EBS volume.
func (ec2 *EC2) DetachVolume(id string) (resp *SimpleResp, err error) {
params := makeParams("DetachVolume")
params["VolumeId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Finds or lists all volumes.
func (ec2 *EC2) Volumes(volIds []string, filter *Filter) (resp *VolumesResp, err error) {
params := makeParams("DescribeVolumes")
addParamsList(params, "VolumeId", volIds)
filter.addParams(params)
resp = &VolumesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// Availability zone management functions and types.
// See http://goo.gl/ylxT4R for more details.
// DescribeAvailabilityZonesResp represents a response to a DescribeAvailabilityZones
// request in EC2.
type DescribeAvailabilityZonesResp struct {
RequestId string `xml:"requestId"`
Zones []AvailabilityZoneInfo `xml:"availabilityZoneInfo>item"`
}
// AvailabilityZoneInfo encapsulates details for an availability zone in EC2.
type AvailabilityZoneInfo struct {
AvailabilityZone
State string `xml:"zoneState"`
MessageSet []string `xml:"messageSet>item"`
}
// AvailabilityZone represents an EC2 availability zone.
type AvailabilityZone struct {
Name string `xml:"zoneName"`
Region string `xml:"regionName"`
}
// DescribeAvailabilityZones returns details about availability zones in EC2.
// The filter parameter is optional, and if provided will limit the
// availability zones returned to those matching the given filtering
// rules.
//
// See http://goo.gl/ylxT4R for more details.
func (ec2 *EC2) DescribeAvailabilityZones(filter *Filter) (resp *DescribeAvailabilityZonesResp, err error) {
params := makeParams("DescribeAvailabilityZones")
filter.addParams(params)
resp = &DescribeAvailabilityZonesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// ElasticIp management (for VPC)
// The AllocateAddress request parameters
//
// see http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-AllocateAddress.html
type AllocateAddress struct {
Domain string
}
// Response to an AllocateAddress request
type AllocateAddressResp struct {
RequestId string `xml:"requestId"`
PublicIp string `xml:"publicIp"`
Domain string `xml:"domain"`
AllocationId string `xml:"allocationId"`
}
// The AssociateAddress request parameters
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-AssociateAddress.html
type AssociateAddress struct {
InstanceId string
PublicIp string
AllocationId string
AllowReassociation bool
}
// Response to an AssociateAddress request
type AssociateAddressResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
AssociationId string `xml:"associationId"`
}
// Address represents an Elastic IP Address
// See http://goo.gl/uxCjp7 for more details
type Address struct {
PublicIp string `xml:"publicIp"`
AllocationId string `xml:"allocationId"`
Domain string `xml:"domain"`
InstanceId string `xml:"instanceId"`
AssociationId string `xml:"associationId"`
NetworkInterfaceId string `xml:"networkInterfaceId"`
NetworkInterfaceOwnerId string `xml:"networkInterfaceOwnerId"`
PrivateIpAddress string `xml:"privateIpAddress"`
}
type DescribeAddressesResp struct {
RequestId string `xml:"requestId"`
Addresses []Address `xml:"addressesSet>item"`
}
// Allocate a new Elastic IP.
func (ec2 *EC2) AllocateAddress(options *AllocateAddress) (resp *AllocateAddressResp, err error) {
params := makeParams("AllocateAddress")
params["Domain"] = options.Domain
resp = &AllocateAddressResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Release an Elastic IP (VPC).
func (ec2 *EC2) ReleaseAddress(id string) (resp *SimpleResp, err error) {
params := makeParams("ReleaseAddress")
params["AllocationId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Release an Elastic IP (Public)
func (ec2 *EC2) ReleasePublicAddress(publicIp string) (resp *SimpleResp, err error) {
params := makeParams("ReleaseAddress")
params["PublicIp"] = publicIp
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Associate an address with a VPC instance.
func (ec2 *EC2) AssociateAddress(options *AssociateAddress) (resp *AssociateAddressResp, err error) {
params := makeParams("AssociateAddress")
params["InstanceId"] = options.InstanceId
if options.PublicIp != "" {
params["PublicIp"] = options.PublicIp
}
if options.AllocationId != "" {
params["AllocationId"] = options.AllocationId
}
if options.AllowReassociation {
params["AllowReassociation"] = "true"
}
resp = &AssociateAddressResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Disassociate an address from a VPC instance.
func (ec2 *EC2) DisassociateAddress(id string) (resp *SimpleResp, err error) {
params := makeParams("DisassociateAddress")
params["AssociationId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Disassociate an address from a VPC instance.
func (ec2 *EC2) DisassociateAddressClassic(ip string) (resp *SimpleResp, err error) {
params := makeParams("DisassociateAddress")
params["PublicIp"] = ip
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// DescribeAddresses returns details about one or more
// Elastic IP Addresses. Returned addresses can be
// filtered by Public IP, Allocation ID or multiple filters
//
// See http://goo.gl/zW7J4p for more details.
func (ec2 *EC2) Addresses(publicIps []string, allocationIds []string, filter *Filter) (resp *DescribeAddressesResp, err error) {
params := makeParams("DescribeAddresses")
addParamsList(params, "PublicIp", publicIps)
addParamsList(params, "AllocationId", allocationIds)
filter.addParams(params)
resp = &DescribeAddressesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// Image and snapshot management functions and types.
// The CreateImage request parameters.
//
// See http://goo.gl/cxU41 for more details.
type CreateImage struct {
InstanceId string
Name string
Description string
NoReboot bool
BlockDevices []BlockDeviceMapping
}
// Response to a CreateImage request.
//
// See http://goo.gl/cxU41 for more details.
type CreateImageResp struct {
RequestId string `xml:"requestId"`
ImageId string `xml:"imageId"`
}
// Response to a DescribeImages request.
//
// See http://goo.gl/hLnyg for more details.
type ImagesResp struct {
RequestId string `xml:"requestId"`
Images []Image `xml:"imagesSet>item"`
}
// Response to a DescribeImageAttribute request.
//
// See http://goo.gl/bHO3zT for more details.
type ImageAttributeResp struct {
RequestId string `xml:"requestId"`
ImageId string `xml:"imageId"`
Kernel string `xml:"kernel>value"`
RamDisk string `xml:"ramdisk>value"`
Description string `xml:"description>value"`
Group string `xml:"launchPermission>item>group"`
UserIds []string `xml:"launchPermission>item>userId"`
ProductCodes []string `xml:"productCodes>item>productCode"`
BlockDevices []BlockDeviceMapping `xml:"blockDeviceMapping>item"`
}
// The RegisterImage request parameters.
type RegisterImage struct {
ImageLocation string
Name string
Description string
Architecture string
KernelId string
RamdiskId string
RootDeviceName string
VirtType string
SriovNetSupport string
BlockDevices []BlockDeviceMapping
}
// Response to a RegisterImage request.
type RegisterImageResp struct {
RequestId string `xml:"requestId"`
ImageId string `xml:"imageId"`
}
// Response to a DegisterImage request.
//
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeregisterImage.html
type DeregisterImageResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
}
// BlockDeviceMapping represents the association of a block device with an image.
//
// See http://goo.gl/wnDBf for more details.
type BlockDeviceMapping struct {
DeviceName string `xml:"deviceName"`
VirtualName string `xml:"virtualName"`
SnapshotId string `xml:"ebs>snapshotId"`
VolumeType string `xml:"ebs>volumeType"`
VolumeSize int64 `xml:"ebs>volumeSize"`
DeleteOnTermination bool `xml:"ebs>deleteOnTermination"`
Encrypted bool `xml:"ebs>encrypted"`
NoDevice bool `xml:"noDevice"`
// The number of I/O operations per second (IOPS) that the volume supports.
IOPS int64 `xml:"ebs>iops"`
}
// Image represents details about an image.
//
// See http://goo.gl/iSqJG for more details.
type Image struct {
Id string `xml:"imageId"`
Name string `xml:"name"`
Description string `xml:"description"`
Type string `xml:"imageType"`
State string `xml:"imageState"`
Location string `xml:"imageLocation"`
Public bool `xml:"isPublic"`
Architecture string `xml:"architecture"`
Platform string `xml:"platform"`
ProductCodes []string `xml:"productCode>item>productCode"`
KernelId string `xml:"kernelId"`
RamdiskId string `xml:"ramdiskId"`
StateReason string `xml:"stateReason"`
OwnerId string `xml:"imageOwnerId"`
OwnerAlias string `xml:"imageOwnerAlias"`
RootDeviceType string `xml:"rootDeviceType"`
RootDeviceName string `xml:"rootDeviceName"`
VirtualizationType string `xml:"virtualizationType"`
Hypervisor string `xml:"hypervisor"`
BlockDevices []BlockDeviceMapping `xml:"blockDeviceMapping>item"`
Tags []Tag `xml:"tagSet>item"`
}
// The ModifyImageAttribute request parameters.
type ModifyImageAttribute struct {
AddUsers []string
RemoveUsers []string
AddGroups []string
RemoveGroups []string
ProductCodes []string
Description string
}
// The CopyImage request parameters.
//
// See http://goo.gl/hQwPCK for more details.
type CopyImage struct {
SourceRegion string
SourceImageId string
Name string
Description string
ClientToken string
}
// Response to a CopyImage request.
//
// See http://goo.gl/hQwPCK for more details.
type CopyImageResp struct {
RequestId string `xml:"requestId"`
ImageId string `xml:"imageId"`
}
// Creates an Amazon EBS-backed AMI from an Amazon EBS-backed instance
// that is either running or stopped.
//
// See http://goo.gl/cxU41 for more details.
func (ec2 *EC2) CreateImage(options *CreateImage) (resp *CreateImageResp, err error) {
params := makeParams("CreateImage")
params["InstanceId"] = options.InstanceId
params["Name"] = options.Name
if options.Description != "" {
params["Description"] = options.Description
}
if options.NoReboot {
params["NoReboot"] = "true"
}
addBlockDeviceParams("", params, options.BlockDevices)
resp = &CreateImageResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Images returns details about available images.
// The ids and filter parameters, if provided, will limit the images returned.
// For example, to get all the private images associated with this account set
// the boolean filter "is-public" to 0.
// For list of filters: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html
//
// Note: calling this function with nil ids and filter parameters will result in
// a very large number of images being returned.
//
// See http://goo.gl/SRBhW for more details.
func (ec2 *EC2) Images(ids []string, filter *Filter) (resp *ImagesResp, err error) {
params := makeParams("DescribeImages")
for i, id := range ids {
params["ImageId."+strconv.Itoa(i+1)] = id
}
filter.addParams(params)
resp = &ImagesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ImagesByOwners returns details about available images.
// The ids, owners, and filter parameters, if provided, will limit the images returned.
// For example, to get all the private images associated with this account set
// the boolean filter "is-public" to 0.
// For list of filters: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html
//
// Note: calling this function with nil ids and filter parameters will result in
// a very large number of images being returned.
//
// See http://goo.gl/SRBhW for more details.
func (ec2 *EC2) ImagesByOwners(ids []string, owners []string, filter *Filter) (resp *ImagesResp, err error) {
params := makeParams("DescribeImages")
for i, id := range ids {
params["ImageId."+strconv.Itoa(i+1)] = id
}
for i, owner := range owners {
params[fmt.Sprintf("Owner.%d", i+1)] = owner
}
filter.addParams(params)
resp = &ImagesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ImageAttribute describes an attribute of an AMI.
// You can specify only one attribute at a time.
// Valid attributes are:
// description | kernel | ramdisk | launchPermission | productCodes | blockDeviceMapping
//
// See http://goo.gl/bHO3zT for more details.
func (ec2 *EC2) ImageAttribute(imageId, attribute string) (resp *ImageAttributeResp, err error) {
params := makeParams("DescribeImageAttribute")
params["ImageId"] = imageId
params["Attribute"] = attribute
resp = &ImageAttributeResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ModifyImageAttribute sets attributes for an image.
//
// See http://goo.gl/YUjO4G for more details.
func (ec2 *EC2) ModifyImageAttribute(imageId string, options *ModifyImageAttribute) (resp *SimpleResp, err error) {
params := makeParams("ModifyImageAttribute")
params["ImageId"] = imageId
if options.Description != "" {
params["Description.Value"] = options.Description
}
if options.AddUsers != nil {
for i, user := range options.AddUsers {
p := fmt.Sprintf("LaunchPermission.Add.%d.UserId", i+1)
params[p] = user
}
}
if options.RemoveUsers != nil {
for i, user := range options.RemoveUsers {
p := fmt.Sprintf("LaunchPermission.Remove.%d.UserId", i+1)
params[p] = user
}
}
if options.AddGroups != nil {
for i, group := range options.AddGroups {
p := fmt.Sprintf("LaunchPermission.Add.%d.Group", i+1)
params[p] = group
}
}
if options.RemoveGroups != nil {
for i, group := range options.RemoveGroups {
p := fmt.Sprintf("LaunchPermission.Remove.%d.Group", i+1)
params[p] = group
}
}
if options.ProductCodes != nil {
addParamsList(params, "ProductCode", options.ProductCodes)
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
resp = nil
}
return
}
// Registers a new AMI with EC2.
//
// See: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-RegisterImage.html
func (ec2 *EC2) RegisterImage(options *RegisterImage) (resp *RegisterImageResp, err error) {
params := makeParams("RegisterImage")
params["Name"] = options.Name
if options.ImageLocation != "" {
params["ImageLocation"] = options.ImageLocation
}
if options.Description != "" {
params["Description"] = options.Description
}
if options.Architecture != "" {
params["Architecture"] = options.Architecture
}
if options.KernelId != "" {
params["KernelId"] = options.KernelId
}
if options.RamdiskId != "" {
params["RamdiskId"] = options.RamdiskId
}
if options.RootDeviceName != "" {
params["RootDeviceName"] = options.RootDeviceName
}
if options.VirtType != "" {
params["VirtualizationType"] = options.VirtType
}
if options.SriovNetSupport != "" {
params["SriovNetSupport"] = "simple"
}
addBlockDeviceParams("", params, options.BlockDevices)
resp = &RegisterImageResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Degisters an image. Note that this does not delete the backing stores of the AMI.
//
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeregisterImage.html
func (ec2 *EC2) DeregisterImage(imageId string) (resp *DeregisterImageResp, err error) {
params := makeParams("DeregisterImage")
params["ImageId"] = imageId
resp = &DeregisterImageResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Copy and Image from one region to another.
//
// See http://goo.gl/hQwPCK for more details.
func (ec2 *EC2) CopyImage(options *CopyImage) (resp *CopyImageResp, err error) {
params := makeParams("CopyImage")
if options.SourceRegion != "" {
params["SourceRegion"] = options.SourceRegion
}
if options.SourceImageId != "" {
params["SourceImageId"] = options.SourceImageId
}
if options.Name != "" {
params["Name"] = options.Name
}
if options.Description != "" {
params["Description"] = options.Description
}
if options.ClientToken != "" {
params["ClientToken"] = options.ClientToken
}
resp = &CopyImageResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Response to a CreateSnapshot request.
//
// See http://goo.gl/ttcda for more details.
type CreateSnapshotResp struct {
RequestId string `xml:"requestId"`
Snapshot
}
// CreateSnapshot creates a volume snapshot and stores it in S3.
//
// See http://goo.gl/ttcda for more details.
func (ec2 *EC2) CreateSnapshot(volumeId, description string) (resp *CreateSnapshotResp, err error) {
params := makeParams("CreateSnapshot")
params["VolumeId"] = volumeId
params["Description"] = description
resp = &CreateSnapshotResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// DeleteSnapshots deletes the volume snapshots with the given ids.
//
// Note: If you make periodic snapshots of a volume, the snapshots are
// incremental so that only the blocks on the device that have changed
// since your last snapshot are incrementally saved in the new snapshot.
// Even though snapshots are saved incrementally, the snapshot deletion
// process is designed so that you need to retain only the most recent
// snapshot in order to restore the volume.
//
// See http://goo.gl/vwU1y for more details.
func (ec2 *EC2) DeleteSnapshots(ids []string) (resp *SimpleResp, err error) {
params := makeParams("DeleteSnapshot")
for i, id := range ids {
params["SnapshotId."+strconv.Itoa(i+1)] = id
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Response to a DescribeSnapshots request.
//
// See http://goo.gl/nClDT for more details.
type SnapshotsResp struct {
RequestId string `xml:"requestId"`
Snapshots []Snapshot `xml:"snapshotSet>item"`
}
// Snapshot represents details about a volume snapshot.
//
// See http://goo.gl/nkovs for more details.
type Snapshot struct {
Id string `xml:"snapshotId"`
VolumeId string `xml:"volumeId"`
VolumeSize string `xml:"volumeSize"`
Status string `xml:"status"`
StartTime string `xml:"startTime"`
Description string `xml:"description"`
Progress string `xml:"progress"`
OwnerId string `xml:"ownerId"`
OwnerAlias string `xml:"ownerAlias"`
Encrypted bool `xml:"encrypted"`
Tags []Tag `xml:"tagSet>item"`
}
// Snapshots returns details about volume snapshots available to the user.
// The ids and filter parameters, if provided, limit the snapshots returned.
//
// See http://goo.gl/ogJL4 for more details.
func (ec2 *EC2) Snapshots(ids []string, filter *Filter) (resp *SnapshotsResp, err error) {
params := makeParams("DescribeSnapshots")
for i, id := range ids {
params["SnapshotId."+strconv.Itoa(i+1)] = id
}
filter.addParams(params)
resp = &SnapshotsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ----------------------------------------------------------------------------
// KeyPair management functions and types.
type KeyPair struct {
Name string `xml:"keyName"`
Fingerprint string `xml:"keyFingerprint"`
}
type KeyPairsResp struct {
RequestId string `xml:"requestId"`
Keys []KeyPair `xml:"keySet>item"`
}
type CreateKeyPairResp struct {
RequestId string `xml:"requestId"`
KeyName string `xml:"keyName"`
KeyFingerprint string `xml:"keyFingerprint"`
KeyMaterial string `xml:"keyMaterial"`
}
type ImportKeyPairResponse struct {
RequestId string `xml:"requestId"`
KeyName string `xml:"keyName"`
KeyFingerprint string `xml:"keyFingerprint"`
}
// CreateKeyPair creates a new key pair and returns the private key contents.
//
// See http://goo.gl/0S6hV
func (ec2 *EC2) CreateKeyPair(keyName string) (resp *CreateKeyPairResp, err error) {
params := makeParams("CreateKeyPair")
params["KeyName"] = keyName
resp = &CreateKeyPairResp{}
err = ec2.query(params, resp)
if err == nil {
resp.KeyFingerprint = strings.TrimSpace(resp.KeyFingerprint)
}
return
}
// DeleteKeyPair deletes a key pair.
//
// See http://goo.gl/0bqok
func (ec2 *EC2) DeleteKeyPair(name string) (resp *SimpleResp, err error) {
params := makeParams("DeleteKeyPair")
params["KeyName"] = name
resp = &SimpleResp{}
err = ec2.query(params, resp)
return
}
// KeyPairs returns list of key pairs for this account
//
// See http://goo.gl/Apzsfz
func (ec2 *EC2) KeyPairs(keynames []string, filter *Filter) (resp *KeyPairsResp, err error) {
params := makeParams("DescribeKeyPairs")
for i, name := range keynames {
params["KeyName."+strconv.Itoa(i)] = name
}
filter.addParams(params)
resp = &KeyPairsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// ImportKeyPair imports a key into AWS
//
// See http://goo.gl/NbZUvw
func (ec2 *EC2) ImportKeyPair(keyname string, key string) (resp *ImportKeyPairResponse, err error) {
params := makeParams("ImportKeyPair")
params["KeyName"] = keyname
// Oddly, AWS requires the key material to be base64-encoded, even if it was
// already encoded. So, we force another round of encoding...
// c.f. https://groups.google.com/forum/?fromgroups#!topic/boto-dev/IczrStO9Q8M
params["PublicKeyMaterial"] = base64.StdEncoding.EncodeToString([]byte(key))
resp = &ImportKeyPairResponse{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// ----------------------------------------------------------------------------
// Security group management functions and types.
// SimpleResp represents a response to an EC2 request which on success will
// return no other information besides a request id.
type SimpleResp struct {
XMLName xml.Name
RequestId string `xml:"requestId"`
}
// CreateSecurityGroupResp represents a response to a CreateSecurityGroup request.
type CreateSecurityGroupResp struct {
SecurityGroup
RequestId string `xml:"requestId"`
}
// CreateSecurityGroup run a CreateSecurityGroup request in EC2, with the provided
// name and description.
//
// See http://goo.gl/Eo7Yl for more details.
func (ec2 *EC2) CreateSecurityGroup(group SecurityGroup) (resp *CreateSecurityGroupResp, err error) {
params := makeParams("CreateSecurityGroup")
params["GroupName"] = group.Name
params["GroupDescription"] = group.Description
if group.VpcId != "" {
params["VpcId"] = group.VpcId
}
resp = &CreateSecurityGroupResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
resp.Name = group.Name
return resp, nil
}
// SecurityGroupsResp represents a response to a DescribeSecurityGroups
// request in EC2.
//
// See http://goo.gl/k12Uy for more details.
type SecurityGroupsResp struct {
RequestId string `xml:"requestId"`
Groups []SecurityGroupInfo `xml:"securityGroupInfo>item"`
}
// SecurityGroup encapsulates details for a security group in EC2.
//
// See http://goo.gl/CIdyP for more details.
type SecurityGroupInfo struct {
SecurityGroup
OwnerId string `xml:"ownerId"`
Description string `xml:"groupDescription"`
IPPerms []IPPerm `xml:"ipPermissions>item"`
}
// IPPerm represents an allowance within an EC2 security group.
//
// See http://goo.gl/4oTxv for more details.
type IPPerm struct {
Protocol string `xml:"ipProtocol"`
FromPort int `xml:"fromPort"`
ToPort int `xml:"toPort"`
SourceIPs []string `xml:"ipRanges>item>cidrIp"`
SourceGroups []UserSecurityGroup `xml:"groups>item"`
}
// UserSecurityGroup holds a security group and the owner
// of that group.
type UserSecurityGroup struct {
Id string `xml:"groupId"`
Name string `xml:"groupName"`
OwnerId string `xml:"userId"`
}
// SecurityGroup represents an EC2 security group.
// If SecurityGroup is used as a parameter, then one of Id or Name
// may be empty. If both are set, then Id is used.
type SecurityGroup struct {
Id string `xml:"groupId"`
Name string `xml:"groupName"`
Description string `xml:"groupDescription"`
VpcId string `xml:"vpcId"`
Tags []Tag `xml:"tagSet>item"`
}
// SecurityGroupNames is a convenience function that
// returns a slice of security groups with the given names.
func SecurityGroupNames(names ...string) []SecurityGroup {
g := make([]SecurityGroup, len(names))
for i, name := range names {
g[i] = SecurityGroup{Name: name}
}
return g
}
// SecurityGroupNames is a convenience function that
// returns a slice of security groups with the given ids.
func SecurityGroupIds(ids ...string) []SecurityGroup {
g := make([]SecurityGroup, len(ids))
for i, id := range ids {
g[i] = SecurityGroup{Id: id}
}
return g
}
// SecurityGroups returns details about security groups in EC2. Both parameters
// are optional, and if provided will limit the security groups returned to those
// matching the given groups or filtering rules.
//
// See http://goo.gl/k12Uy for more details.
func (ec2 *EC2) SecurityGroups(groups []SecurityGroup, filter *Filter) (resp *SecurityGroupsResp, err error) {
params := makeParams("DescribeSecurityGroups")
i, j := 1, 1
for _, g := range groups {
if g.Id != "" {
params["GroupId."+strconv.Itoa(i)] = g.Id
i++
} else {
params["GroupName."+strconv.Itoa(j)] = g.Name
j++
}
}
filter.addParams(params)
resp = &SecurityGroupsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// DeleteSecurityGroup removes the given security group in EC2.
//
// See http://goo.gl/QJJDO for more details.
func (ec2 *EC2) DeleteSecurityGroup(group SecurityGroup) (resp *SimpleResp, err error) {
params := makeParams("DeleteSecurityGroup")
if group.Id != "" {
params["GroupId"] = group.Id
} else {
params["GroupName"] = group.Name
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// AuthorizeSecurityGroup creates an allowance for clients matching the provided
// rules to access instances within the given security group.
//
// See http://goo.gl/u2sDJ for more details.
func (ec2 *EC2) AuthorizeSecurityGroup(group SecurityGroup, perms []IPPerm) (resp *SimpleResp, err error) {
return ec2.authOrRevoke("AuthorizeSecurityGroupIngress", group, perms)
}
// AuthorizeSecurityGroupEgress creates an allowance for clients matching the provided
// rules for egress access.
//
// See http://goo.gl/UHnH4L for more details.
func (ec2 *EC2) AuthorizeSecurityGroupEgress(group SecurityGroup, perms []IPPerm) (resp *SimpleResp, err error) {
return ec2.authOrRevoke("AuthorizeSecurityGroupEgress", group, perms)
}
// RevokeSecurityGroup revokes permissions from a group.
//
// See http://goo.gl/ZgdxA for more details.
func (ec2 *EC2) RevokeSecurityGroup(group SecurityGroup, perms []IPPerm) (resp *SimpleResp, err error) {
return ec2.authOrRevoke("RevokeSecurityGroupIngress", group, perms)
}
func (ec2 *EC2) authOrRevoke(op string, group SecurityGroup, perms []IPPerm) (resp *SimpleResp, err error) {
params := makeParams(op)
if group.Id != "" {
params["GroupId"] = group.Id
} else {
params["GroupName"] = group.Name
}
for i, perm := range perms {
prefix := "IpPermissions." + strconv.Itoa(i+1)
params[prefix+".IpProtocol"] = perm.Protocol
params[prefix+".FromPort"] = strconv.Itoa(perm.FromPort)
params[prefix+".ToPort"] = strconv.Itoa(perm.ToPort)
for j, ip := range perm.SourceIPs {
params[prefix+".IpRanges."+strconv.Itoa(j+1)+".CidrIp"] = ip
}
for j, g := range perm.SourceGroups {
subprefix := prefix + ".Groups." + strconv.Itoa(j+1)
if g.OwnerId != "" {
params[subprefix+".UserId"] = g.OwnerId
}
if g.Id != "" {
params[subprefix+".GroupId"] = g.Id
} else {
params[subprefix+".GroupName"] = g.Name
}
}
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// ResourceTag represents key-value metadata used to classify and organize
// EC2 instances.
//
// See http://goo.gl/bncl3 for more details
type Tag struct {
Key string `xml:"key"`
Value string `xml:"value"`
}
// CreateTags adds or overwrites one or more tags for the specified taggable resources.
// For a list of tagable resources, see: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html
//
// See http://goo.gl/Vmkqc for more details
func (ec2 *EC2) CreateTags(resourceIds []string, tags []Tag) (resp *SimpleResp, err error) {
params := makeParams("CreateTags")
addParamsList(params, "ResourceId", resourceIds)
for j, tag := range tags {
params["Tag."+strconv.Itoa(j+1)+".Key"] = tag.Key
params["Tag."+strconv.Itoa(j+1)+".Value"] = tag.Value
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// DeleteTags deletes tags.
func (ec2 *EC2) DeleteTags(resourceIds []string, tags []Tag) (resp *SimpleResp, err error) {
params := makeParams("DeleteTags")
addParamsList(params, "ResourceId", resourceIds)
for j, tag := range tags {
params["Tag."+strconv.Itoa(j+1)+".Key"] = tag.Key
if tag.Value != "" {
params["Tag."+strconv.Itoa(j+1)+".Value"] = tag.Value
}
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
type TagsResp struct {
RequestId string `xml:"requestId"`
Tags []ResourceTag `xml:"tagSet>item"`
}
type ResourceTag struct {
Tag
ResourceId string `xml:"resourceId"`
ResourceType string `xml:"resourceType"`
}
func (ec2 *EC2) Tags(filter *Filter) (*TagsResp, error) {
params := makeParams("DescribeTags")
filter.addParams(params)
resp := &TagsResp{}
if err := ec2.query(params, resp); err != nil {
return nil, err
}
return resp, nil
}
// Response to a StartInstances request.
//
// See http://goo.gl/awKeF for more details.
type StartInstanceResp struct {
RequestId string `xml:"requestId"`
StateChanges []InstanceStateChange `xml:"instancesSet>item"`
}
// Response to a StopInstances request.
//
// See http://goo.gl/436dJ for more details.
type StopInstanceResp struct {
RequestId string `xml:"requestId"`
StateChanges []InstanceStateChange `xml:"instancesSet>item"`
}
// StartInstances starts an Amazon EBS-backed AMI that you've previously stopped.
//
// See http://goo.gl/awKeF for more details.
func (ec2 *EC2) StartInstances(ids ...string) (resp *StartInstanceResp, err error) {
params := makeParams("StartInstances")
addParamsList(params, "InstanceId", ids)
resp = &StartInstanceResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// StopInstances requests stopping one or more Amazon EBS-backed instances.
//
// See http://goo.gl/436dJ for more details.
func (ec2 *EC2) StopInstances(ids ...string) (resp *StopInstanceResp, err error) {
params := makeParams("StopInstances")
addParamsList(params, "InstanceId", ids)
resp = &StopInstanceResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// RebootInstance requests a reboot of one or more instances. This operation is asynchronous;
// it only queues a request to reboot the specified instance(s). The operation will succeed
// if the instances are valid and belong to you.
//
// Requests to reboot terminated instances are ignored.
//
// See http://goo.gl/baoUf for more details.
func (ec2 *EC2) RebootInstances(ids ...string) (resp *SimpleResp, err error) {
params := makeParams("RebootInstances")
addParamsList(params, "InstanceId", ids)
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// The ModifyInstanceAttribute request parameters.
type ModifyInstance struct {
InstanceType string
BlockDevices []BlockDeviceMapping
DisableAPITermination bool
EbsOptimized bool
SecurityGroups []SecurityGroup
ShutdownBehavior string
KernelId string
RamdiskId string
SourceDestCheck bool
SriovNetSupport bool
UserData []byte
SetSourceDestCheck bool
}
// Response to a ModifyInstanceAttribute request.
//
// http://goo.gl/icuXh5 for more details.
type ModifyInstanceResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
}
// ModifyImageAttribute modifies the specified attribute of the specified instance.
// You can specify only one attribute at a time. To modify some attributes, the
// instance must be stopped.
//
// See http://goo.gl/icuXh5 for more details.
func (ec2 *EC2) ModifyInstance(instId string, options *ModifyInstance) (resp *ModifyInstanceResp, err error) {
params := makeParams("ModifyInstanceAttribute")
params["InstanceId"] = instId
addBlockDeviceParams("", params, options.BlockDevices)
if options.InstanceType != "" {
params["InstanceType.Value"] = options.InstanceType
}
if options.DisableAPITermination {
params["DisableApiTermination.Value"] = "true"
}
if options.EbsOptimized {
params["EbsOptimized"] = "true"
}
if options.ShutdownBehavior != "" {
params["InstanceInitiatedShutdownBehavior.Value"] = options.ShutdownBehavior
}
if options.KernelId != "" {
params["Kernel.Value"] = options.KernelId
}
if options.RamdiskId != "" {
params["Ramdisk.Value"] = options.RamdiskId
}
if options.SourceDestCheck || options.SetSourceDestCheck {
if options.SourceDestCheck {
params["SourceDestCheck.Value"] = "true"
} else {
params["SourceDestCheck.Value"] = "false"
}
}
if options.SriovNetSupport {
params["SriovNetSupport.Value"] = "simple"
}
if options.UserData != nil {
userData := make([]byte, b64.EncodedLen(len(options.UserData)))
b64.Encode(userData, options.UserData)
params["UserData"] = string(userData)
}
i := 1
for _, g := range options.SecurityGroups {
if g.Id != "" {
params["GroupId."+strconv.Itoa(i)] = g.Id
i++
}
}
resp = &ModifyInstanceResp{}
err = ec2.query(params, resp)
if err != nil {
resp = nil
}
return
}
// ----------------------------------------------------------------------------
// VPC management functions and types.
// The CreateVpc request parameters
//
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVpc.html
type CreateVpc struct {
CidrBlock string
InstanceTenancy string
}
// Response to a CreateVpc request
type CreateVpcResp struct {
RequestId string `xml:"requestId"`
VPC VPC `xml:"vpc"`
}
// The ModifyVpcAttribute request parameters.
//
// See http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeVpcAttribute.html for more details.
type ModifyVpcAttribute struct {
EnableDnsSupport bool
EnableDnsHostnames bool
SetEnableDnsSupport bool
SetEnableDnsHostnames bool
}
// Response to a DescribeVpcAttribute request.
//
// See http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeVpcAttribute.html for more details.
type VpcAttributeResp struct {
RequestId string `xml:"requestId"`
VpcId string `xml:"vpcId"`
EnableDnsSupport bool `xml:"enableDnsSupport>value"`
EnableDnsHostnames bool `xml:"enableDnsHostnames>value"`
}
// CreateInternetGateway request parameters.
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateInternetGateway.html
type CreateInternetGateway struct{}
// CreateInternetGateway response
type CreateInternetGatewayResp struct {
RequestId string `xml:"requestId"`
InternetGateway InternetGateway `xml:"internetGateway"`
}
// The CreateRouteTable request parameters.
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateRouteTable.html
type CreateRouteTable struct {
VpcId string
}
// Response to a CreateRouteTable request.
type CreateRouteTableResp struct {
RequestId string `xml:"requestId"`
RouteTable RouteTable `xml:"routeTable"`
}
// CreateRoute request parameters
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateRoute.html
type CreateRoute struct {
RouteTableId string
DestinationCidrBlock string
GatewayId string
InstanceId string
NetworkInterfaceId string
VpcPeeringConnectionId string
}
type ReplaceRoute struct {
RouteTableId string
DestinationCidrBlock string
GatewayId string
InstanceId string
NetworkInterfaceId string
VpcPeeringConnectionId string
}
type AssociateRouteTableResp struct {
RequestId string `xml:"requestId"`
AssociationId string `xml:"associationId"`
}
type ReassociateRouteTableResp struct {
RequestId string `xml:"requestId"`
AssociationId string `xml:"newAssociationId"`
}
// The CreateSubnet request parameters
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSubnet.html
type CreateSubnet struct {
VpcId string
CidrBlock string
AvailabilityZone string
}
// Response to a CreateSubnet request
type CreateSubnetResp struct {
RequestId string `xml:"requestId"`
Subnet Subnet `xml:"subnet"`
}
// The ModifySubnetAttribute request parameters
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-ModifySubnetAttribute.html
type ModifySubnetAttribute struct {
SubnetId string
MapPublicIpOnLaunch bool
}
type ModifySubnetAttributeResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
}
// The CreateNetworkAcl request parameters
//
// http://goo.gl/BZmCRF
type CreateNetworkAcl struct {
VpcId string
}
// Response to a CreateNetworkAcl request
type CreateNetworkAclResp struct {
RequestId string `xml:"requestId"`
NetworkAcl NetworkAcl `xml:"networkAcl"`
}
// Response to CreateNetworkAclEntry request
type CreateNetworkAclEntryResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
}
// Response to a DescribeInternetGateways request.
type InternetGatewaysResp struct {
RequestId string `xml:"requestId"`
InternetGateways []InternetGateway `xml:"internetGatewaySet>item"`
}
// Response to a DescribeRouteTables request.
type RouteTablesResp struct {
RequestId string `xml:"requestId"`
RouteTables []RouteTable `xml:"routeTableSet>item"`
}
// Response to a DescribeVpcs request.
type VpcsResp struct {
RequestId string `xml:"requestId"`
VPCs []VPC `xml:"vpcSet>item"`
}
// Internet Gateway
type InternetGateway struct {
InternetGatewayId string `xml:"internetGatewayId"`
Attachments []InternetGatewayAttachment `xml:"attachmentSet>item"`
Tags []Tag `xml:"tagSet>item"`
}
type InternetGatewayAttachment struct {
VpcId string `xml:"vpcId"`
State string `xml:"state"`
}
// Routing Table
type RouteTable struct {
RouteTableId string `xml:"routeTableId"`
VpcId string `xml:"vpcId"`
Associations []RouteTableAssociation `xml:"associationSet>item"`
Routes []Route `xml:"routeSet>item"`
Tags []Tag `xml:"tagSet>item"`
}
type RouteTableAssociation struct {
AssociationId string `xml:"routeTableAssociationId"`
RouteTableId string `xml:"routeTableId"`
SubnetId string `xml:"subnetId"`
Main bool `xml:"main"`
}
type Route struct {
DestinationCidrBlock string `xml:"destinationCidrBlock"`
GatewayId string `xml:"gatewayId"`
InstanceId string `xml:"instanceId"`
InstanceOwnerId string `xml:"instanceOwnerId"`
NetworkInterfaceId string `xml:"networkInterfaceId"`
State string `xml:"state"`
Origin string `xml:"origin"`
VpcPeeringConnectionId string `xml:"vpcPeeringConnectionId"`
}
// Subnet
type Subnet struct {
SubnetId string `xml:"subnetId"`
State string `xml:"state"`
VpcId string `xml:"vpcId"`
CidrBlock string `xml:"cidrBlock"`
AvailableIpAddressCount int `xml:"availableIpAddressCount"`
AvailabilityZone string `xml:"availabilityZone"`
DefaultForAZ bool `xml:"defaultForAz"`
MapPublicIpOnLaunch bool `xml:"mapPublicIpOnLaunch"`
Tags []Tag `xml:"tagSet>item"`
}
// NetworkAcl represent network acl
type NetworkAcl struct {
NetworkAclId string `xml:"networkAclId"`
VpcId string `xml:"vpcId"`
Default string `xml:"default"`
EntrySet []NetworkAclEntry `xml:"entrySet>item"`
AssociationSet []NetworkAclAssociation `xml:"associationSet>item"`
Tags []Tag `xml:"tagSet>item"`
}
// NetworkAclAssociation
type NetworkAclAssociation struct {
NetworkAclAssociationId string `xml:"networkAclAssociationId"`
NetworkAclId string `xml:"networkAclId"`
SubnetId string `xml:"subnetId"`
}
// NetworkAclEntry represent a rule within NetworkAcl
type NetworkAclEntry struct {
RuleNumber int `xml:"ruleNumber"`
Protocol int `xml:"protocol"`
RuleAction string `xml:"ruleAction"`
Egress bool `xml:"egress"`
CidrBlock string `xml:"cidrBlock"`
IcmpCode IcmpCode `xml:"icmpTypeCode"`
PortRange PortRange `xml:"portRange"`
}
// IcmpCode
type IcmpCode struct {
Code int `xml:"code"`
Type int `xml:"type"`
}
// PortRange
type PortRange struct {
From int `xml:"from"`
To int `xml:"to"`
}
// Response to describe NetworkAcls
type NetworkAclsResp struct {
RequestId string `xml:"requestId"`
NetworkAcls []NetworkAcl `xml:"networkAclSet>item"`
}
// VPC represents a single VPC.
type VPC struct {
VpcId string `xml:"vpcId"`
State string `xml:"state"`
CidrBlock string `xml:"cidrBlock"`
DHCPOptionsID string `xml:"dhcpOptionsId"`
InstanceTenancy string `xml:"instanceTenancy"`
IsDefault bool `xml:"isDefault"`
Tags []Tag `xml:"tagSet>item"`
}
// Response to a DescribeSubnets request.
type SubnetsResp struct {
RequestId string `xml:"requestId"`
Subnets []Subnet `xml:"subnetSet>item"`
}
// Create a new VPC.
func (ec2 *EC2) CreateVpc(options *CreateVpc) (resp *CreateVpcResp, err error) {
params := makeParams("CreateVpc")
params["CidrBlock"] = options.CidrBlock
if options.InstanceTenancy != "" {
params["InstanceTenancy"] = options.InstanceTenancy
}
resp = &CreateVpcResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Delete a VPC.
func (ec2 *EC2) DeleteVpc(id string) (resp *SimpleResp, err error) {
params := makeParams("DeleteVpc")
params["VpcId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// DescribeVpcs
//
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVpcs.html
func (ec2 *EC2) DescribeVpcs(ids []string, filter *Filter) (resp *VpcsResp, err error) {
params := makeParams("DescribeVpcs")
addParamsList(params, "VpcId", ids)
filter.addParams(params)
resp = &VpcsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// VpcAttribute describes an attribute of a VPC.
// You can specify only one attribute at a time.
// Valid attributes are:
// enableDnsSupport | enableDnsHostnames
//
// See http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeVpcAttribute.html for more details.
func (ec2 *EC2) VpcAttribute(vpcId, attribute string) (resp *VpcAttributeResp, err error) {
params := makeParams("DescribeVpcAttribute")
params["VpcId"] = vpcId
params["Attribute"] = attribute
resp = &VpcAttributeResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ModifyVpcAttribute modifies the specified attribute of the specified VPC.
//
// See http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-ModifyVpcAttribute.html for more details.
func (ec2 *EC2) ModifyVpcAttribute(vpcId string, options *ModifyVpcAttribute) (*SimpleResp, error) {
params := makeParams("ModifyVpcAttribute")
params["VpcId"] = vpcId
if options.SetEnableDnsSupport {
params["EnableDnsSupport.Value"] = strconv.FormatBool(options.EnableDnsSupport)
}
if options.SetEnableDnsHostnames {
params["EnableDnsHostnames.Value"] = strconv.FormatBool(options.EnableDnsHostnames)
}
resp := &SimpleResp{}
if err := ec2.query(params, resp); err != nil {
return nil, err
}
return resp, nil
}
// Create a new subnet.
func (ec2 *EC2) CreateSubnet(options *CreateSubnet) (resp *CreateSubnetResp, err error) {
params := makeParams("CreateSubnet")
params["AvailabilityZone"] = options.AvailabilityZone
params["CidrBlock"] = options.CidrBlock
params["VpcId"] = options.VpcId
resp = &CreateSubnetResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Delete a Subnet.
func (ec2 *EC2) DeleteSubnet(id string) (resp *SimpleResp, err error) {
params := makeParams("DeleteSubnet")
params["SubnetId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// ModifySubnetAttribute
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-ModifySubnetAttribute.html
func (ec2 *EC2) ModifySubnetAttribute(options *ModifySubnetAttribute) (resp *ModifySubnetAttributeResp, err error) {
params := makeParams("ModifySubnetAttribute")
params["SubnetId"] = options.SubnetId
if options.MapPublicIpOnLaunch {
params["MapPublicIpOnLaunch.Value"] = "true"
} else {
params["MapPublicIpOnLaunch.Value"] = "false"
}
resp = &ModifySubnetAttributeResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// DescribeSubnets
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html
func (ec2 *EC2) DescribeSubnets(ids []string, filter *Filter) (resp *SubnetsResp, err error) {
params := makeParams("DescribeSubnets")
addParamsList(params, "SubnetId", ids)
filter.addParams(params)
resp = &SubnetsResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// CreateNetworkAcl creates a network ACL in a VPC.
//
// http://goo.gl/51X7db
func (ec2 *EC2) CreateNetworkAcl(options *CreateNetworkAcl) (resp *CreateNetworkAclResp, err error) {
params := makeParams("CreateNetworkAcl")
params["VpcId"] = options.VpcId
resp = &CreateNetworkAclResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// CreateNetworkAclEntry creates an entry (a rule) in a network ACL with the specified rule number.
//
// http://goo.gl/BtXhtj
func (ec2 *EC2) CreateNetworkAclEntry(networkAclId string, options *NetworkAclEntry) (resp *CreateNetworkAclEntryResp, err error) {
params := makeParams("CreateNetworkAclEntry")
params["NetworkAclId"] = networkAclId
params["RuleNumber"] = strconv.Itoa(options.RuleNumber)
params["Protocol"] = strconv.Itoa(options.Protocol)
params["RuleAction"] = options.RuleAction
params["Egress"] = strconv.FormatBool(options.Egress)
params["CidrBlock"] = options.CidrBlock
if params["Protocol"] == "-1" {
params["Icmp.Type"] = strconv.Itoa(options.IcmpCode.Type)
params["Icmp.Code"] = strconv.Itoa(options.IcmpCode.Code)
}
params["PortRange.From"] = strconv.Itoa(options.PortRange.From)
params["PortRange.To"] = strconv.Itoa(options.PortRange.To)
resp = &CreateNetworkAclEntryResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// NetworkAcls describes one or more of your network ACLs for given filter.
//
// http://goo.gl/mk9RsV
func (ec2 *EC2) NetworkAcls(networkAclIds []string, filter *Filter) (resp *NetworkAclsResp, err error) {
params := makeParams("DescribeNetworkAcls")
addParamsList(params, "NetworkAclId", networkAclIds)
filter.addParams(params)
resp = &NetworkAclsResp{}
if err = ec2.query(params, resp); err != nil {
return nil, err
}
return resp, nil
}
// Response to a DeleteNetworkAcl request.
type DeleteNetworkAclResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
}
// DeleteNetworkAcl deletes the network ACL with specified id.
//
// http://goo.gl/nC78Wx
func (ec2 *EC2) DeleteNetworkAcl(id string) (resp *DeleteNetworkAclResp, err error) {
params := makeParams("DeleteNetworkAcl")
params["NetworkAclId"] = id
resp = &DeleteNetworkAclResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// Response to a DeleteNetworkAclEntry request.
type DeleteNetworkAclEntryResp struct {
RequestId string `xml:"requestId"`
Return bool `xml:"return"`
}
// DeleteNetworkAclEntry deletes the specified ingress or egress entry (rule) from the specified network ACL.
//
// http://goo.gl/moQbE2
func (ec2 *EC2) DeleteNetworkAclEntry(id string, ruleNumber int, egress bool) (resp *DeleteNetworkAclEntryResp, err error) {
params := makeParams("DeleteNetworkAclEntry")
params["NetworkAclId"] = id
params["RuleNumber"] = strconv.Itoa(ruleNumber)
params["Egress"] = strconv.FormatBool(egress)
resp = &DeleteNetworkAclEntryResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
type ReplaceNetworkAclAssociationResponse struct {
RequestId string `xml:"requestId"`
NewAssociationId string `xml:"newAssociationId"`
}
// ReplaceNetworkAclAssociation changes which network ACL a subnet is associated with.
//
// http://goo.gl/ar0MH5
func (ec2 *EC2) ReplaceNetworkAclAssociation(associationId string, networkAclId string) (resp *ReplaceNetworkAclAssociationResponse, err error) {
params := makeParams("ReplaceNetworkAclAssociation")
params["NetworkAclId"] = networkAclId
params["AssociationId"] = associationId
resp = &ReplaceNetworkAclAssociationResponse{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// Create a new internet gateway.
func (ec2 *EC2) CreateInternetGateway(
options *CreateInternetGateway) (resp *CreateInternetGatewayResp, err error) {
params := makeParams("CreateInternetGateway")
resp = &CreateInternetGatewayResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Attach an InternetGateway.
func (ec2 *EC2) AttachInternetGateway(id, vpcId string) (resp *SimpleResp, err error) {
params := makeParams("AttachInternetGateway")
params["InternetGatewayId"] = id
params["VpcId"] = vpcId
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Detach an InternetGateway.
func (ec2 *EC2) DetachInternetGateway(id, vpcId string) (resp *SimpleResp, err error) {
params := makeParams("DetachInternetGateway")
params["InternetGatewayId"] = id
params["VpcId"] = vpcId
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Delete an InternetGateway.
func (ec2 *EC2) DeleteInternetGateway(id string) (resp *SimpleResp, err error) {
params := makeParams("DeleteInternetGateway")
params["InternetGatewayId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// DescribeInternetGateways
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInternetGateways.html
func (ec2 *EC2) DescribeInternetGateways(ids []string, filter *Filter) (resp *InternetGatewaysResp, err error) {
params := makeParams("DescribeInternetGateways")
addParamsList(params, "InternetGatewayId", ids)
filter.addParams(params)
resp = &InternetGatewaysResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Create a new routing table.
func (ec2 *EC2) CreateRouteTable(
options *CreateRouteTable) (resp *CreateRouteTableResp, err error) {
params := makeParams("CreateRouteTable")
params["VpcId"] = options.VpcId
resp = &CreateRouteTableResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Delete a RouteTable.
func (ec2 *EC2) DeleteRouteTable(id string) (resp *SimpleResp, err error) {
params := makeParams("DeleteRouteTable")
params["RouteTableId"] = id
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// DescribeRouteTables
//
// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeRouteTables.html
func (ec2 *EC2) DescribeRouteTables(ids []string, filter *Filter) (resp *RouteTablesResp, err error) {
params := makeParams("DescribeRouteTables")
addParamsList(params, "RouteTableId", ids)
filter.addParams(params)
resp = &RouteTablesResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Associate a routing table.
func (ec2 *EC2) AssociateRouteTable(id, subnetId string) (*AssociateRouteTableResp, error) {
params := makeParams("AssociateRouteTable")
params["RouteTableId"] = id
params["SubnetId"] = subnetId
resp := &AssociateRouteTableResp{}
err := ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// Disassociate a routing table.
func (ec2 *EC2) DisassociateRouteTable(id string) (*SimpleResp, error) {
params := makeParams("DisassociateRouteTable")
params["AssociationId"] = id
resp := &SimpleResp{}
err := ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// Re-associate a routing table.
func (ec2 *EC2) ReassociateRouteTable(id, routeTableId string) (*ReassociateRouteTableResp, error) {
params := makeParams("ReplaceRouteTableAssociation")
params["AssociationId"] = id
params["RouteTableId"] = routeTableId
resp := &ReassociateRouteTableResp{}
err := ec2.query(params, resp)
if err != nil {
return nil, err
}
return resp, nil
}
// Create a new route.
func (ec2 *EC2) CreateRoute(options *CreateRoute) (resp *SimpleResp, err error) {
params := makeParams("CreateRoute")
params["RouteTableId"] = options.RouteTableId
params["DestinationCidrBlock"] = options.DestinationCidrBlock
if v := options.GatewayId; v != "" {
params["GatewayId"] = v
}
if v := options.InstanceId; v != "" {
params["InstanceId"] = v
}
if v := options.NetworkInterfaceId; v != "" {
params["NetworkInterfaceId"] = v
}
if v := options.VpcPeeringConnectionId; v != "" {
params["VpcPeeringConnectionId"] = v
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Delete a Route.
func (ec2 *EC2) DeleteRoute(routeTableId, cidr string) (resp *SimpleResp, err error) {
params := makeParams("DeleteRoute")
params["RouteTableId"] = routeTableId
params["DestinationCidrBlock"] = cidr
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// Replace a new route.
func (ec2 *EC2) ReplaceRoute(options *ReplaceRoute) (resp *SimpleResp, err error) {
params := makeParams("ReplaceRoute")
params["RouteTableId"] = options.RouteTableId
params["DestinationCidrBlock"] = options.DestinationCidrBlock
if v := options.GatewayId; v != "" {
params["GatewayId"] = v
}
if v := options.InstanceId; v != "" {
params["InstanceId"] = v
}
if v := options.NetworkInterfaceId; v != "" {
params["NetworkInterfaceId"] = v
}
if v := options.VpcPeeringConnectionId; v != "" {
params["VpcPeeringConnectionId"] = v
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
// The ResetImageAttribute request parameters.
type ResetImageAttribute struct {
Attribute string
}
// ResetImageAttribute resets an attribute of an AMI to its default value.
//
// http://goo.gl/r6ZCPm for more details.
func (ec2 *EC2) ResetImageAttribute(imageId string, options *ResetImageAttribute) (resp *SimpleResp, err error) {
params := makeParams("ResetImageAttribute")
params["ImageId"] = imageId
if options.Attribute != "" {
params["Attribute"] = options.Attribute
}
resp = &SimpleResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.12.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891