examples_test.go 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package ec2_test
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/aws/awserr"
  9. "github.com/aws/aws-sdk-go/aws/session"
  10. "github.com/aws/aws-sdk-go/service/ec2"
  11. )
  12. var _ time.Duration
  13. var _ strings.Reader
  14. var _ aws.Config
  15. func parseTime(layout, value string) *time.Time {
  16. t, err := time.Parse(layout, value)
  17. if err != nil {
  18. panic(err)
  19. }
  20. return &t
  21. }
  22. // To allocate an Elastic IP address for EC2-VPC
  23. //
  24. // This example allocates an Elastic IP address to use with an instance in a VPC.
  25. func ExampleEC2_AllocateAddress_shared00() {
  26. svc := ec2.New(session.New())
  27. input := &ec2.AllocateAddressInput{
  28. Domain: aws.String("vpc"),
  29. }
  30. result, err := svc.AllocateAddress(input)
  31. if err != nil {
  32. if aerr, ok := err.(awserr.Error); ok {
  33. switch aerr.Code() {
  34. default:
  35. fmt.Println(aerr.Error())
  36. }
  37. } else {
  38. // Print the error, cast err to awserr.Error to get the Code and
  39. // Message from an error.
  40. fmt.Println(err.Error())
  41. }
  42. return
  43. }
  44. fmt.Println(result)
  45. }
  46. // To allocate an Elastic IP address for EC2-Classic
  47. //
  48. // This example allocates an Elastic IP address to use with an instance in EC2-Classic.
  49. func ExampleEC2_AllocateAddress_shared01() {
  50. svc := ec2.New(session.New())
  51. input := &ec2.AllocateAddressInput{}
  52. result, err := svc.AllocateAddress(input)
  53. if err != nil {
  54. if aerr, ok := err.(awserr.Error); ok {
  55. switch aerr.Code() {
  56. default:
  57. fmt.Println(aerr.Error())
  58. }
  59. } else {
  60. // Print the error, cast err to awserr.Error to get the Code and
  61. // Message from an error.
  62. fmt.Println(err.Error())
  63. }
  64. return
  65. }
  66. fmt.Println(result)
  67. }
  68. // To assign a specific secondary private IP address to an interface
  69. //
  70. // This example assigns the specified secondary private IP address to the specified
  71. // network interface.
  72. func ExampleEC2_AssignPrivateIpAddresses_shared00() {
  73. svc := ec2.New(session.New())
  74. input := &ec2.AssignPrivateIpAddressesInput{
  75. NetworkInterfaceId: aws.String("eni-e5aa89a3"),
  76. PrivateIpAddresses: []*string{
  77. aws.String("10.0.0.82"),
  78. },
  79. }
  80. result, err := svc.AssignPrivateIpAddresses(input)
  81. if err != nil {
  82. if aerr, ok := err.(awserr.Error); ok {
  83. switch aerr.Code() {
  84. default:
  85. fmt.Println(aerr.Error())
  86. }
  87. } else {
  88. // Print the error, cast err to awserr.Error to get the Code and
  89. // Message from an error.
  90. fmt.Println(err.Error())
  91. }
  92. return
  93. }
  94. fmt.Println(result)
  95. }
  96. // To assign secondary private IP addresses that Amazon EC2 selects to an interface
  97. //
  98. // This example assigns two secondary private IP addresses to the specified network
  99. // interface. Amazon EC2 automatically assigns these IP addresses from the available
  100. // IP addresses in the CIDR block range of the subnet the network interface is associated
  101. // with.
  102. func ExampleEC2_AssignPrivateIpAddresses_shared01() {
  103. svc := ec2.New(session.New())
  104. input := &ec2.AssignPrivateIpAddressesInput{
  105. NetworkInterfaceId: aws.String("eni-e5aa89a3"),
  106. SecondaryPrivateIpAddressCount: aws.Int64(2),
  107. }
  108. result, err := svc.AssignPrivateIpAddresses(input)
  109. if err != nil {
  110. if aerr, ok := err.(awserr.Error); ok {
  111. switch aerr.Code() {
  112. default:
  113. fmt.Println(aerr.Error())
  114. }
  115. } else {
  116. // Print the error, cast err to awserr.Error to get the Code and
  117. // Message from an error.
  118. fmt.Println(err.Error())
  119. }
  120. return
  121. }
  122. fmt.Println(result)
  123. }
  124. // To associate an Elastic IP address in EC2-VPC
  125. //
  126. // This example associates the specified Elastic IP address with the specified instance
  127. // in a VPC.
  128. func ExampleEC2_AssociateAddress_shared00() {
  129. svc := ec2.New(session.New())
  130. input := &ec2.AssociateAddressInput{
  131. AllocationId: aws.String("eipalloc-64d5890a"),
  132. InstanceId: aws.String("i-0b263919b6498b123"),
  133. }
  134. result, err := svc.AssociateAddress(input)
  135. if err != nil {
  136. if aerr, ok := err.(awserr.Error); ok {
  137. switch aerr.Code() {
  138. default:
  139. fmt.Println(aerr.Error())
  140. }
  141. } else {
  142. // Print the error, cast err to awserr.Error to get the Code and
  143. // Message from an error.
  144. fmt.Println(err.Error())
  145. }
  146. return
  147. }
  148. fmt.Println(result)
  149. }
  150. // To associate an Elastic IP address with a network interface
  151. //
  152. // This example associates the specified Elastic IP address with the specified network
  153. // interface.
  154. func ExampleEC2_AssociateAddress_shared01() {
  155. svc := ec2.New(session.New())
  156. input := &ec2.AssociateAddressInput{
  157. AllocationId: aws.String("eipalloc-64d5890a"),
  158. NetworkInterfaceId: aws.String("eni-1a2b3c4d"),
  159. }
  160. result, err := svc.AssociateAddress(input)
  161. if err != nil {
  162. if aerr, ok := err.(awserr.Error); ok {
  163. switch aerr.Code() {
  164. default:
  165. fmt.Println(aerr.Error())
  166. }
  167. } else {
  168. // Print the error, cast err to awserr.Error to get the Code and
  169. // Message from an error.
  170. fmt.Println(err.Error())
  171. }
  172. return
  173. }
  174. fmt.Println(result)
  175. }
  176. // To associate an Elastic IP address in EC2-Classic
  177. //
  178. // This example associates an Elastic IP address with an instance in EC2-Classic.
  179. func ExampleEC2_AssociateAddress_shared02() {
  180. svc := ec2.New(session.New())
  181. input := &ec2.AssociateAddressInput{
  182. InstanceId: aws.String("i-07ffe74c7330ebf53"),
  183. PublicIp: aws.String("198.51.100.0"),
  184. }
  185. result, err := svc.AssociateAddress(input)
  186. if err != nil {
  187. if aerr, ok := err.(awserr.Error); ok {
  188. switch aerr.Code() {
  189. default:
  190. fmt.Println(aerr.Error())
  191. }
  192. } else {
  193. // Print the error, cast err to awserr.Error to get the Code and
  194. // Message from an error.
  195. fmt.Println(err.Error())
  196. }
  197. return
  198. }
  199. fmt.Println(result)
  200. }
  201. // To associate a DHCP options set with a VPC
  202. //
  203. // This example associates the specified DHCP options set with the specified VPC.
  204. func ExampleEC2_AssociateDhcpOptions_shared00() {
  205. svc := ec2.New(session.New())
  206. input := &ec2.AssociateDhcpOptionsInput{
  207. DhcpOptionsId: aws.String("dopt-d9070ebb"),
  208. VpcId: aws.String("vpc-a01106c2"),
  209. }
  210. result, err := svc.AssociateDhcpOptions(input)
  211. if err != nil {
  212. if aerr, ok := err.(awserr.Error); ok {
  213. switch aerr.Code() {
  214. default:
  215. fmt.Println(aerr.Error())
  216. }
  217. } else {
  218. // Print the error, cast err to awserr.Error to get the Code and
  219. // Message from an error.
  220. fmt.Println(err.Error())
  221. }
  222. return
  223. }
  224. fmt.Println(result)
  225. }
  226. // To associate the default DHCP options set with a VPC
  227. //
  228. // This example associates the default DHCP options set with the specified VPC.
  229. func ExampleEC2_AssociateDhcpOptions_shared01() {
  230. svc := ec2.New(session.New())
  231. input := &ec2.AssociateDhcpOptionsInput{
  232. DhcpOptionsId: aws.String("default"),
  233. VpcId: aws.String("vpc-a01106c2"),
  234. }
  235. result, err := svc.AssociateDhcpOptions(input)
  236. if err != nil {
  237. if aerr, ok := err.(awserr.Error); ok {
  238. switch aerr.Code() {
  239. default:
  240. fmt.Println(aerr.Error())
  241. }
  242. } else {
  243. // Print the error, cast err to awserr.Error to get the Code and
  244. // Message from an error.
  245. fmt.Println(err.Error())
  246. }
  247. return
  248. }
  249. fmt.Println(result)
  250. }
  251. // To associate an IAM instance profile with an instance
  252. //
  253. // This example associates an IAM instance profile named admin-role with the specified
  254. // instance.
  255. func ExampleEC2_AssociateIamInstanceProfile_shared00() {
  256. svc := ec2.New(session.New())
  257. input := &ec2.AssociateIamInstanceProfileInput{
  258. IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
  259. Name: aws.String("admin-role"),
  260. },
  261. InstanceId: aws.String("i-123456789abcde123"),
  262. }
  263. result, err := svc.AssociateIamInstanceProfile(input)
  264. if err != nil {
  265. if aerr, ok := err.(awserr.Error); ok {
  266. switch aerr.Code() {
  267. default:
  268. fmt.Println(aerr.Error())
  269. }
  270. } else {
  271. // Print the error, cast err to awserr.Error to get the Code and
  272. // Message from an error.
  273. fmt.Println(err.Error())
  274. }
  275. return
  276. }
  277. fmt.Println(result)
  278. }
  279. // To associate a route table with a subnet
  280. //
  281. // This example associates the specified route table with the specified subnet.
  282. func ExampleEC2_AssociateRouteTable_shared00() {
  283. svc := ec2.New(session.New())
  284. input := &ec2.AssociateRouteTableInput{
  285. RouteTableId: aws.String("rtb-22574640"),
  286. SubnetId: aws.String("subnet-9d4a7b6"),
  287. }
  288. result, err := svc.AssociateRouteTable(input)
  289. if err != nil {
  290. if aerr, ok := err.(awserr.Error); ok {
  291. switch aerr.Code() {
  292. default:
  293. fmt.Println(aerr.Error())
  294. }
  295. } else {
  296. // Print the error, cast err to awserr.Error to get the Code and
  297. // Message from an error.
  298. fmt.Println(err.Error())
  299. }
  300. return
  301. }
  302. fmt.Println(result)
  303. }
  304. // To attach an Internet gateway to a VPC
  305. //
  306. // This example attaches the specified Internet gateway to the specified VPC.
  307. func ExampleEC2_AttachInternetGateway_shared00() {
  308. svc := ec2.New(session.New())
  309. input := &ec2.AttachInternetGatewayInput{
  310. InternetGatewayId: aws.String("igw-c0a643a9"),
  311. VpcId: aws.String("vpc-a01106c2"),
  312. }
  313. result, err := svc.AttachInternetGateway(input)
  314. if err != nil {
  315. if aerr, ok := err.(awserr.Error); ok {
  316. switch aerr.Code() {
  317. default:
  318. fmt.Println(aerr.Error())
  319. }
  320. } else {
  321. // Print the error, cast err to awserr.Error to get the Code and
  322. // Message from an error.
  323. fmt.Println(err.Error())
  324. }
  325. return
  326. }
  327. fmt.Println(result)
  328. }
  329. // To attach a network interface to an instance
  330. //
  331. // This example attaches the specified network interface to the specified instance.
  332. func ExampleEC2_AttachNetworkInterface_shared00() {
  333. svc := ec2.New(session.New())
  334. input := &ec2.AttachNetworkInterfaceInput{
  335. DeviceIndex: aws.Int64(1),
  336. InstanceId: aws.String("i-1234567890abcdef0"),
  337. NetworkInterfaceId: aws.String("eni-e5aa89a3"),
  338. }
  339. result, err := svc.AttachNetworkInterface(input)
  340. if err != nil {
  341. if aerr, ok := err.(awserr.Error); ok {
  342. switch aerr.Code() {
  343. default:
  344. fmt.Println(aerr.Error())
  345. }
  346. } else {
  347. // Print the error, cast err to awserr.Error to get the Code and
  348. // Message from an error.
  349. fmt.Println(err.Error())
  350. }
  351. return
  352. }
  353. fmt.Println(result)
  354. }
  355. // To attach a volume to an instance
  356. //
  357. // This example attaches a volume (``vol-1234567890abcdef0``) to an instance (``i-01474ef662b89480``)
  358. // as ``/dev/sdf``.
  359. func ExampleEC2_AttachVolume_shared00() {
  360. svc := ec2.New(session.New())
  361. input := &ec2.AttachVolumeInput{
  362. Device: aws.String("/dev/sdf"),
  363. InstanceId: aws.String("i-01474ef662b89480"),
  364. VolumeId: aws.String("vol-1234567890abcdef0"),
  365. }
  366. result, err := svc.AttachVolume(input)
  367. if err != nil {
  368. if aerr, ok := err.(awserr.Error); ok {
  369. switch aerr.Code() {
  370. default:
  371. fmt.Println(aerr.Error())
  372. }
  373. } else {
  374. // Print the error, cast err to awserr.Error to get the Code and
  375. // Message from an error.
  376. fmt.Println(err.Error())
  377. }
  378. return
  379. }
  380. fmt.Println(result)
  381. }
  382. // To add a rule that allows outbound traffic to a specific address range
  383. //
  384. // This example adds a rule that grants access to the specified address ranges on TCP
  385. // port 80.
  386. func ExampleEC2_AuthorizeSecurityGroupEgress_shared00() {
  387. svc := ec2.New(session.New())
  388. input := &ec2.AuthorizeSecurityGroupEgressInput{
  389. GroupId: aws.String("sg-1a2b3c4d"),
  390. IpPermissions: []*ec2.IpPermission{
  391. {
  392. FromPort: aws.Int64(80),
  393. IpProtocol: aws.String("tcp"),
  394. IpRanges: []*ec2.IpRange{
  395. {
  396. CidrIp: aws.String("10.0.0.0/16"),
  397. },
  398. },
  399. ToPort: aws.Int64(80),
  400. },
  401. },
  402. }
  403. result, err := svc.AuthorizeSecurityGroupEgress(input)
  404. if err != nil {
  405. if aerr, ok := err.(awserr.Error); ok {
  406. switch aerr.Code() {
  407. default:
  408. fmt.Println(aerr.Error())
  409. }
  410. } else {
  411. // Print the error, cast err to awserr.Error to get the Code and
  412. // Message from an error.
  413. fmt.Println(err.Error())
  414. }
  415. return
  416. }
  417. fmt.Println(result)
  418. }
  419. // To add a rule that allows outbound traffic to a specific security group
  420. //
  421. // This example adds a rule that grants access to the specified security group on TCP
  422. // port 80.
  423. func ExampleEC2_AuthorizeSecurityGroupEgress_shared01() {
  424. svc := ec2.New(session.New())
  425. input := &ec2.AuthorizeSecurityGroupEgressInput{
  426. GroupId: aws.String("sg-1a2b3c4d"),
  427. IpPermissions: []*ec2.IpPermission{
  428. {
  429. FromPort: aws.Int64(80),
  430. IpProtocol: aws.String("tcp"),
  431. ToPort: aws.Int64(80),
  432. UserIdGroupPairs: []*ec2.UserIdGroupPair{
  433. {
  434. GroupId: aws.String("sg-4b51a32f"),
  435. },
  436. },
  437. },
  438. },
  439. }
  440. result, err := svc.AuthorizeSecurityGroupEgress(input)
  441. if err != nil {
  442. if aerr, ok := err.(awserr.Error); ok {
  443. switch aerr.Code() {
  444. default:
  445. fmt.Println(aerr.Error())
  446. }
  447. } else {
  448. // Print the error, cast err to awserr.Error to get the Code and
  449. // Message from an error.
  450. fmt.Println(err.Error())
  451. }
  452. return
  453. }
  454. fmt.Println(result)
  455. }
  456. // To add a rule that allows inbound SSH traffic from an IPv4 address range
  457. //
  458. // This example enables inbound traffic on TCP port 22 (SSH). The rule includes a description
  459. // to help you identify it later.
  460. func ExampleEC2_AuthorizeSecurityGroupIngress_shared00() {
  461. svc := ec2.New(session.New())
  462. input := &ec2.AuthorizeSecurityGroupIngressInput{
  463. GroupId: aws.String("sg-903004f8"),
  464. IpPermissions: []*ec2.IpPermission{
  465. {
  466. FromPort: aws.Int64(22),
  467. IpProtocol: aws.String("tcp"),
  468. IpRanges: []*ec2.IpRange{
  469. {
  470. CidrIp: aws.String("203.0.113.0/24"),
  471. Description: aws.String("SSH access from the LA office"),
  472. },
  473. },
  474. ToPort: aws.Int64(22),
  475. },
  476. },
  477. }
  478. result, err := svc.AuthorizeSecurityGroupIngress(input)
  479. if err != nil {
  480. if aerr, ok := err.(awserr.Error); ok {
  481. switch aerr.Code() {
  482. default:
  483. fmt.Println(aerr.Error())
  484. }
  485. } else {
  486. // Print the error, cast err to awserr.Error to get the Code and
  487. // Message from an error.
  488. fmt.Println(err.Error())
  489. }
  490. return
  491. }
  492. fmt.Println(result)
  493. }
  494. // To add a rule that allows inbound HTTP traffic from another security group
  495. //
  496. // This example enables inbound traffic on TCP port 80 from the specified security group.
  497. // The group must be in the same VPC or a peer VPC. Incoming traffic is allowed based
  498. // on the private IP addresses of instances that are associated with the specified security
  499. // group.
  500. func ExampleEC2_AuthorizeSecurityGroupIngress_shared01() {
  501. svc := ec2.New(session.New())
  502. input := &ec2.AuthorizeSecurityGroupIngressInput{
  503. GroupId: aws.String("sg-111aaa22"),
  504. IpPermissions: []*ec2.IpPermission{
  505. {
  506. FromPort: aws.Int64(80),
  507. IpProtocol: aws.String("tcp"),
  508. ToPort: aws.Int64(80),
  509. UserIdGroupPairs: []*ec2.UserIdGroupPair{
  510. {
  511. Description: aws.String("HTTP access from other instances"),
  512. GroupId: aws.String("sg-1a2b3c4d"),
  513. },
  514. },
  515. },
  516. },
  517. }
  518. result, err := svc.AuthorizeSecurityGroupIngress(input)
  519. if err != nil {
  520. if aerr, ok := err.(awserr.Error); ok {
  521. switch aerr.Code() {
  522. default:
  523. fmt.Println(aerr.Error())
  524. }
  525. } else {
  526. // Print the error, cast err to awserr.Error to get the Code and
  527. // Message from an error.
  528. fmt.Println(err.Error())
  529. }
  530. return
  531. }
  532. fmt.Println(result)
  533. }
  534. // To add a rule that allows inbound RDP traffic from an IPv6 address range
  535. //
  536. // This example adds an inbound rule that allows RDP traffic from the specified IPv6
  537. // address range. The rule includes a description to help you identify it later.
  538. func ExampleEC2_AuthorizeSecurityGroupIngress_shared02() {
  539. svc := ec2.New(session.New())
  540. input := &ec2.AuthorizeSecurityGroupIngressInput{
  541. GroupId: aws.String("sg-123abc12 "),
  542. IpPermissions: []*ec2.IpPermission{
  543. {
  544. FromPort: aws.Int64(3389),
  545. IpProtocol: aws.String("tcp"),
  546. Ipv6Ranges: []*ec2.Ipv6Range{
  547. {
  548. CidrIpv6: aws.String("2001:db8:1234:1a00::/64"),
  549. Description: aws.String("RDP access from the NY office"),
  550. },
  551. },
  552. ToPort: aws.Int64(3389),
  553. },
  554. },
  555. }
  556. result, err := svc.AuthorizeSecurityGroupIngress(input)
  557. if err != nil {
  558. if aerr, ok := err.(awserr.Error); ok {
  559. switch aerr.Code() {
  560. default:
  561. fmt.Println(aerr.Error())
  562. }
  563. } else {
  564. // Print the error, cast err to awserr.Error to get the Code and
  565. // Message from an error.
  566. fmt.Println(err.Error())
  567. }
  568. return
  569. }
  570. fmt.Println(result)
  571. }
  572. // To cancel a Spot fleet request
  573. //
  574. // This example cancels the specified Spot fleet request and terminates its associated
  575. // Spot Instances.
  576. func ExampleEC2_CancelSpotFleetRequests_shared00() {
  577. svc := ec2.New(session.New())
  578. input := &ec2.CancelSpotFleetRequestsInput{
  579. SpotFleetRequestIds: []*string{
  580. aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  581. },
  582. TerminateInstances: aws.Bool(true),
  583. }
  584. result, err := svc.CancelSpotFleetRequests(input)
  585. if err != nil {
  586. if aerr, ok := err.(awserr.Error); ok {
  587. switch aerr.Code() {
  588. default:
  589. fmt.Println(aerr.Error())
  590. }
  591. } else {
  592. // Print the error, cast err to awserr.Error to get the Code and
  593. // Message from an error.
  594. fmt.Println(err.Error())
  595. }
  596. return
  597. }
  598. fmt.Println(result)
  599. }
  600. // To cancel a Spot fleet request without terminating its Spot Instances
  601. //
  602. // This example cancels the specified Spot fleet request without terminating its associated
  603. // Spot Instances.
  604. func ExampleEC2_CancelSpotFleetRequests_shared01() {
  605. svc := ec2.New(session.New())
  606. input := &ec2.CancelSpotFleetRequestsInput{
  607. SpotFleetRequestIds: []*string{
  608. aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  609. },
  610. TerminateInstances: aws.Bool(false),
  611. }
  612. result, err := svc.CancelSpotFleetRequests(input)
  613. if err != nil {
  614. if aerr, ok := err.(awserr.Error); ok {
  615. switch aerr.Code() {
  616. default:
  617. fmt.Println(aerr.Error())
  618. }
  619. } else {
  620. // Print the error, cast err to awserr.Error to get the Code and
  621. // Message from an error.
  622. fmt.Println(err.Error())
  623. }
  624. return
  625. }
  626. fmt.Println(result)
  627. }
  628. // To cancel Spot Instance requests
  629. //
  630. // This example cancels a Spot Instance request.
  631. func ExampleEC2_CancelSpotInstanceRequests_shared00() {
  632. svc := ec2.New(session.New())
  633. input := &ec2.CancelSpotInstanceRequestsInput{
  634. SpotInstanceRequestIds: []*string{
  635. aws.String("sir-08b93456"),
  636. },
  637. }
  638. result, err := svc.CancelSpotInstanceRequests(input)
  639. if err != nil {
  640. if aerr, ok := err.(awserr.Error); ok {
  641. switch aerr.Code() {
  642. default:
  643. fmt.Println(aerr.Error())
  644. }
  645. } else {
  646. // Print the error, cast err to awserr.Error to get the Code and
  647. // Message from an error.
  648. fmt.Println(err.Error())
  649. }
  650. return
  651. }
  652. fmt.Println(result)
  653. }
  654. // To confirm the product instance
  655. //
  656. // This example determines whether the specified product code is associated with the
  657. // specified instance.
  658. func ExampleEC2_ConfirmProductInstance_shared00() {
  659. svc := ec2.New(session.New())
  660. input := &ec2.ConfirmProductInstanceInput{
  661. InstanceId: aws.String("i-1234567890abcdef0"),
  662. ProductCode: aws.String("774F4FF8"),
  663. }
  664. result, err := svc.ConfirmProductInstance(input)
  665. if err != nil {
  666. if aerr, ok := err.(awserr.Error); ok {
  667. switch aerr.Code() {
  668. default:
  669. fmt.Println(aerr.Error())
  670. }
  671. } else {
  672. // Print the error, cast err to awserr.Error to get the Code and
  673. // Message from an error.
  674. fmt.Println(err.Error())
  675. }
  676. return
  677. }
  678. fmt.Println(result)
  679. }
  680. // To copy an AMI to another region
  681. //
  682. // This example copies the specified AMI from the us-east-1 region to the current region.
  683. func ExampleEC2_CopyImage_shared00() {
  684. svc := ec2.New(session.New())
  685. input := &ec2.CopyImageInput{
  686. Description: aws.String(""),
  687. Name: aws.String("My server"),
  688. SourceImageId: aws.String("ami-5731123e"),
  689. SourceRegion: aws.String("us-east-1"),
  690. }
  691. result, err := svc.CopyImage(input)
  692. if err != nil {
  693. if aerr, ok := err.(awserr.Error); ok {
  694. switch aerr.Code() {
  695. default:
  696. fmt.Println(aerr.Error())
  697. }
  698. } else {
  699. // Print the error, cast err to awserr.Error to get the Code and
  700. // Message from an error.
  701. fmt.Println(err.Error())
  702. }
  703. return
  704. }
  705. fmt.Println(result)
  706. }
  707. // To copy a snapshot
  708. //
  709. // This example copies a snapshot with the snapshot ID of ``snap-066877671789bd71b``
  710. // from the ``us-west-2`` region to the ``us-east-1`` region and adds a short description
  711. // to identify the snapshot.
  712. func ExampleEC2_CopySnapshot_shared00() {
  713. svc := ec2.New(session.New())
  714. input := &ec2.CopySnapshotInput{
  715. Description: aws.String("This is my copied snapshot."),
  716. DestinationRegion: aws.String("us-east-1"),
  717. SourceRegion: aws.String("us-west-2"),
  718. SourceSnapshotId: aws.String("snap-066877671789bd71b"),
  719. }
  720. result, err := svc.CopySnapshot(input)
  721. if err != nil {
  722. if aerr, ok := err.(awserr.Error); ok {
  723. switch aerr.Code() {
  724. default:
  725. fmt.Println(aerr.Error())
  726. }
  727. } else {
  728. // Print the error, cast err to awserr.Error to get the Code and
  729. // Message from an error.
  730. fmt.Println(err.Error())
  731. }
  732. return
  733. }
  734. fmt.Println(result)
  735. }
  736. // To create a customer gateway
  737. //
  738. // This example creates a customer gateway with the specified IP address for its outside
  739. // interface.
  740. func ExampleEC2_CreateCustomerGateway_shared00() {
  741. svc := ec2.New(session.New())
  742. input := &ec2.CreateCustomerGatewayInput{
  743. BgpAsn: aws.Int64(65534),
  744. PublicIp: aws.String("12.1.2.3"),
  745. Type: aws.String("ipsec.1"),
  746. }
  747. result, err := svc.CreateCustomerGateway(input)
  748. if err != nil {
  749. if aerr, ok := err.(awserr.Error); ok {
  750. switch aerr.Code() {
  751. default:
  752. fmt.Println(aerr.Error())
  753. }
  754. } else {
  755. // Print the error, cast err to awserr.Error to get the Code and
  756. // Message from an error.
  757. fmt.Println(err.Error())
  758. }
  759. return
  760. }
  761. fmt.Println(result)
  762. }
  763. // To create a DHCP options set
  764. //
  765. // This example creates a DHCP options set.
  766. func ExampleEC2_CreateDhcpOptions_shared00() {
  767. svc := ec2.New(session.New())
  768. input := &ec2.CreateDhcpOptionsInput{
  769. DhcpConfigurations: []*ec2.NewDhcpConfiguration{
  770. {
  771. Key: aws.String("domain-name-servers"),
  772. Values: []*string{
  773. aws.String("10.2.5.1"),
  774. aws.String("10.2.5.2"),
  775. },
  776. },
  777. },
  778. }
  779. result, err := svc.CreateDhcpOptions(input)
  780. if err != nil {
  781. if aerr, ok := err.(awserr.Error); ok {
  782. switch aerr.Code() {
  783. default:
  784. fmt.Println(aerr.Error())
  785. }
  786. } else {
  787. // Print the error, cast err to awserr.Error to get the Code and
  788. // Message from an error.
  789. fmt.Println(err.Error())
  790. }
  791. return
  792. }
  793. fmt.Println(result)
  794. }
  795. // To create an AMI from an Amazon EBS-backed instance
  796. //
  797. // This example creates an AMI from the specified instance and adds an EBS volume with
  798. // the device name /dev/sdh and an instance store volume with the device name /dev/sdc.
  799. func ExampleEC2_CreateImage_shared00() {
  800. svc := ec2.New(session.New())
  801. input := &ec2.CreateImageInput{
  802. BlockDeviceMappings: []*ec2.BlockDeviceMapping{
  803. {
  804. DeviceName: aws.String("/dev/sdh"),
  805. Ebs: &ec2.EbsBlockDevice{
  806. VolumeSize: aws.Int64(100),
  807. },
  808. },
  809. {
  810. DeviceName: aws.String("/dev/sdc"),
  811. VirtualName: aws.String("ephemeral1"),
  812. },
  813. },
  814. Description: aws.String("An AMI for my server"),
  815. InstanceId: aws.String("i-1234567890abcdef0"),
  816. Name: aws.String("My server"),
  817. NoReboot: aws.Bool(true),
  818. }
  819. result, err := svc.CreateImage(input)
  820. if err != nil {
  821. if aerr, ok := err.(awserr.Error); ok {
  822. switch aerr.Code() {
  823. default:
  824. fmt.Println(aerr.Error())
  825. }
  826. } else {
  827. // Print the error, cast err to awserr.Error to get the Code and
  828. // Message from an error.
  829. fmt.Println(err.Error())
  830. }
  831. return
  832. }
  833. fmt.Println(result)
  834. }
  835. // To create an Internet gateway
  836. //
  837. // This example creates an Internet gateway.
  838. func ExampleEC2_CreateInternetGateway_shared00() {
  839. svc := ec2.New(session.New())
  840. input := &ec2.CreateInternetGatewayInput{}
  841. result, err := svc.CreateInternetGateway(input)
  842. if err != nil {
  843. if aerr, ok := err.(awserr.Error); ok {
  844. switch aerr.Code() {
  845. default:
  846. fmt.Println(aerr.Error())
  847. }
  848. } else {
  849. // Print the error, cast err to awserr.Error to get the Code and
  850. // Message from an error.
  851. fmt.Println(err.Error())
  852. }
  853. return
  854. }
  855. fmt.Println(result)
  856. }
  857. // To create a key pair
  858. //
  859. // This example creates a key pair named my-key-pair.
  860. func ExampleEC2_CreateKeyPair_shared00() {
  861. svc := ec2.New(session.New())
  862. input := &ec2.CreateKeyPairInput{
  863. KeyName: aws.String("my-key-pair"),
  864. }
  865. result, err := svc.CreateKeyPair(input)
  866. if err != nil {
  867. if aerr, ok := err.(awserr.Error); ok {
  868. switch aerr.Code() {
  869. default:
  870. fmt.Println(aerr.Error())
  871. }
  872. } else {
  873. // Print the error, cast err to awserr.Error to get the Code and
  874. // Message from an error.
  875. fmt.Println(err.Error())
  876. }
  877. return
  878. }
  879. fmt.Println(result)
  880. }
  881. // To create a launch template
  882. //
  883. // This example creates a launch template that specifies the subnet in which to launch
  884. // the instance, assigns a public IP address and an IPv6 address to the instance, and
  885. // creates a tag for the instance.
  886. func ExampleEC2_CreateLaunchTemplate_shared00() {
  887. svc := ec2.New(session.New())
  888. input := &ec2.CreateLaunchTemplateInput{
  889. LaunchTemplateData: &ec2.RequestLaunchTemplateData{
  890. ImageId: aws.String("ami-8c1be5f6"),
  891. InstanceType: aws.String("t2.small"),
  892. NetworkInterfaces: []*ec2.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest{
  893. {
  894. AssociatePublicIpAddress: aws.Bool(true),
  895. DeviceIndex: aws.Int64(0),
  896. Ipv6AddressCount: aws.Int64(1),
  897. SubnetId: aws.String("subnet-7b16de0c"),
  898. },
  899. },
  900. TagSpecifications: []*ec2.LaunchTemplateTagSpecificationRequest{
  901. {
  902. ResourceType: aws.String("instance"),
  903. Tags: []*ec2.Tag{
  904. {
  905. Key: aws.String("Name"),
  906. Value: aws.String("webserver"),
  907. },
  908. },
  909. },
  910. },
  911. },
  912. LaunchTemplateName: aws.String("my-template"),
  913. VersionDescription: aws.String("WebVersion1"),
  914. }
  915. result, err := svc.CreateLaunchTemplate(input)
  916. if err != nil {
  917. if aerr, ok := err.(awserr.Error); ok {
  918. switch aerr.Code() {
  919. default:
  920. fmt.Println(aerr.Error())
  921. }
  922. } else {
  923. // Print the error, cast err to awserr.Error to get the Code and
  924. // Message from an error.
  925. fmt.Println(err.Error())
  926. }
  927. return
  928. }
  929. fmt.Println(result)
  930. }
  931. // To create a launch template version
  932. //
  933. // This example creates a new launch template version based on version 1 of the specified
  934. // launch template and specifies a different AMI ID.
  935. func ExampleEC2_CreateLaunchTemplateVersion_shared00() {
  936. svc := ec2.New(session.New())
  937. input := &ec2.CreateLaunchTemplateVersionInput{
  938. LaunchTemplateData: &ec2.RequestLaunchTemplateData{
  939. ImageId: aws.String("ami-c998b6b2"),
  940. },
  941. LaunchTemplateId: aws.String("lt-0abcd290751193123"),
  942. SourceVersion: aws.String("1"),
  943. VersionDescription: aws.String("WebVersion2"),
  944. }
  945. result, err := svc.CreateLaunchTemplateVersion(input)
  946. if err != nil {
  947. if aerr, ok := err.(awserr.Error); ok {
  948. switch aerr.Code() {
  949. default:
  950. fmt.Println(aerr.Error())
  951. }
  952. } else {
  953. // Print the error, cast err to awserr.Error to get the Code and
  954. // Message from an error.
  955. fmt.Println(err.Error())
  956. }
  957. return
  958. }
  959. fmt.Println(result)
  960. }
  961. // To create a NAT gateway
  962. //
  963. // This example creates a NAT gateway in subnet subnet-1a2b3c4d and associates an Elastic
  964. // IP address with the allocation ID eipalloc-37fc1a52 with the NAT gateway.
  965. func ExampleEC2_CreateNatGateway_shared00() {
  966. svc := ec2.New(session.New())
  967. input := &ec2.CreateNatGatewayInput{
  968. AllocationId: aws.String("eipalloc-37fc1a52"),
  969. SubnetId: aws.String("subnet-1a2b3c4d"),
  970. }
  971. result, err := svc.CreateNatGateway(input)
  972. if err != nil {
  973. if aerr, ok := err.(awserr.Error); ok {
  974. switch aerr.Code() {
  975. default:
  976. fmt.Println(aerr.Error())
  977. }
  978. } else {
  979. // Print the error, cast err to awserr.Error to get the Code and
  980. // Message from an error.
  981. fmt.Println(err.Error())
  982. }
  983. return
  984. }
  985. fmt.Println(result)
  986. }
  987. // To create a network ACL
  988. //
  989. // This example creates a network ACL for the specified VPC.
  990. func ExampleEC2_CreateNetworkAcl_shared00() {
  991. svc := ec2.New(session.New())
  992. input := &ec2.CreateNetworkAclInput{
  993. VpcId: aws.String("vpc-a01106c2"),
  994. }
  995. result, err := svc.CreateNetworkAcl(input)
  996. if err != nil {
  997. if aerr, ok := err.(awserr.Error); ok {
  998. switch aerr.Code() {
  999. default:
  1000. fmt.Println(aerr.Error())
  1001. }
  1002. } else {
  1003. // Print the error, cast err to awserr.Error to get the Code and
  1004. // Message from an error.
  1005. fmt.Println(err.Error())
  1006. }
  1007. return
  1008. }
  1009. fmt.Println(result)
  1010. }
  1011. // To create a network ACL entry
  1012. //
  1013. // This example creates an entry for the specified network ACL. The rule allows ingress
  1014. // traffic from anywhere (0.0.0.0/0) on UDP port 53 (DNS) into any associated subnet.
  1015. func ExampleEC2_CreateNetworkAclEntry_shared00() {
  1016. svc := ec2.New(session.New())
  1017. input := &ec2.CreateNetworkAclEntryInput{
  1018. CidrBlock: aws.String("0.0.0.0/0"),
  1019. Egress: aws.Bool(false),
  1020. NetworkAclId: aws.String("acl-5fb85d36"),
  1021. PortRange: &ec2.PortRange{
  1022. From: aws.Int64(53),
  1023. To: aws.Int64(53),
  1024. },
  1025. Protocol: aws.String("17"),
  1026. RuleAction: aws.String("allow"),
  1027. RuleNumber: aws.Int64(100),
  1028. }
  1029. result, err := svc.CreateNetworkAclEntry(input)
  1030. if err != nil {
  1031. if aerr, ok := err.(awserr.Error); ok {
  1032. switch aerr.Code() {
  1033. default:
  1034. fmt.Println(aerr.Error())
  1035. }
  1036. } else {
  1037. // Print the error, cast err to awserr.Error to get the Code and
  1038. // Message from an error.
  1039. fmt.Println(err.Error())
  1040. }
  1041. return
  1042. }
  1043. fmt.Println(result)
  1044. }
  1045. // To create a network interface
  1046. //
  1047. // This example creates a network interface for the specified subnet.
  1048. func ExampleEC2_CreateNetworkInterface_shared00() {
  1049. svc := ec2.New(session.New())
  1050. input := &ec2.CreateNetworkInterfaceInput{
  1051. Description: aws.String("my network interface"),
  1052. Groups: []*string{
  1053. aws.String("sg-903004f8"),
  1054. },
  1055. PrivateIpAddress: aws.String("10.0.2.17"),
  1056. SubnetId: aws.String("subnet-9d4a7b6c"),
  1057. }
  1058. result, err := svc.CreateNetworkInterface(input)
  1059. if err != nil {
  1060. if aerr, ok := err.(awserr.Error); ok {
  1061. switch aerr.Code() {
  1062. default:
  1063. fmt.Println(aerr.Error())
  1064. }
  1065. } else {
  1066. // Print the error, cast err to awserr.Error to get the Code and
  1067. // Message from an error.
  1068. fmt.Println(err.Error())
  1069. }
  1070. return
  1071. }
  1072. fmt.Println(result)
  1073. }
  1074. // To create a placement group
  1075. //
  1076. // This example creates a placement group with the specified name.
  1077. func ExampleEC2_CreatePlacementGroup_shared00() {
  1078. svc := ec2.New(session.New())
  1079. input := &ec2.CreatePlacementGroupInput{
  1080. GroupName: aws.String("my-cluster"),
  1081. Strategy: aws.String("cluster"),
  1082. }
  1083. result, err := svc.CreatePlacementGroup(input)
  1084. if err != nil {
  1085. if aerr, ok := err.(awserr.Error); ok {
  1086. switch aerr.Code() {
  1087. default:
  1088. fmt.Println(aerr.Error())
  1089. }
  1090. } else {
  1091. // Print the error, cast err to awserr.Error to get the Code and
  1092. // Message from an error.
  1093. fmt.Println(err.Error())
  1094. }
  1095. return
  1096. }
  1097. fmt.Println(result)
  1098. }
  1099. // To create a route
  1100. //
  1101. // This example creates a route for the specified route table. The route matches all
  1102. // traffic (0.0.0.0/0) and routes it to the specified Internet gateway.
  1103. func ExampleEC2_CreateRoute_shared00() {
  1104. svc := ec2.New(session.New())
  1105. input := &ec2.CreateRouteInput{
  1106. DestinationCidrBlock: aws.String("0.0.0.0/0"),
  1107. GatewayId: aws.String("igw-c0a643a9"),
  1108. RouteTableId: aws.String("rtb-22574640"),
  1109. }
  1110. result, err := svc.CreateRoute(input)
  1111. if err != nil {
  1112. if aerr, ok := err.(awserr.Error); ok {
  1113. switch aerr.Code() {
  1114. default:
  1115. fmt.Println(aerr.Error())
  1116. }
  1117. } else {
  1118. // Print the error, cast err to awserr.Error to get the Code and
  1119. // Message from an error.
  1120. fmt.Println(err.Error())
  1121. }
  1122. return
  1123. }
  1124. fmt.Println(result)
  1125. }
  1126. // To create a route table
  1127. //
  1128. // This example creates a route table for the specified VPC.
  1129. func ExampleEC2_CreateRouteTable_shared00() {
  1130. svc := ec2.New(session.New())
  1131. input := &ec2.CreateRouteTableInput{
  1132. VpcId: aws.String("vpc-a01106c2"),
  1133. }
  1134. result, err := svc.CreateRouteTable(input)
  1135. if err != nil {
  1136. if aerr, ok := err.(awserr.Error); ok {
  1137. switch aerr.Code() {
  1138. default:
  1139. fmt.Println(aerr.Error())
  1140. }
  1141. } else {
  1142. // Print the error, cast err to awserr.Error to get the Code and
  1143. // Message from an error.
  1144. fmt.Println(err.Error())
  1145. }
  1146. return
  1147. }
  1148. fmt.Println(result)
  1149. }
  1150. // To create a security group for a VPC
  1151. //
  1152. // This example creates a security group for the specified VPC.
  1153. func ExampleEC2_CreateSecurityGroup_shared00() {
  1154. svc := ec2.New(session.New())
  1155. input := &ec2.CreateSecurityGroupInput{
  1156. Description: aws.String("My security group"),
  1157. GroupName: aws.String("my-security-group"),
  1158. VpcId: aws.String("vpc-1a2b3c4d"),
  1159. }
  1160. result, err := svc.CreateSecurityGroup(input)
  1161. if err != nil {
  1162. if aerr, ok := err.(awserr.Error); ok {
  1163. switch aerr.Code() {
  1164. default:
  1165. fmt.Println(aerr.Error())
  1166. }
  1167. } else {
  1168. // Print the error, cast err to awserr.Error to get the Code and
  1169. // Message from an error.
  1170. fmt.Println(err.Error())
  1171. }
  1172. return
  1173. }
  1174. fmt.Println(result)
  1175. }
  1176. // To create a snapshot
  1177. //
  1178. // This example creates a snapshot of the volume with a volume ID of ``vol-1234567890abcdef0``
  1179. // and a short description to identify the snapshot.
  1180. func ExampleEC2_CreateSnapshot_shared00() {
  1181. svc := ec2.New(session.New())
  1182. input := &ec2.CreateSnapshotInput{
  1183. Description: aws.String("This is my root volume snapshot."),
  1184. VolumeId: aws.String("vol-1234567890abcdef0"),
  1185. }
  1186. result, err := svc.CreateSnapshot(input)
  1187. if err != nil {
  1188. if aerr, ok := err.(awserr.Error); ok {
  1189. switch aerr.Code() {
  1190. default:
  1191. fmt.Println(aerr.Error())
  1192. }
  1193. } else {
  1194. // Print the error, cast err to awserr.Error to get the Code and
  1195. // Message from an error.
  1196. fmt.Println(err.Error())
  1197. }
  1198. return
  1199. }
  1200. fmt.Println(result)
  1201. }
  1202. // To create a Spot Instance datafeed
  1203. //
  1204. // This example creates a Spot Instance data feed for your AWS account.
  1205. func ExampleEC2_CreateSpotDatafeedSubscription_shared00() {
  1206. svc := ec2.New(session.New())
  1207. input := &ec2.CreateSpotDatafeedSubscriptionInput{
  1208. Bucket: aws.String("my-s3-bucket"),
  1209. Prefix: aws.String("spotdata"),
  1210. }
  1211. result, err := svc.CreateSpotDatafeedSubscription(input)
  1212. if err != nil {
  1213. if aerr, ok := err.(awserr.Error); ok {
  1214. switch aerr.Code() {
  1215. default:
  1216. fmt.Println(aerr.Error())
  1217. }
  1218. } else {
  1219. // Print the error, cast err to awserr.Error to get the Code and
  1220. // Message from an error.
  1221. fmt.Println(err.Error())
  1222. }
  1223. return
  1224. }
  1225. fmt.Println(result)
  1226. }
  1227. // To create a subnet
  1228. //
  1229. // This example creates a subnet in the specified VPC with the specified CIDR block.
  1230. // We recommend that you let us select an Availability Zone for you.
  1231. func ExampleEC2_CreateSubnet_shared00() {
  1232. svc := ec2.New(session.New())
  1233. input := &ec2.CreateSubnetInput{
  1234. CidrBlock: aws.String("10.0.1.0/24"),
  1235. VpcId: aws.String("vpc-a01106c2"),
  1236. }
  1237. result, err := svc.CreateSubnet(input)
  1238. if err != nil {
  1239. if aerr, ok := err.(awserr.Error); ok {
  1240. switch aerr.Code() {
  1241. default:
  1242. fmt.Println(aerr.Error())
  1243. }
  1244. } else {
  1245. // Print the error, cast err to awserr.Error to get the Code and
  1246. // Message from an error.
  1247. fmt.Println(err.Error())
  1248. }
  1249. return
  1250. }
  1251. fmt.Println(result)
  1252. }
  1253. // To add a tag to a resource
  1254. //
  1255. // This example adds the tag Stack=production to the specified image, or overwrites
  1256. // an existing tag for the AMI where the tag key is Stack.
  1257. func ExampleEC2_CreateTags_shared00() {
  1258. svc := ec2.New(session.New())
  1259. input := &ec2.CreateTagsInput{
  1260. Resources: []*string{
  1261. aws.String("ami-78a54011"),
  1262. },
  1263. Tags: []*ec2.Tag{
  1264. {
  1265. Key: aws.String("Stack"),
  1266. Value: aws.String("production"),
  1267. },
  1268. },
  1269. }
  1270. result, err := svc.CreateTags(input)
  1271. if err != nil {
  1272. if aerr, ok := err.(awserr.Error); ok {
  1273. switch aerr.Code() {
  1274. default:
  1275. fmt.Println(aerr.Error())
  1276. }
  1277. } else {
  1278. // Print the error, cast err to awserr.Error to get the Code and
  1279. // Message from an error.
  1280. fmt.Println(err.Error())
  1281. }
  1282. return
  1283. }
  1284. fmt.Println(result)
  1285. }
  1286. // To create a new volume
  1287. //
  1288. // This example creates an 80 GiB General Purpose (SSD) volume in the Availability Zone
  1289. // ``us-east-1a``.
  1290. func ExampleEC2_CreateVolume_shared00() {
  1291. svc := ec2.New(session.New())
  1292. input := &ec2.CreateVolumeInput{
  1293. AvailabilityZone: aws.String("us-east-1a"),
  1294. Size: aws.Int64(80),
  1295. VolumeType: aws.String("gp2"),
  1296. }
  1297. result, err := svc.CreateVolume(input)
  1298. if err != nil {
  1299. if aerr, ok := err.(awserr.Error); ok {
  1300. switch aerr.Code() {
  1301. default:
  1302. fmt.Println(aerr.Error())
  1303. }
  1304. } else {
  1305. // Print the error, cast err to awserr.Error to get the Code and
  1306. // Message from an error.
  1307. fmt.Println(err.Error())
  1308. }
  1309. return
  1310. }
  1311. fmt.Println(result)
  1312. }
  1313. // To create a new Provisioned IOPS (SSD) volume from a snapshot
  1314. //
  1315. // This example creates a new Provisioned IOPS (SSD) volume with 1000 provisioned IOPS
  1316. // from a snapshot in the Availability Zone ``us-east-1a``.
  1317. func ExampleEC2_CreateVolume_shared01() {
  1318. svc := ec2.New(session.New())
  1319. input := &ec2.CreateVolumeInput{
  1320. AvailabilityZone: aws.String("us-east-1a"),
  1321. Iops: aws.Int64(1000),
  1322. SnapshotId: aws.String("snap-066877671789bd71b"),
  1323. VolumeType: aws.String("io1"),
  1324. }
  1325. result, err := svc.CreateVolume(input)
  1326. if err != nil {
  1327. if aerr, ok := err.(awserr.Error); ok {
  1328. switch aerr.Code() {
  1329. default:
  1330. fmt.Println(aerr.Error())
  1331. }
  1332. } else {
  1333. // Print the error, cast err to awserr.Error to get the Code and
  1334. // Message from an error.
  1335. fmt.Println(err.Error())
  1336. }
  1337. return
  1338. }
  1339. fmt.Println(result)
  1340. }
  1341. // To create a VPC
  1342. //
  1343. // This example creates a VPC with the specified CIDR block.
  1344. func ExampleEC2_CreateVpc_shared00() {
  1345. svc := ec2.New(session.New())
  1346. input := &ec2.CreateVpcInput{
  1347. CidrBlock: aws.String("10.0.0.0/16"),
  1348. }
  1349. result, err := svc.CreateVpc(input)
  1350. if err != nil {
  1351. if aerr, ok := err.(awserr.Error); ok {
  1352. switch aerr.Code() {
  1353. default:
  1354. fmt.Println(aerr.Error())
  1355. }
  1356. } else {
  1357. // Print the error, cast err to awserr.Error to get the Code and
  1358. // Message from an error.
  1359. fmt.Println(err.Error())
  1360. }
  1361. return
  1362. }
  1363. fmt.Println(result)
  1364. }
  1365. // To delete a customer gateway
  1366. //
  1367. // This example deletes the specified customer gateway.
  1368. func ExampleEC2_DeleteCustomerGateway_shared00() {
  1369. svc := ec2.New(session.New())
  1370. input := &ec2.DeleteCustomerGatewayInput{
  1371. CustomerGatewayId: aws.String("cgw-0e11f167"),
  1372. }
  1373. result, err := svc.DeleteCustomerGateway(input)
  1374. if err != nil {
  1375. if aerr, ok := err.(awserr.Error); ok {
  1376. switch aerr.Code() {
  1377. default:
  1378. fmt.Println(aerr.Error())
  1379. }
  1380. } else {
  1381. // Print the error, cast err to awserr.Error to get the Code and
  1382. // Message from an error.
  1383. fmt.Println(err.Error())
  1384. }
  1385. return
  1386. }
  1387. fmt.Println(result)
  1388. }
  1389. // To delete a DHCP options set
  1390. //
  1391. // This example deletes the specified DHCP options set.
  1392. func ExampleEC2_DeleteDhcpOptions_shared00() {
  1393. svc := ec2.New(session.New())
  1394. input := &ec2.DeleteDhcpOptionsInput{
  1395. DhcpOptionsId: aws.String("dopt-d9070ebb"),
  1396. }
  1397. result, err := svc.DeleteDhcpOptions(input)
  1398. if err != nil {
  1399. if aerr, ok := err.(awserr.Error); ok {
  1400. switch aerr.Code() {
  1401. default:
  1402. fmt.Println(aerr.Error())
  1403. }
  1404. } else {
  1405. // Print the error, cast err to awserr.Error to get the Code and
  1406. // Message from an error.
  1407. fmt.Println(err.Error())
  1408. }
  1409. return
  1410. }
  1411. fmt.Println(result)
  1412. }
  1413. // To delete an Internet gateway
  1414. //
  1415. // This example deletes the specified Internet gateway.
  1416. func ExampleEC2_DeleteInternetGateway_shared00() {
  1417. svc := ec2.New(session.New())
  1418. input := &ec2.DeleteInternetGatewayInput{
  1419. InternetGatewayId: aws.String("igw-c0a643a9"),
  1420. }
  1421. result, err := svc.DeleteInternetGateway(input)
  1422. if err != nil {
  1423. if aerr, ok := err.(awserr.Error); ok {
  1424. switch aerr.Code() {
  1425. default:
  1426. fmt.Println(aerr.Error())
  1427. }
  1428. } else {
  1429. // Print the error, cast err to awserr.Error to get the Code and
  1430. // Message from an error.
  1431. fmt.Println(err.Error())
  1432. }
  1433. return
  1434. }
  1435. fmt.Println(result)
  1436. }
  1437. // To delete a key pair
  1438. //
  1439. // This example deletes the specified key pair.
  1440. func ExampleEC2_DeleteKeyPair_shared00() {
  1441. svc := ec2.New(session.New())
  1442. input := &ec2.DeleteKeyPairInput{
  1443. KeyName: aws.String("my-key-pair"),
  1444. }
  1445. result, err := svc.DeleteKeyPair(input)
  1446. if err != nil {
  1447. if aerr, ok := err.(awserr.Error); ok {
  1448. switch aerr.Code() {
  1449. default:
  1450. fmt.Println(aerr.Error())
  1451. }
  1452. } else {
  1453. // Print the error, cast err to awserr.Error to get the Code and
  1454. // Message from an error.
  1455. fmt.Println(err.Error())
  1456. }
  1457. return
  1458. }
  1459. fmt.Println(result)
  1460. }
  1461. // To delete a launch template
  1462. //
  1463. // This example deletes the specified launch template.
  1464. func ExampleEC2_DeleteLaunchTemplate_shared00() {
  1465. svc := ec2.New(session.New())
  1466. input := &ec2.DeleteLaunchTemplateInput{
  1467. LaunchTemplateId: aws.String("lt-0abcd290751193123"),
  1468. }
  1469. result, err := svc.DeleteLaunchTemplate(input)
  1470. if err != nil {
  1471. if aerr, ok := err.(awserr.Error); ok {
  1472. switch aerr.Code() {
  1473. default:
  1474. fmt.Println(aerr.Error())
  1475. }
  1476. } else {
  1477. // Print the error, cast err to awserr.Error to get the Code and
  1478. // Message from an error.
  1479. fmt.Println(err.Error())
  1480. }
  1481. return
  1482. }
  1483. fmt.Println(result)
  1484. }
  1485. // To delete a launch template version
  1486. //
  1487. // This example deletes the specified launch template version.
  1488. func ExampleEC2_DeleteLaunchTemplateVersions_shared00() {
  1489. svc := ec2.New(session.New())
  1490. input := &ec2.DeleteLaunchTemplateVersionsInput{
  1491. LaunchTemplateId: aws.String("lt-0abcd290751193123"),
  1492. Versions: []*string{
  1493. aws.String("1"),
  1494. },
  1495. }
  1496. result, err := svc.DeleteLaunchTemplateVersions(input)
  1497. if err != nil {
  1498. if aerr, ok := err.(awserr.Error); ok {
  1499. switch aerr.Code() {
  1500. default:
  1501. fmt.Println(aerr.Error())
  1502. }
  1503. } else {
  1504. // Print the error, cast err to awserr.Error to get the Code and
  1505. // Message from an error.
  1506. fmt.Println(err.Error())
  1507. }
  1508. return
  1509. }
  1510. fmt.Println(result)
  1511. }
  1512. // To delete a NAT gateway
  1513. //
  1514. // This example deletes the specified NAT gateway.
  1515. func ExampleEC2_DeleteNatGateway_shared00() {
  1516. svc := ec2.New(session.New())
  1517. input := &ec2.DeleteNatGatewayInput{
  1518. NatGatewayId: aws.String("nat-04ae55e711cec5680"),
  1519. }
  1520. result, err := svc.DeleteNatGateway(input)
  1521. if err != nil {
  1522. if aerr, ok := err.(awserr.Error); ok {
  1523. switch aerr.Code() {
  1524. default:
  1525. fmt.Println(aerr.Error())
  1526. }
  1527. } else {
  1528. // Print the error, cast err to awserr.Error to get the Code and
  1529. // Message from an error.
  1530. fmt.Println(err.Error())
  1531. }
  1532. return
  1533. }
  1534. fmt.Println(result)
  1535. }
  1536. // To delete a network ACL
  1537. //
  1538. // This example deletes the specified network ACL.
  1539. func ExampleEC2_DeleteNetworkAcl_shared00() {
  1540. svc := ec2.New(session.New())
  1541. input := &ec2.DeleteNetworkAclInput{
  1542. NetworkAclId: aws.String("acl-5fb85d36"),
  1543. }
  1544. result, err := svc.DeleteNetworkAcl(input)
  1545. if err != nil {
  1546. if aerr, ok := err.(awserr.Error); ok {
  1547. switch aerr.Code() {
  1548. default:
  1549. fmt.Println(aerr.Error())
  1550. }
  1551. } else {
  1552. // Print the error, cast err to awserr.Error to get the Code and
  1553. // Message from an error.
  1554. fmt.Println(err.Error())
  1555. }
  1556. return
  1557. }
  1558. fmt.Println(result)
  1559. }
  1560. // To delete a network ACL entry
  1561. //
  1562. // This example deletes ingress rule number 100 from the specified network ACL.
  1563. func ExampleEC2_DeleteNetworkAclEntry_shared00() {
  1564. svc := ec2.New(session.New())
  1565. input := &ec2.DeleteNetworkAclEntryInput{
  1566. Egress: aws.Bool(true),
  1567. NetworkAclId: aws.String("acl-5fb85d36"),
  1568. RuleNumber: aws.Int64(100),
  1569. }
  1570. result, err := svc.DeleteNetworkAclEntry(input)
  1571. if err != nil {
  1572. if aerr, ok := err.(awserr.Error); ok {
  1573. switch aerr.Code() {
  1574. default:
  1575. fmt.Println(aerr.Error())
  1576. }
  1577. } else {
  1578. // Print the error, cast err to awserr.Error to get the Code and
  1579. // Message from an error.
  1580. fmt.Println(err.Error())
  1581. }
  1582. return
  1583. }
  1584. fmt.Println(result)
  1585. }
  1586. // To delete a network interface
  1587. //
  1588. // This example deletes the specified network interface.
  1589. func ExampleEC2_DeleteNetworkInterface_shared00() {
  1590. svc := ec2.New(session.New())
  1591. input := &ec2.DeleteNetworkInterfaceInput{
  1592. NetworkInterfaceId: aws.String("eni-e5aa89a3"),
  1593. }
  1594. result, err := svc.DeleteNetworkInterface(input)
  1595. if err != nil {
  1596. if aerr, ok := err.(awserr.Error); ok {
  1597. switch aerr.Code() {
  1598. default:
  1599. fmt.Println(aerr.Error())
  1600. }
  1601. } else {
  1602. // Print the error, cast err to awserr.Error to get the Code and
  1603. // Message from an error.
  1604. fmt.Println(err.Error())
  1605. }
  1606. return
  1607. }
  1608. fmt.Println(result)
  1609. }
  1610. // To delete a placement group
  1611. //
  1612. // This example deletes the specified placement group.
  1613. //
  1614. func ExampleEC2_DeletePlacementGroup_shared00() {
  1615. svc := ec2.New(session.New())
  1616. input := &ec2.DeletePlacementGroupInput{
  1617. GroupName: aws.String("my-cluster"),
  1618. }
  1619. result, err := svc.DeletePlacementGroup(input)
  1620. if err != nil {
  1621. if aerr, ok := err.(awserr.Error); ok {
  1622. switch aerr.Code() {
  1623. default:
  1624. fmt.Println(aerr.Error())
  1625. }
  1626. } else {
  1627. // Print the error, cast err to awserr.Error to get the Code and
  1628. // Message from an error.
  1629. fmt.Println(err.Error())
  1630. }
  1631. return
  1632. }
  1633. fmt.Println(result)
  1634. }
  1635. // To delete a route
  1636. //
  1637. // This example deletes the specified route from the specified route table.
  1638. func ExampleEC2_DeleteRoute_shared00() {
  1639. svc := ec2.New(session.New())
  1640. input := &ec2.DeleteRouteInput{
  1641. DestinationCidrBlock: aws.String("0.0.0.0/0"),
  1642. RouteTableId: aws.String("rtb-22574640"),
  1643. }
  1644. result, err := svc.DeleteRoute(input)
  1645. if err != nil {
  1646. if aerr, ok := err.(awserr.Error); ok {
  1647. switch aerr.Code() {
  1648. default:
  1649. fmt.Println(aerr.Error())
  1650. }
  1651. } else {
  1652. // Print the error, cast err to awserr.Error to get the Code and
  1653. // Message from an error.
  1654. fmt.Println(err.Error())
  1655. }
  1656. return
  1657. }
  1658. fmt.Println(result)
  1659. }
  1660. // To delete a route table
  1661. //
  1662. // This example deletes the specified route table.
  1663. func ExampleEC2_DeleteRouteTable_shared00() {
  1664. svc := ec2.New(session.New())
  1665. input := &ec2.DeleteRouteTableInput{
  1666. RouteTableId: aws.String("rtb-22574640"),
  1667. }
  1668. result, err := svc.DeleteRouteTable(input)
  1669. if err != nil {
  1670. if aerr, ok := err.(awserr.Error); ok {
  1671. switch aerr.Code() {
  1672. default:
  1673. fmt.Println(aerr.Error())
  1674. }
  1675. } else {
  1676. // Print the error, cast err to awserr.Error to get the Code and
  1677. // Message from an error.
  1678. fmt.Println(err.Error())
  1679. }
  1680. return
  1681. }
  1682. fmt.Println(result)
  1683. }
  1684. // To delete a security group
  1685. //
  1686. // This example deletes the specified security group.
  1687. func ExampleEC2_DeleteSecurityGroup_shared00() {
  1688. svc := ec2.New(session.New())
  1689. input := &ec2.DeleteSecurityGroupInput{
  1690. GroupId: aws.String("sg-903004f8"),
  1691. }
  1692. result, err := svc.DeleteSecurityGroup(input)
  1693. if err != nil {
  1694. if aerr, ok := err.(awserr.Error); ok {
  1695. switch aerr.Code() {
  1696. default:
  1697. fmt.Println(aerr.Error())
  1698. }
  1699. } else {
  1700. // Print the error, cast err to awserr.Error to get the Code and
  1701. // Message from an error.
  1702. fmt.Println(err.Error())
  1703. }
  1704. return
  1705. }
  1706. fmt.Println(result)
  1707. }
  1708. // To delete a snapshot
  1709. //
  1710. // This example deletes a snapshot with the snapshot ID of ``snap-1234567890abcdef0``.
  1711. // If the command succeeds, no output is returned.
  1712. func ExampleEC2_DeleteSnapshot_shared00() {
  1713. svc := ec2.New(session.New())
  1714. input := &ec2.DeleteSnapshotInput{
  1715. SnapshotId: aws.String("snap-1234567890abcdef0"),
  1716. }
  1717. result, err := svc.DeleteSnapshot(input)
  1718. if err != nil {
  1719. if aerr, ok := err.(awserr.Error); ok {
  1720. switch aerr.Code() {
  1721. default:
  1722. fmt.Println(aerr.Error())
  1723. }
  1724. } else {
  1725. // Print the error, cast err to awserr.Error to get the Code and
  1726. // Message from an error.
  1727. fmt.Println(err.Error())
  1728. }
  1729. return
  1730. }
  1731. fmt.Println(result)
  1732. }
  1733. // To cancel a Spot Instance data feed subscription
  1734. //
  1735. // This example deletes a Spot data feed subscription for the account.
  1736. func ExampleEC2_DeleteSpotDatafeedSubscription_shared00() {
  1737. svc := ec2.New(session.New())
  1738. input := &ec2.DeleteSpotDatafeedSubscriptionInput{}
  1739. result, err := svc.DeleteSpotDatafeedSubscription(input)
  1740. if err != nil {
  1741. if aerr, ok := err.(awserr.Error); ok {
  1742. switch aerr.Code() {
  1743. default:
  1744. fmt.Println(aerr.Error())
  1745. }
  1746. } else {
  1747. // Print the error, cast err to awserr.Error to get the Code and
  1748. // Message from an error.
  1749. fmt.Println(err.Error())
  1750. }
  1751. return
  1752. }
  1753. fmt.Println(result)
  1754. }
  1755. // To delete a subnet
  1756. //
  1757. // This example deletes the specified subnet.
  1758. func ExampleEC2_DeleteSubnet_shared00() {
  1759. svc := ec2.New(session.New())
  1760. input := &ec2.DeleteSubnetInput{
  1761. SubnetId: aws.String("subnet-9d4a7b6c"),
  1762. }
  1763. result, err := svc.DeleteSubnet(input)
  1764. if err != nil {
  1765. if aerr, ok := err.(awserr.Error); ok {
  1766. switch aerr.Code() {
  1767. default:
  1768. fmt.Println(aerr.Error())
  1769. }
  1770. } else {
  1771. // Print the error, cast err to awserr.Error to get the Code and
  1772. // Message from an error.
  1773. fmt.Println(err.Error())
  1774. }
  1775. return
  1776. }
  1777. fmt.Println(result)
  1778. }
  1779. // To delete a tag from a resource
  1780. //
  1781. // This example deletes the tag Stack=test from the specified image.
  1782. func ExampleEC2_DeleteTags_shared00() {
  1783. svc := ec2.New(session.New())
  1784. input := &ec2.DeleteTagsInput{
  1785. Resources: []*string{
  1786. aws.String("ami-78a54011"),
  1787. },
  1788. Tags: []*ec2.Tag{
  1789. {
  1790. Key: aws.String("Stack"),
  1791. Value: aws.String("test"),
  1792. },
  1793. },
  1794. }
  1795. result, err := svc.DeleteTags(input)
  1796. if err != nil {
  1797. if aerr, ok := err.(awserr.Error); ok {
  1798. switch aerr.Code() {
  1799. default:
  1800. fmt.Println(aerr.Error())
  1801. }
  1802. } else {
  1803. // Print the error, cast err to awserr.Error to get the Code and
  1804. // Message from an error.
  1805. fmt.Println(err.Error())
  1806. }
  1807. return
  1808. }
  1809. fmt.Println(result)
  1810. }
  1811. // To delete a volume
  1812. //
  1813. // This example deletes an available volume with the volume ID of ``vol-049df61146c4d7901``.
  1814. // If the command succeeds, no output is returned.
  1815. func ExampleEC2_DeleteVolume_shared00() {
  1816. svc := ec2.New(session.New())
  1817. input := &ec2.DeleteVolumeInput{
  1818. VolumeId: aws.String("vol-049df61146c4d7901"),
  1819. }
  1820. result, err := svc.DeleteVolume(input)
  1821. if err != nil {
  1822. if aerr, ok := err.(awserr.Error); ok {
  1823. switch aerr.Code() {
  1824. default:
  1825. fmt.Println(aerr.Error())
  1826. }
  1827. } else {
  1828. // Print the error, cast err to awserr.Error to get the Code and
  1829. // Message from an error.
  1830. fmt.Println(err.Error())
  1831. }
  1832. return
  1833. }
  1834. fmt.Println(result)
  1835. }
  1836. // To delete a VPC
  1837. //
  1838. // This example deletes the specified VPC.
  1839. func ExampleEC2_DeleteVpc_shared00() {
  1840. svc := ec2.New(session.New())
  1841. input := &ec2.DeleteVpcInput{
  1842. VpcId: aws.String("vpc-a01106c2"),
  1843. }
  1844. result, err := svc.DeleteVpc(input)
  1845. if err != nil {
  1846. if aerr, ok := err.(awserr.Error); ok {
  1847. switch aerr.Code() {
  1848. default:
  1849. fmt.Println(aerr.Error())
  1850. }
  1851. } else {
  1852. // Print the error, cast err to awserr.Error to get the Code and
  1853. // Message from an error.
  1854. fmt.Println(err.Error())
  1855. }
  1856. return
  1857. }
  1858. fmt.Println(result)
  1859. }
  1860. // To describe a single attribute for your AWS account
  1861. //
  1862. // This example describes the supported-platforms attribute for your AWS account.
  1863. func ExampleEC2_DescribeAccountAttributes_shared00() {
  1864. svc := ec2.New(session.New())
  1865. input := &ec2.DescribeAccountAttributesInput{
  1866. AttributeNames: []*string{
  1867. aws.String("supported-platforms"),
  1868. },
  1869. }
  1870. result, err := svc.DescribeAccountAttributes(input)
  1871. if err != nil {
  1872. if aerr, ok := err.(awserr.Error); ok {
  1873. switch aerr.Code() {
  1874. default:
  1875. fmt.Println(aerr.Error())
  1876. }
  1877. } else {
  1878. // Print the error, cast err to awserr.Error to get the Code and
  1879. // Message from an error.
  1880. fmt.Println(err.Error())
  1881. }
  1882. return
  1883. }
  1884. fmt.Println(result)
  1885. }
  1886. // To describe all attributes for your AWS account
  1887. //
  1888. // This example describes the attributes for your AWS account.
  1889. func ExampleEC2_DescribeAccountAttributes_shared01() {
  1890. svc := ec2.New(session.New())
  1891. input := &ec2.DescribeAccountAttributesInput{}
  1892. result, err := svc.DescribeAccountAttributes(input)
  1893. if err != nil {
  1894. if aerr, ok := err.(awserr.Error); ok {
  1895. switch aerr.Code() {
  1896. default:
  1897. fmt.Println(aerr.Error())
  1898. }
  1899. } else {
  1900. // Print the error, cast err to awserr.Error to get the Code and
  1901. // Message from an error.
  1902. fmt.Println(err.Error())
  1903. }
  1904. return
  1905. }
  1906. fmt.Println(result)
  1907. }
  1908. // To describe your Elastic IP addresses
  1909. //
  1910. // This example describes your Elastic IP addresses.
  1911. func ExampleEC2_DescribeAddresses_shared00() {
  1912. svc := ec2.New(session.New())
  1913. input := &ec2.DescribeAddressesInput{}
  1914. result, err := svc.DescribeAddresses(input)
  1915. if err != nil {
  1916. if aerr, ok := err.(awserr.Error); ok {
  1917. switch aerr.Code() {
  1918. default:
  1919. fmt.Println(aerr.Error())
  1920. }
  1921. } else {
  1922. // Print the error, cast err to awserr.Error to get the Code and
  1923. // Message from an error.
  1924. fmt.Println(err.Error())
  1925. }
  1926. return
  1927. }
  1928. fmt.Println(result)
  1929. }
  1930. // To describe your Elastic IP addresses for EC2-VPC
  1931. //
  1932. // This example describes your Elastic IP addresses for use with instances in a VPC.
  1933. func ExampleEC2_DescribeAddresses_shared01() {
  1934. svc := ec2.New(session.New())
  1935. input := &ec2.DescribeAddressesInput{
  1936. Filters: []*ec2.Filter{
  1937. {
  1938. Name: aws.String("domain"),
  1939. Values: []*string{
  1940. aws.String("vpc"),
  1941. },
  1942. },
  1943. },
  1944. }
  1945. result, err := svc.DescribeAddresses(input)
  1946. if err != nil {
  1947. if aerr, ok := err.(awserr.Error); ok {
  1948. switch aerr.Code() {
  1949. default:
  1950. fmt.Println(aerr.Error())
  1951. }
  1952. } else {
  1953. // Print the error, cast err to awserr.Error to get the Code and
  1954. // Message from an error.
  1955. fmt.Println(err.Error())
  1956. }
  1957. return
  1958. }
  1959. fmt.Println(result)
  1960. }
  1961. // To describe your Elastic IP addresses for EC2-Classic
  1962. //
  1963. // This example describes your Elastic IP addresses for use with instances in EC2-Classic.
  1964. func ExampleEC2_DescribeAddresses_shared02() {
  1965. svc := ec2.New(session.New())
  1966. input := &ec2.DescribeAddressesInput{
  1967. Filters: []*ec2.Filter{
  1968. {
  1969. Name: aws.String("domain"),
  1970. Values: []*string{
  1971. aws.String("standard"),
  1972. },
  1973. },
  1974. },
  1975. }
  1976. result, err := svc.DescribeAddresses(input)
  1977. if err != nil {
  1978. if aerr, ok := err.(awserr.Error); ok {
  1979. switch aerr.Code() {
  1980. default:
  1981. fmt.Println(aerr.Error())
  1982. }
  1983. } else {
  1984. // Print the error, cast err to awserr.Error to get the Code and
  1985. // Message from an error.
  1986. fmt.Println(err.Error())
  1987. }
  1988. return
  1989. }
  1990. fmt.Println(result)
  1991. }
  1992. // To describe your Availability Zones
  1993. //
  1994. // This example describes the Availability Zones that are available to you. The response
  1995. // includes Availability Zones only for the current region.
  1996. func ExampleEC2_DescribeAvailabilityZones_shared00() {
  1997. svc := ec2.New(session.New())
  1998. input := &ec2.DescribeAvailabilityZonesInput{}
  1999. result, err := svc.DescribeAvailabilityZones(input)
  2000. if err != nil {
  2001. if aerr, ok := err.(awserr.Error); ok {
  2002. switch aerr.Code() {
  2003. default:
  2004. fmt.Println(aerr.Error())
  2005. }
  2006. } else {
  2007. // Print the error, cast err to awserr.Error to get the Code and
  2008. // Message from an error.
  2009. fmt.Println(err.Error())
  2010. }
  2011. return
  2012. }
  2013. fmt.Println(result)
  2014. }
  2015. // To describe a customer gateway
  2016. //
  2017. // This example describes the specified customer gateway.
  2018. func ExampleEC2_DescribeCustomerGateways_shared00() {
  2019. svc := ec2.New(session.New())
  2020. input := &ec2.DescribeCustomerGatewaysInput{
  2021. CustomerGatewayIds: []*string{
  2022. aws.String("cgw-0e11f167"),
  2023. },
  2024. }
  2025. result, err := svc.DescribeCustomerGateways(input)
  2026. if err != nil {
  2027. if aerr, ok := err.(awserr.Error); ok {
  2028. switch aerr.Code() {
  2029. default:
  2030. fmt.Println(aerr.Error())
  2031. }
  2032. } else {
  2033. // Print the error, cast err to awserr.Error to get the Code and
  2034. // Message from an error.
  2035. fmt.Println(err.Error())
  2036. }
  2037. return
  2038. }
  2039. fmt.Println(result)
  2040. }
  2041. // To describe a DHCP options set
  2042. //
  2043. // This example describes the specified DHCP options set.
  2044. func ExampleEC2_DescribeDhcpOptions_shared00() {
  2045. svc := ec2.New(session.New())
  2046. input := &ec2.DescribeDhcpOptionsInput{
  2047. DhcpOptionsIds: []*string{
  2048. aws.String("dopt-d9070ebb"),
  2049. },
  2050. }
  2051. result, err := svc.DescribeDhcpOptions(input)
  2052. if err != nil {
  2053. if aerr, ok := err.(awserr.Error); ok {
  2054. switch aerr.Code() {
  2055. default:
  2056. fmt.Println(aerr.Error())
  2057. }
  2058. } else {
  2059. // Print the error, cast err to awserr.Error to get the Code and
  2060. // Message from an error.
  2061. fmt.Println(err.Error())
  2062. }
  2063. return
  2064. }
  2065. fmt.Println(result)
  2066. }
  2067. // To describe an IAM instance profile association
  2068. //
  2069. // This example describes the specified IAM instance profile association.
  2070. func ExampleEC2_DescribeIamInstanceProfileAssociations_shared00() {
  2071. svc := ec2.New(session.New())
  2072. input := &ec2.DescribeIamInstanceProfileAssociationsInput{
  2073. AssociationIds: []*string{
  2074. aws.String("iip-assoc-0db249b1f25fa24b8"),
  2075. },
  2076. }
  2077. result, err := svc.DescribeIamInstanceProfileAssociations(input)
  2078. if err != nil {
  2079. if aerr, ok := err.(awserr.Error); ok {
  2080. switch aerr.Code() {
  2081. default:
  2082. fmt.Println(aerr.Error())
  2083. }
  2084. } else {
  2085. // Print the error, cast err to awserr.Error to get the Code and
  2086. // Message from an error.
  2087. fmt.Println(err.Error())
  2088. }
  2089. return
  2090. }
  2091. fmt.Println(result)
  2092. }
  2093. // To describe the launch permissions for an AMI
  2094. //
  2095. // This example describes the launch permissions for the specified AMI.
  2096. func ExampleEC2_DescribeImageAttribute_shared00() {
  2097. svc := ec2.New(session.New())
  2098. input := &ec2.DescribeImageAttributeInput{
  2099. Attribute: aws.String("launchPermission"),
  2100. ImageId: aws.String("ami-5731123e"),
  2101. }
  2102. result, err := svc.DescribeImageAttribute(input)
  2103. if err != nil {
  2104. if aerr, ok := err.(awserr.Error); ok {
  2105. switch aerr.Code() {
  2106. default:
  2107. fmt.Println(aerr.Error())
  2108. }
  2109. } else {
  2110. // Print the error, cast err to awserr.Error to get the Code and
  2111. // Message from an error.
  2112. fmt.Println(err.Error())
  2113. }
  2114. return
  2115. }
  2116. fmt.Println(result)
  2117. }
  2118. // To describe an AMI
  2119. //
  2120. // This example describes the specified AMI.
  2121. func ExampleEC2_DescribeImages_shared00() {
  2122. svc := ec2.New(session.New())
  2123. input := &ec2.DescribeImagesInput{
  2124. ImageIds: []*string{
  2125. aws.String("ami-5731123e"),
  2126. },
  2127. }
  2128. result, err := svc.DescribeImages(input)
  2129. if err != nil {
  2130. if aerr, ok := err.(awserr.Error); ok {
  2131. switch aerr.Code() {
  2132. default:
  2133. fmt.Println(aerr.Error())
  2134. }
  2135. } else {
  2136. // Print the error, cast err to awserr.Error to get the Code and
  2137. // Message from an error.
  2138. fmt.Println(err.Error())
  2139. }
  2140. return
  2141. }
  2142. fmt.Println(result)
  2143. }
  2144. // To describe the instance type
  2145. //
  2146. // This example describes the instance type of the specified instance.
  2147. //
  2148. func ExampleEC2_DescribeInstanceAttribute_shared00() {
  2149. svc := ec2.New(session.New())
  2150. input := &ec2.DescribeInstanceAttributeInput{
  2151. Attribute: aws.String("instanceType"),
  2152. InstanceId: aws.String("i-1234567890abcdef0"),
  2153. }
  2154. result, err := svc.DescribeInstanceAttribute(input)
  2155. if err != nil {
  2156. if aerr, ok := err.(awserr.Error); ok {
  2157. switch aerr.Code() {
  2158. default:
  2159. fmt.Println(aerr.Error())
  2160. }
  2161. } else {
  2162. // Print the error, cast err to awserr.Error to get the Code and
  2163. // Message from an error.
  2164. fmt.Println(err.Error())
  2165. }
  2166. return
  2167. }
  2168. fmt.Println(result)
  2169. }
  2170. // To describe the disableApiTermination attribute
  2171. //
  2172. // This example describes the ``disableApiTermination`` attribute of the specified instance.
  2173. //
  2174. func ExampleEC2_DescribeInstanceAttribute_shared01() {
  2175. svc := ec2.New(session.New())
  2176. input := &ec2.DescribeInstanceAttributeInput{
  2177. Attribute: aws.String("disableApiTermination"),
  2178. InstanceId: aws.String("i-1234567890abcdef0"),
  2179. }
  2180. result, err := svc.DescribeInstanceAttribute(input)
  2181. if err != nil {
  2182. if aerr, ok := err.(awserr.Error); ok {
  2183. switch aerr.Code() {
  2184. default:
  2185. fmt.Println(aerr.Error())
  2186. }
  2187. } else {
  2188. // Print the error, cast err to awserr.Error to get the Code and
  2189. // Message from an error.
  2190. fmt.Println(err.Error())
  2191. }
  2192. return
  2193. }
  2194. fmt.Println(result)
  2195. }
  2196. // To describe the block device mapping for an instance
  2197. //
  2198. // This example describes the ``blockDeviceMapping`` attribute of the specified instance.
  2199. //
  2200. func ExampleEC2_DescribeInstanceAttribute_shared02() {
  2201. svc := ec2.New(session.New())
  2202. input := &ec2.DescribeInstanceAttributeInput{
  2203. Attribute: aws.String("blockDeviceMapping"),
  2204. InstanceId: aws.String("i-1234567890abcdef0"),
  2205. }
  2206. result, err := svc.DescribeInstanceAttribute(input)
  2207. if err != nil {
  2208. if aerr, ok := err.(awserr.Error); ok {
  2209. switch aerr.Code() {
  2210. default:
  2211. fmt.Println(aerr.Error())
  2212. }
  2213. } else {
  2214. // Print the error, cast err to awserr.Error to get the Code and
  2215. // Message from an error.
  2216. fmt.Println(err.Error())
  2217. }
  2218. return
  2219. }
  2220. fmt.Println(result)
  2221. }
  2222. // To describe the status of an instance
  2223. //
  2224. // This example describes the current status of the specified instance.
  2225. func ExampleEC2_DescribeInstanceStatus_shared00() {
  2226. svc := ec2.New(session.New())
  2227. input := &ec2.DescribeInstanceStatusInput{
  2228. InstanceIds: []*string{
  2229. aws.String("i-1234567890abcdef0"),
  2230. },
  2231. }
  2232. result, err := svc.DescribeInstanceStatus(input)
  2233. if err != nil {
  2234. if aerr, ok := err.(awserr.Error); ok {
  2235. switch aerr.Code() {
  2236. default:
  2237. fmt.Println(aerr.Error())
  2238. }
  2239. } else {
  2240. // Print the error, cast err to awserr.Error to get the Code and
  2241. // Message from an error.
  2242. fmt.Println(err.Error())
  2243. }
  2244. return
  2245. }
  2246. fmt.Println(result)
  2247. }
  2248. // To describe an Amazon EC2 instance
  2249. //
  2250. // This example describes the specified instance.
  2251. func ExampleEC2_DescribeInstances_shared00() {
  2252. svc := ec2.New(session.New())
  2253. input := &ec2.DescribeInstancesInput{
  2254. InstanceIds: []*string{
  2255. aws.String("i-1234567890abcdef0"),
  2256. },
  2257. }
  2258. result, err := svc.DescribeInstances(input)
  2259. if err != nil {
  2260. if aerr, ok := err.(awserr.Error); ok {
  2261. switch aerr.Code() {
  2262. default:
  2263. fmt.Println(aerr.Error())
  2264. }
  2265. } else {
  2266. // Print the error, cast err to awserr.Error to get the Code and
  2267. // Message from an error.
  2268. fmt.Println(err.Error())
  2269. }
  2270. return
  2271. }
  2272. fmt.Println(result)
  2273. }
  2274. // To describe the instances with a specific instance type
  2275. //
  2276. // This example describes the instances with the t2.micro instance type.
  2277. func ExampleEC2_DescribeInstances_shared01() {
  2278. svc := ec2.New(session.New())
  2279. input := &ec2.DescribeInstancesInput{
  2280. Filters: []*ec2.Filter{
  2281. {
  2282. Name: aws.String("instance-type"),
  2283. Values: []*string{
  2284. aws.String("t2.micro"),
  2285. },
  2286. },
  2287. },
  2288. }
  2289. result, err := svc.DescribeInstances(input)
  2290. if err != nil {
  2291. if aerr, ok := err.(awserr.Error); ok {
  2292. switch aerr.Code() {
  2293. default:
  2294. fmt.Println(aerr.Error())
  2295. }
  2296. } else {
  2297. // Print the error, cast err to awserr.Error to get the Code and
  2298. // Message from an error.
  2299. fmt.Println(err.Error())
  2300. }
  2301. return
  2302. }
  2303. fmt.Println(result)
  2304. }
  2305. // To describe the instances with a specific tag
  2306. //
  2307. // This example describes the instances with the Purpose=test tag.
  2308. func ExampleEC2_DescribeInstances_shared02() {
  2309. svc := ec2.New(session.New())
  2310. input := &ec2.DescribeInstancesInput{
  2311. Filters: []*ec2.Filter{
  2312. {
  2313. Name: aws.String("tag:Purpose"),
  2314. Values: []*string{
  2315. aws.String("test"),
  2316. },
  2317. },
  2318. },
  2319. }
  2320. result, err := svc.DescribeInstances(input)
  2321. if err != nil {
  2322. if aerr, ok := err.(awserr.Error); ok {
  2323. switch aerr.Code() {
  2324. default:
  2325. fmt.Println(aerr.Error())
  2326. }
  2327. } else {
  2328. // Print the error, cast err to awserr.Error to get the Code and
  2329. // Message from an error.
  2330. fmt.Println(err.Error())
  2331. }
  2332. return
  2333. }
  2334. fmt.Println(result)
  2335. }
  2336. // To describe the Internet gateway for a VPC
  2337. //
  2338. // This example describes the Internet gateway for the specified VPC.
  2339. func ExampleEC2_DescribeInternetGateways_shared00() {
  2340. svc := ec2.New(session.New())
  2341. input := &ec2.DescribeInternetGatewaysInput{
  2342. Filters: []*ec2.Filter{
  2343. {
  2344. Name: aws.String("attachment.vpc-id"),
  2345. Values: []*string{
  2346. aws.String("vpc-a01106c2"),
  2347. },
  2348. },
  2349. },
  2350. }
  2351. result, err := svc.DescribeInternetGateways(input)
  2352. if err != nil {
  2353. if aerr, ok := err.(awserr.Error); ok {
  2354. switch aerr.Code() {
  2355. default:
  2356. fmt.Println(aerr.Error())
  2357. }
  2358. } else {
  2359. // Print the error, cast err to awserr.Error to get the Code and
  2360. // Message from an error.
  2361. fmt.Println(err.Error())
  2362. }
  2363. return
  2364. }
  2365. fmt.Println(result)
  2366. }
  2367. // To display a key pair
  2368. //
  2369. // This example displays the fingerprint for the specified key.
  2370. func ExampleEC2_DescribeKeyPairs_shared00() {
  2371. svc := ec2.New(session.New())
  2372. input := &ec2.DescribeKeyPairsInput{
  2373. KeyNames: []*string{
  2374. aws.String("my-key-pair"),
  2375. },
  2376. }
  2377. result, err := svc.DescribeKeyPairs(input)
  2378. if err != nil {
  2379. if aerr, ok := err.(awserr.Error); ok {
  2380. switch aerr.Code() {
  2381. default:
  2382. fmt.Println(aerr.Error())
  2383. }
  2384. } else {
  2385. // Print the error, cast err to awserr.Error to get the Code and
  2386. // Message from an error.
  2387. fmt.Println(err.Error())
  2388. }
  2389. return
  2390. }
  2391. fmt.Println(result)
  2392. }
  2393. // To describe the versions for a launch template
  2394. //
  2395. // This example describes the versions for the specified launch template.
  2396. func ExampleEC2_DescribeLaunchTemplateVersions_shared00() {
  2397. svc := ec2.New(session.New())
  2398. input := &ec2.DescribeLaunchTemplateVersionsInput{
  2399. LaunchTemplateId: aws.String("068f72b72934aff71"),
  2400. }
  2401. result, err := svc.DescribeLaunchTemplateVersions(input)
  2402. if err != nil {
  2403. if aerr, ok := err.(awserr.Error); ok {
  2404. switch aerr.Code() {
  2405. default:
  2406. fmt.Println(aerr.Error())
  2407. }
  2408. } else {
  2409. // Print the error, cast err to awserr.Error to get the Code and
  2410. // Message from an error.
  2411. fmt.Println(err.Error())
  2412. }
  2413. return
  2414. }
  2415. fmt.Println(result)
  2416. }
  2417. // To describe a launch template
  2418. //
  2419. // This example describes the specified launch template.
  2420. func ExampleEC2_DescribeLaunchTemplates_shared00() {
  2421. svc := ec2.New(session.New())
  2422. input := &ec2.DescribeLaunchTemplatesInput{
  2423. LaunchTemplateIds: []*string{
  2424. aws.String("lt-01238c059e3466abc"),
  2425. },
  2426. }
  2427. result, err := svc.DescribeLaunchTemplates(input)
  2428. if err != nil {
  2429. if aerr, ok := err.(awserr.Error); ok {
  2430. switch aerr.Code() {
  2431. default:
  2432. fmt.Println(aerr.Error())
  2433. }
  2434. } else {
  2435. // Print the error, cast err to awserr.Error to get the Code and
  2436. // Message from an error.
  2437. fmt.Println(err.Error())
  2438. }
  2439. return
  2440. }
  2441. fmt.Println(result)
  2442. }
  2443. // To describe your moving addresses
  2444. //
  2445. // This example describes all of your moving Elastic IP addresses.
  2446. func ExampleEC2_DescribeMovingAddresses_shared00() {
  2447. svc := ec2.New(session.New())
  2448. input := &ec2.DescribeMovingAddressesInput{}
  2449. result, err := svc.DescribeMovingAddresses(input)
  2450. if err != nil {
  2451. if aerr, ok := err.(awserr.Error); ok {
  2452. switch aerr.Code() {
  2453. default:
  2454. fmt.Println(aerr.Error())
  2455. }
  2456. } else {
  2457. // Print the error, cast err to awserr.Error to get the Code and
  2458. // Message from an error.
  2459. fmt.Println(err.Error())
  2460. }
  2461. return
  2462. }
  2463. fmt.Println(result)
  2464. }
  2465. // To describe a NAT gateway
  2466. //
  2467. // This example describes the NAT gateway for the specified VPC.
  2468. func ExampleEC2_DescribeNatGateways_shared00() {
  2469. svc := ec2.New(session.New())
  2470. input := &ec2.DescribeNatGatewaysInput{
  2471. Filter: []*ec2.Filter{
  2472. {
  2473. Name: aws.String("vpc-id"),
  2474. Values: []*string{
  2475. aws.String("vpc-1a2b3c4d"),
  2476. },
  2477. },
  2478. },
  2479. }
  2480. result, err := svc.DescribeNatGateways(input)
  2481. if err != nil {
  2482. if aerr, ok := err.(awserr.Error); ok {
  2483. switch aerr.Code() {
  2484. default:
  2485. fmt.Println(aerr.Error())
  2486. }
  2487. } else {
  2488. // Print the error, cast err to awserr.Error to get the Code and
  2489. // Message from an error.
  2490. fmt.Println(err.Error())
  2491. }
  2492. return
  2493. }
  2494. fmt.Println(result)
  2495. }
  2496. // To describe a network ACL
  2497. //
  2498. // This example describes the specified network ACL.
  2499. func ExampleEC2_DescribeNetworkAcls_shared00() {
  2500. svc := ec2.New(session.New())
  2501. input := &ec2.DescribeNetworkAclsInput{
  2502. NetworkAclIds: []*string{
  2503. aws.String("acl-5fb85d36"),
  2504. },
  2505. }
  2506. result, err := svc.DescribeNetworkAcls(input)
  2507. if err != nil {
  2508. if aerr, ok := err.(awserr.Error); ok {
  2509. switch aerr.Code() {
  2510. default:
  2511. fmt.Println(aerr.Error())
  2512. }
  2513. } else {
  2514. // Print the error, cast err to awserr.Error to get the Code and
  2515. // Message from an error.
  2516. fmt.Println(err.Error())
  2517. }
  2518. return
  2519. }
  2520. fmt.Println(result)
  2521. }
  2522. // To describe the attachment attribute of a network interface
  2523. //
  2524. // This example describes the attachment attribute of the specified network interface.
  2525. func ExampleEC2_DescribeNetworkInterfaceAttribute_shared00() {
  2526. svc := ec2.New(session.New())
  2527. input := &ec2.DescribeNetworkInterfaceAttributeInput{
  2528. Attribute: aws.String("attachment"),
  2529. NetworkInterfaceId: aws.String("eni-686ea200"),
  2530. }
  2531. result, err := svc.DescribeNetworkInterfaceAttribute(input)
  2532. if err != nil {
  2533. if aerr, ok := err.(awserr.Error); ok {
  2534. switch aerr.Code() {
  2535. default:
  2536. fmt.Println(aerr.Error())
  2537. }
  2538. } else {
  2539. // Print the error, cast err to awserr.Error to get the Code and
  2540. // Message from an error.
  2541. fmt.Println(err.Error())
  2542. }
  2543. return
  2544. }
  2545. fmt.Println(result)
  2546. }
  2547. // To describe the description attribute of a network interface
  2548. //
  2549. // This example describes the description attribute of the specified network interface.
  2550. func ExampleEC2_DescribeNetworkInterfaceAttribute_shared01() {
  2551. svc := ec2.New(session.New())
  2552. input := &ec2.DescribeNetworkInterfaceAttributeInput{
  2553. Attribute: aws.String("description"),
  2554. NetworkInterfaceId: aws.String("eni-686ea200"),
  2555. }
  2556. result, err := svc.DescribeNetworkInterfaceAttribute(input)
  2557. if err != nil {
  2558. if aerr, ok := err.(awserr.Error); ok {
  2559. switch aerr.Code() {
  2560. default:
  2561. fmt.Println(aerr.Error())
  2562. }
  2563. } else {
  2564. // Print the error, cast err to awserr.Error to get the Code and
  2565. // Message from an error.
  2566. fmt.Println(err.Error())
  2567. }
  2568. return
  2569. }
  2570. fmt.Println(result)
  2571. }
  2572. // To describe the groupSet attribute of a network interface
  2573. //
  2574. // This example describes the groupSet attribute of the specified network interface.
  2575. func ExampleEC2_DescribeNetworkInterfaceAttribute_shared02() {
  2576. svc := ec2.New(session.New())
  2577. input := &ec2.DescribeNetworkInterfaceAttributeInput{
  2578. Attribute: aws.String("groupSet"),
  2579. NetworkInterfaceId: aws.String("eni-686ea200"),
  2580. }
  2581. result, err := svc.DescribeNetworkInterfaceAttribute(input)
  2582. if err != nil {
  2583. if aerr, ok := err.(awserr.Error); ok {
  2584. switch aerr.Code() {
  2585. default:
  2586. fmt.Println(aerr.Error())
  2587. }
  2588. } else {
  2589. // Print the error, cast err to awserr.Error to get the Code and
  2590. // Message from an error.
  2591. fmt.Println(err.Error())
  2592. }
  2593. return
  2594. }
  2595. fmt.Println(result)
  2596. }
  2597. // To describe the sourceDestCheck attribute of a network interface
  2598. //
  2599. // This example describes the sourceDestCheck attribute of the specified network interface.
  2600. func ExampleEC2_DescribeNetworkInterfaceAttribute_shared03() {
  2601. svc := ec2.New(session.New())
  2602. input := &ec2.DescribeNetworkInterfaceAttributeInput{
  2603. Attribute: aws.String("sourceDestCheck"),
  2604. NetworkInterfaceId: aws.String("eni-686ea200"),
  2605. }
  2606. result, err := svc.DescribeNetworkInterfaceAttribute(input)
  2607. if err != nil {
  2608. if aerr, ok := err.(awserr.Error); ok {
  2609. switch aerr.Code() {
  2610. default:
  2611. fmt.Println(aerr.Error())
  2612. }
  2613. } else {
  2614. // Print the error, cast err to awserr.Error to get the Code and
  2615. // Message from an error.
  2616. fmt.Println(err.Error())
  2617. }
  2618. return
  2619. }
  2620. fmt.Println(result)
  2621. }
  2622. // To describe a network interface
  2623. //
  2624. func ExampleEC2_DescribeNetworkInterfaces_shared00() {
  2625. svc := ec2.New(session.New())
  2626. input := &ec2.DescribeNetworkInterfacesInput{
  2627. NetworkInterfaceIds: []*string{
  2628. aws.String("eni-e5aa89a3"),
  2629. },
  2630. }
  2631. result, err := svc.DescribeNetworkInterfaces(input)
  2632. if err != nil {
  2633. if aerr, ok := err.(awserr.Error); ok {
  2634. switch aerr.Code() {
  2635. default:
  2636. fmt.Println(aerr.Error())
  2637. }
  2638. } else {
  2639. // Print the error, cast err to awserr.Error to get the Code and
  2640. // Message from an error.
  2641. fmt.Println(err.Error())
  2642. }
  2643. return
  2644. }
  2645. fmt.Println(result)
  2646. }
  2647. // To describe your regions
  2648. //
  2649. // This example describes all the regions that are available to you.
  2650. func ExampleEC2_DescribeRegions_shared00() {
  2651. svc := ec2.New(session.New())
  2652. input := &ec2.DescribeRegionsInput{}
  2653. result, err := svc.DescribeRegions(input)
  2654. if err != nil {
  2655. if aerr, ok := err.(awserr.Error); ok {
  2656. switch aerr.Code() {
  2657. default:
  2658. fmt.Println(aerr.Error())
  2659. }
  2660. } else {
  2661. // Print the error, cast err to awserr.Error to get the Code and
  2662. // Message from an error.
  2663. fmt.Println(err.Error())
  2664. }
  2665. return
  2666. }
  2667. fmt.Println(result)
  2668. }
  2669. // To describe a route table
  2670. //
  2671. // This example describes the specified route table.
  2672. func ExampleEC2_DescribeRouteTables_shared00() {
  2673. svc := ec2.New(session.New())
  2674. input := &ec2.DescribeRouteTablesInput{
  2675. RouteTableIds: []*string{
  2676. aws.String("rtb-1f382e7d"),
  2677. },
  2678. }
  2679. result, err := svc.DescribeRouteTables(input)
  2680. if err != nil {
  2681. if aerr, ok := err.(awserr.Error); ok {
  2682. switch aerr.Code() {
  2683. default:
  2684. fmt.Println(aerr.Error())
  2685. }
  2686. } else {
  2687. // Print the error, cast err to awserr.Error to get the Code and
  2688. // Message from an error.
  2689. fmt.Println(err.Error())
  2690. }
  2691. return
  2692. }
  2693. fmt.Println(result)
  2694. }
  2695. // To describe an available schedule
  2696. //
  2697. // This example describes a schedule that occurs every week on Sunday, starting on the
  2698. // specified date. Note that the output contains a single schedule as an example.
  2699. func ExampleEC2_DescribeScheduledInstanceAvailability_shared00() {
  2700. svc := ec2.New(session.New())
  2701. input := &ec2.DescribeScheduledInstanceAvailabilityInput{
  2702. FirstSlotStartTimeRange: &ec2.SlotDateTimeRangeRequest{
  2703. EarliestTime: parseTime("2006-01-02T15:04:05Z", "2016-01-31T00:00:00Z"),
  2704. LatestTime: parseTime("2006-01-02T15:04:05Z", "2016-01-31T04:00:00Z"),
  2705. },
  2706. Recurrence: &ec2.ScheduledInstanceRecurrenceRequest{
  2707. Frequency: aws.String("Weekly"),
  2708. Interval: aws.Int64(1),
  2709. OccurrenceDays: []*int64{
  2710. aws.Int64(1),
  2711. },
  2712. },
  2713. }
  2714. result, err := svc.DescribeScheduledInstanceAvailability(input)
  2715. if err != nil {
  2716. if aerr, ok := err.(awserr.Error); ok {
  2717. switch aerr.Code() {
  2718. default:
  2719. fmt.Println(aerr.Error())
  2720. }
  2721. } else {
  2722. // Print the error, cast err to awserr.Error to get the Code and
  2723. // Message from an error.
  2724. fmt.Println(err.Error())
  2725. }
  2726. return
  2727. }
  2728. fmt.Println(result)
  2729. }
  2730. // To describe your Scheduled Instances
  2731. //
  2732. // This example describes the specified Scheduled Instance.
  2733. func ExampleEC2_DescribeScheduledInstances_shared00() {
  2734. svc := ec2.New(session.New())
  2735. input := &ec2.DescribeScheduledInstancesInput{
  2736. ScheduledInstanceIds: []*string{
  2737. aws.String("sci-1234-1234-1234-1234-123456789012"),
  2738. },
  2739. }
  2740. result, err := svc.DescribeScheduledInstances(input)
  2741. if err != nil {
  2742. if aerr, ok := err.(awserr.Error); ok {
  2743. switch aerr.Code() {
  2744. default:
  2745. fmt.Println(aerr.Error())
  2746. }
  2747. } else {
  2748. // Print the error, cast err to awserr.Error to get the Code and
  2749. // Message from an error.
  2750. fmt.Println(err.Error())
  2751. }
  2752. return
  2753. }
  2754. fmt.Println(result)
  2755. }
  2756. // To describe security group references
  2757. //
  2758. // This example describes the security group references for the specified security group.
  2759. func ExampleEC2_DescribeSecurityGroupReferences_shared00() {
  2760. svc := ec2.New(session.New())
  2761. input := &ec2.DescribeSecurityGroupReferencesInput{
  2762. GroupId: []*string{
  2763. aws.String("sg-903004f8"),
  2764. },
  2765. }
  2766. result, err := svc.DescribeSecurityGroupReferences(input)
  2767. if err != nil {
  2768. if aerr, ok := err.(awserr.Error); ok {
  2769. switch aerr.Code() {
  2770. default:
  2771. fmt.Println(aerr.Error())
  2772. }
  2773. } else {
  2774. // Print the error, cast err to awserr.Error to get the Code and
  2775. // Message from an error.
  2776. fmt.Println(err.Error())
  2777. }
  2778. return
  2779. }
  2780. fmt.Println(result)
  2781. }
  2782. // To describe a security group
  2783. //
  2784. // This example describes the specified security group.
  2785. func ExampleEC2_DescribeSecurityGroups_shared00() {
  2786. svc := ec2.New(session.New())
  2787. input := &ec2.DescribeSecurityGroupsInput{
  2788. GroupIds: []*string{
  2789. aws.String("sg-903004f8"),
  2790. },
  2791. }
  2792. result, err := svc.DescribeSecurityGroups(input)
  2793. if err != nil {
  2794. if aerr, ok := err.(awserr.Error); ok {
  2795. switch aerr.Code() {
  2796. default:
  2797. fmt.Println(aerr.Error())
  2798. }
  2799. } else {
  2800. // Print the error, cast err to awserr.Error to get the Code and
  2801. // Message from an error.
  2802. fmt.Println(err.Error())
  2803. }
  2804. return
  2805. }
  2806. fmt.Println(result)
  2807. }
  2808. // To describe a tagged security group
  2809. //
  2810. // This example describes the security groups that include the specified tag (Purpose=test).
  2811. func ExampleEC2_DescribeSecurityGroups_shared01() {
  2812. svc := ec2.New(session.New())
  2813. input := &ec2.DescribeSecurityGroupsInput{
  2814. Filters: []*ec2.Filter{
  2815. {
  2816. Name: aws.String("tag:Purpose"),
  2817. Values: []*string{
  2818. aws.String("test"),
  2819. },
  2820. },
  2821. },
  2822. }
  2823. result, err := svc.DescribeSecurityGroups(input)
  2824. if err != nil {
  2825. if aerr, ok := err.(awserr.Error); ok {
  2826. switch aerr.Code() {
  2827. default:
  2828. fmt.Println(aerr.Error())
  2829. }
  2830. } else {
  2831. // Print the error, cast err to awserr.Error to get the Code and
  2832. // Message from an error.
  2833. fmt.Println(err.Error())
  2834. }
  2835. return
  2836. }
  2837. fmt.Println(result)
  2838. }
  2839. // To describe snapshot attributes
  2840. //
  2841. // This example describes the ``createVolumePermission`` attribute on a snapshot with
  2842. // the snapshot ID of ``snap-066877671789bd71b``.
  2843. func ExampleEC2_DescribeSnapshotAttribute_shared00() {
  2844. svc := ec2.New(session.New())
  2845. input := &ec2.DescribeSnapshotAttributeInput{
  2846. Attribute: aws.String("createVolumePermission"),
  2847. SnapshotId: aws.String("snap-066877671789bd71b"),
  2848. }
  2849. result, err := svc.DescribeSnapshotAttribute(input)
  2850. if err != nil {
  2851. if aerr, ok := err.(awserr.Error); ok {
  2852. switch aerr.Code() {
  2853. default:
  2854. fmt.Println(aerr.Error())
  2855. }
  2856. } else {
  2857. // Print the error, cast err to awserr.Error to get the Code and
  2858. // Message from an error.
  2859. fmt.Println(err.Error())
  2860. }
  2861. return
  2862. }
  2863. fmt.Println(result)
  2864. }
  2865. // To describe a snapshot
  2866. //
  2867. // This example describes a snapshot with the snapshot ID of ``snap-1234567890abcdef0``.
  2868. func ExampleEC2_DescribeSnapshots_shared00() {
  2869. svc := ec2.New(session.New())
  2870. input := &ec2.DescribeSnapshotsInput{
  2871. SnapshotIds: []*string{
  2872. aws.String("snap-1234567890abcdef0"),
  2873. },
  2874. }
  2875. result, err := svc.DescribeSnapshots(input)
  2876. if err != nil {
  2877. if aerr, ok := err.(awserr.Error); ok {
  2878. switch aerr.Code() {
  2879. default:
  2880. fmt.Println(aerr.Error())
  2881. }
  2882. } else {
  2883. // Print the error, cast err to awserr.Error to get the Code and
  2884. // Message from an error.
  2885. fmt.Println(err.Error())
  2886. }
  2887. return
  2888. }
  2889. fmt.Println(result)
  2890. }
  2891. // To describe snapshots using filters
  2892. //
  2893. // This example describes all snapshots owned by the ID 012345678910 that are in the
  2894. // ``pending`` status.
  2895. func ExampleEC2_DescribeSnapshots_shared01() {
  2896. svc := ec2.New(session.New())
  2897. input := &ec2.DescribeSnapshotsInput{
  2898. Filters: []*ec2.Filter{
  2899. {
  2900. Name: aws.String("status"),
  2901. Values: []*string{
  2902. aws.String("pending"),
  2903. },
  2904. },
  2905. },
  2906. OwnerIds: []*string{
  2907. aws.String("012345678910"),
  2908. },
  2909. }
  2910. result, err := svc.DescribeSnapshots(input)
  2911. if err != nil {
  2912. if aerr, ok := err.(awserr.Error); ok {
  2913. switch aerr.Code() {
  2914. default:
  2915. fmt.Println(aerr.Error())
  2916. }
  2917. } else {
  2918. // Print the error, cast err to awserr.Error to get the Code and
  2919. // Message from an error.
  2920. fmt.Println(err.Error())
  2921. }
  2922. return
  2923. }
  2924. fmt.Println(result)
  2925. }
  2926. // To describe the datafeed for your AWS account
  2927. //
  2928. // This example describes the Spot Instance datafeed subscription for your AWS account.
  2929. func ExampleEC2_DescribeSpotDatafeedSubscription_shared00() {
  2930. svc := ec2.New(session.New())
  2931. input := &ec2.DescribeSpotDatafeedSubscriptionInput{}
  2932. result, err := svc.DescribeSpotDatafeedSubscription(input)
  2933. if err != nil {
  2934. if aerr, ok := err.(awserr.Error); ok {
  2935. switch aerr.Code() {
  2936. default:
  2937. fmt.Println(aerr.Error())
  2938. }
  2939. } else {
  2940. // Print the error, cast err to awserr.Error to get the Code and
  2941. // Message from an error.
  2942. fmt.Println(err.Error())
  2943. }
  2944. return
  2945. }
  2946. fmt.Println(result)
  2947. }
  2948. // To describe the Spot Instances associated with a Spot fleet
  2949. //
  2950. // This example lists the Spot Instances associated with the specified Spot fleet.
  2951. func ExampleEC2_DescribeSpotFleetInstances_shared00() {
  2952. svc := ec2.New(session.New())
  2953. input := &ec2.DescribeSpotFleetInstancesInput{
  2954. SpotFleetRequestId: aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  2955. }
  2956. result, err := svc.DescribeSpotFleetInstances(input)
  2957. if err != nil {
  2958. if aerr, ok := err.(awserr.Error); ok {
  2959. switch aerr.Code() {
  2960. default:
  2961. fmt.Println(aerr.Error())
  2962. }
  2963. } else {
  2964. // Print the error, cast err to awserr.Error to get the Code and
  2965. // Message from an error.
  2966. fmt.Println(err.Error())
  2967. }
  2968. return
  2969. }
  2970. fmt.Println(result)
  2971. }
  2972. // To describe Spot fleet history
  2973. //
  2974. // This example returns the history for the specified Spot fleet starting at the specified
  2975. // time.
  2976. func ExampleEC2_DescribeSpotFleetRequestHistory_shared00() {
  2977. svc := ec2.New(session.New())
  2978. input := &ec2.DescribeSpotFleetRequestHistoryInput{
  2979. SpotFleetRequestId: aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  2980. StartTime: parseTime("2006-01-02T15:04:05Z", "2015-05-26T00:00:00Z"),
  2981. }
  2982. result, err := svc.DescribeSpotFleetRequestHistory(input)
  2983. if err != nil {
  2984. if aerr, ok := err.(awserr.Error); ok {
  2985. switch aerr.Code() {
  2986. default:
  2987. fmt.Println(aerr.Error())
  2988. }
  2989. } else {
  2990. // Print the error, cast err to awserr.Error to get the Code and
  2991. // Message from an error.
  2992. fmt.Println(err.Error())
  2993. }
  2994. return
  2995. }
  2996. fmt.Println(result)
  2997. }
  2998. // To describe a Spot fleet request
  2999. //
  3000. // This example describes the specified Spot fleet request.
  3001. func ExampleEC2_DescribeSpotFleetRequests_shared00() {
  3002. svc := ec2.New(session.New())
  3003. input := &ec2.DescribeSpotFleetRequestsInput{
  3004. SpotFleetRequestIds: []*string{
  3005. aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  3006. },
  3007. }
  3008. result, err := svc.DescribeSpotFleetRequests(input)
  3009. if err != nil {
  3010. if aerr, ok := err.(awserr.Error); ok {
  3011. switch aerr.Code() {
  3012. default:
  3013. fmt.Println(aerr.Error())
  3014. }
  3015. } else {
  3016. // Print the error, cast err to awserr.Error to get the Code and
  3017. // Message from an error.
  3018. fmt.Println(err.Error())
  3019. }
  3020. return
  3021. }
  3022. fmt.Println(result)
  3023. }
  3024. // To describe a Spot Instance request
  3025. //
  3026. // This example describes the specified Spot Instance request.
  3027. func ExampleEC2_DescribeSpotInstanceRequests_shared00() {
  3028. svc := ec2.New(session.New())
  3029. input := &ec2.DescribeSpotInstanceRequestsInput{
  3030. SpotInstanceRequestIds: []*string{
  3031. aws.String("sir-08b93456"),
  3032. },
  3033. }
  3034. result, err := svc.DescribeSpotInstanceRequests(input)
  3035. if err != nil {
  3036. if aerr, ok := err.(awserr.Error); ok {
  3037. switch aerr.Code() {
  3038. default:
  3039. fmt.Println(aerr.Error())
  3040. }
  3041. } else {
  3042. // Print the error, cast err to awserr.Error to get the Code and
  3043. // Message from an error.
  3044. fmt.Println(err.Error())
  3045. }
  3046. return
  3047. }
  3048. fmt.Println(result)
  3049. }
  3050. // To describe Spot price history for Linux/UNIX (Amazon VPC)
  3051. //
  3052. // This example returns the Spot Price history for m1.xlarge, Linux/UNIX (Amazon VPC)
  3053. // instances for a particular day in January.
  3054. func ExampleEC2_DescribeSpotPriceHistory_shared00() {
  3055. svc := ec2.New(session.New())
  3056. input := &ec2.DescribeSpotPriceHistoryInput{
  3057. EndTime: parseTime("2006-01-02T15:04:05Z", "2014-01-06T08:09:10"),
  3058. InstanceTypes: []*string{
  3059. aws.String("m1.xlarge"),
  3060. },
  3061. ProductDescriptions: []*string{
  3062. aws.String("Linux/UNIX (Amazon VPC)"),
  3063. },
  3064. StartTime: parseTime("2006-01-02T15:04:05Z", "2014-01-06T07:08:09"),
  3065. }
  3066. result, err := svc.DescribeSpotPriceHistory(input)
  3067. if err != nil {
  3068. if aerr, ok := err.(awserr.Error); ok {
  3069. switch aerr.Code() {
  3070. default:
  3071. fmt.Println(aerr.Error())
  3072. }
  3073. } else {
  3074. // Print the error, cast err to awserr.Error to get the Code and
  3075. // Message from an error.
  3076. fmt.Println(err.Error())
  3077. }
  3078. return
  3079. }
  3080. fmt.Println(result)
  3081. }
  3082. // To describe the subnets for a VPC
  3083. //
  3084. // This example describes the subnets for the specified VPC.
  3085. func ExampleEC2_DescribeSubnets_shared00() {
  3086. svc := ec2.New(session.New())
  3087. input := &ec2.DescribeSubnetsInput{
  3088. Filters: []*ec2.Filter{
  3089. {
  3090. Name: aws.String("vpc-id"),
  3091. Values: []*string{
  3092. aws.String("vpc-a01106c2"),
  3093. },
  3094. },
  3095. },
  3096. }
  3097. result, err := svc.DescribeSubnets(input)
  3098. if err != nil {
  3099. if aerr, ok := err.(awserr.Error); ok {
  3100. switch aerr.Code() {
  3101. default:
  3102. fmt.Println(aerr.Error())
  3103. }
  3104. } else {
  3105. // Print the error, cast err to awserr.Error to get the Code and
  3106. // Message from an error.
  3107. fmt.Println(err.Error())
  3108. }
  3109. return
  3110. }
  3111. fmt.Println(result)
  3112. }
  3113. // To describe the tags for a single resource
  3114. //
  3115. // This example describes the tags for the specified instance.
  3116. func ExampleEC2_DescribeTags_shared00() {
  3117. svc := ec2.New(session.New())
  3118. input := &ec2.DescribeTagsInput{
  3119. Filters: []*ec2.Filter{
  3120. {
  3121. Name: aws.String("resource-id"),
  3122. Values: []*string{
  3123. aws.String("i-1234567890abcdef8"),
  3124. },
  3125. },
  3126. },
  3127. }
  3128. result, err := svc.DescribeTags(input)
  3129. if err != nil {
  3130. if aerr, ok := err.(awserr.Error); ok {
  3131. switch aerr.Code() {
  3132. default:
  3133. fmt.Println(aerr.Error())
  3134. }
  3135. } else {
  3136. // Print the error, cast err to awserr.Error to get the Code and
  3137. // Message from an error.
  3138. fmt.Println(err.Error())
  3139. }
  3140. return
  3141. }
  3142. fmt.Println(result)
  3143. }
  3144. // To describe a volume attribute
  3145. //
  3146. // This example describes the ``autoEnableIo`` attribute of the volume with the ID ``vol-049df61146c4d7901``.
  3147. func ExampleEC2_DescribeVolumeAttribute_shared00() {
  3148. svc := ec2.New(session.New())
  3149. input := &ec2.DescribeVolumeAttributeInput{
  3150. Attribute: aws.String("autoEnableIO"),
  3151. VolumeId: aws.String("vol-049df61146c4d7901"),
  3152. }
  3153. result, err := svc.DescribeVolumeAttribute(input)
  3154. if err != nil {
  3155. if aerr, ok := err.(awserr.Error); ok {
  3156. switch aerr.Code() {
  3157. default:
  3158. fmt.Println(aerr.Error())
  3159. }
  3160. } else {
  3161. // Print the error, cast err to awserr.Error to get the Code and
  3162. // Message from an error.
  3163. fmt.Println(err.Error())
  3164. }
  3165. return
  3166. }
  3167. fmt.Println(result)
  3168. }
  3169. // To describe the status of a single volume
  3170. //
  3171. // This example describes the status for the volume ``vol-1234567890abcdef0``.
  3172. func ExampleEC2_DescribeVolumeStatus_shared00() {
  3173. svc := ec2.New(session.New())
  3174. input := &ec2.DescribeVolumeStatusInput{
  3175. VolumeIds: []*string{
  3176. aws.String("vol-1234567890abcdef0"),
  3177. },
  3178. }
  3179. result, err := svc.DescribeVolumeStatus(input)
  3180. if err != nil {
  3181. if aerr, ok := err.(awserr.Error); ok {
  3182. switch aerr.Code() {
  3183. default:
  3184. fmt.Println(aerr.Error())
  3185. }
  3186. } else {
  3187. // Print the error, cast err to awserr.Error to get the Code and
  3188. // Message from an error.
  3189. fmt.Println(err.Error())
  3190. }
  3191. return
  3192. }
  3193. fmt.Println(result)
  3194. }
  3195. // To describe the status of impaired volumes
  3196. //
  3197. // This example describes the status for all volumes that are impaired. In this example
  3198. // output, there are no impaired volumes.
  3199. func ExampleEC2_DescribeVolumeStatus_shared01() {
  3200. svc := ec2.New(session.New())
  3201. input := &ec2.DescribeVolumeStatusInput{
  3202. Filters: []*ec2.Filter{
  3203. {
  3204. Name: aws.String("volume-status.status"),
  3205. Values: []*string{
  3206. aws.String("impaired"),
  3207. },
  3208. },
  3209. },
  3210. }
  3211. result, err := svc.DescribeVolumeStatus(input)
  3212. if err != nil {
  3213. if aerr, ok := err.(awserr.Error); ok {
  3214. switch aerr.Code() {
  3215. default:
  3216. fmt.Println(aerr.Error())
  3217. }
  3218. } else {
  3219. // Print the error, cast err to awserr.Error to get the Code and
  3220. // Message from an error.
  3221. fmt.Println(err.Error())
  3222. }
  3223. return
  3224. }
  3225. fmt.Println(result)
  3226. }
  3227. // To describe all volumes
  3228. //
  3229. // This example describes all of your volumes in the default region.
  3230. func ExampleEC2_DescribeVolumes_shared00() {
  3231. svc := ec2.New(session.New())
  3232. input := &ec2.DescribeVolumesInput{}
  3233. result, err := svc.DescribeVolumes(input)
  3234. if err != nil {
  3235. if aerr, ok := err.(awserr.Error); ok {
  3236. switch aerr.Code() {
  3237. default:
  3238. fmt.Println(aerr.Error())
  3239. }
  3240. } else {
  3241. // Print the error, cast err to awserr.Error to get the Code and
  3242. // Message from an error.
  3243. fmt.Println(err.Error())
  3244. }
  3245. return
  3246. }
  3247. fmt.Println(result)
  3248. }
  3249. // To describe volumes that are attached to a specific instance
  3250. //
  3251. // This example describes all volumes that are both attached to the instance with the
  3252. // ID i-1234567890abcdef0 and set to delete when the instance terminates.
  3253. func ExampleEC2_DescribeVolumes_shared01() {
  3254. svc := ec2.New(session.New())
  3255. input := &ec2.DescribeVolumesInput{
  3256. Filters: []*ec2.Filter{
  3257. {
  3258. Name: aws.String("attachment.instance-id"),
  3259. Values: []*string{
  3260. aws.String("i-1234567890abcdef0"),
  3261. },
  3262. },
  3263. {
  3264. Name: aws.String("attachment.delete-on-termination"),
  3265. Values: []*string{
  3266. aws.String("true"),
  3267. },
  3268. },
  3269. },
  3270. }
  3271. result, err := svc.DescribeVolumes(input)
  3272. if err != nil {
  3273. if aerr, ok := err.(awserr.Error); ok {
  3274. switch aerr.Code() {
  3275. default:
  3276. fmt.Println(aerr.Error())
  3277. }
  3278. } else {
  3279. // Print the error, cast err to awserr.Error to get the Code and
  3280. // Message from an error.
  3281. fmt.Println(err.Error())
  3282. }
  3283. return
  3284. }
  3285. fmt.Println(result)
  3286. }
  3287. // To describe the enableDnsSupport attribute
  3288. //
  3289. // This example describes the enableDnsSupport attribute. This attribute indicates whether
  3290. // DNS resolution is enabled for the VPC. If this attribute is true, the Amazon DNS
  3291. // server resolves DNS hostnames for your instances to their corresponding IP addresses;
  3292. // otherwise, it does not.
  3293. func ExampleEC2_DescribeVpcAttribute_shared00() {
  3294. svc := ec2.New(session.New())
  3295. input := &ec2.DescribeVpcAttributeInput{
  3296. Attribute: aws.String("enableDnsSupport"),
  3297. VpcId: aws.String("vpc-a01106c2"),
  3298. }
  3299. result, err := svc.DescribeVpcAttribute(input)
  3300. if err != nil {
  3301. if aerr, ok := err.(awserr.Error); ok {
  3302. switch aerr.Code() {
  3303. default:
  3304. fmt.Println(aerr.Error())
  3305. }
  3306. } else {
  3307. // Print the error, cast err to awserr.Error to get the Code and
  3308. // Message from an error.
  3309. fmt.Println(err.Error())
  3310. }
  3311. return
  3312. }
  3313. fmt.Println(result)
  3314. }
  3315. // To describe the enableDnsHostnames attribute
  3316. //
  3317. // This example describes the enableDnsHostnames attribute. This attribute indicates
  3318. // whether the instances launched in the VPC get DNS hostnames. If this attribute is
  3319. // true, instances in the VPC get DNS hostnames; otherwise, they do not.
  3320. func ExampleEC2_DescribeVpcAttribute_shared01() {
  3321. svc := ec2.New(session.New())
  3322. input := &ec2.DescribeVpcAttributeInput{
  3323. Attribute: aws.String("enableDnsHostnames"),
  3324. VpcId: aws.String("vpc-a01106c2"),
  3325. }
  3326. result, err := svc.DescribeVpcAttribute(input)
  3327. if err != nil {
  3328. if aerr, ok := err.(awserr.Error); ok {
  3329. switch aerr.Code() {
  3330. default:
  3331. fmt.Println(aerr.Error())
  3332. }
  3333. } else {
  3334. // Print the error, cast err to awserr.Error to get the Code and
  3335. // Message from an error.
  3336. fmt.Println(err.Error())
  3337. }
  3338. return
  3339. }
  3340. fmt.Println(result)
  3341. }
  3342. // To describe a VPC
  3343. //
  3344. // This example describes the specified VPC.
  3345. func ExampleEC2_DescribeVpcs_shared00() {
  3346. svc := ec2.New(session.New())
  3347. input := &ec2.DescribeVpcsInput{
  3348. VpcIds: []*string{
  3349. aws.String("vpc-a01106c2"),
  3350. },
  3351. }
  3352. result, err := svc.DescribeVpcs(input)
  3353. if err != nil {
  3354. if aerr, ok := err.(awserr.Error); ok {
  3355. switch aerr.Code() {
  3356. default:
  3357. fmt.Println(aerr.Error())
  3358. }
  3359. } else {
  3360. // Print the error, cast err to awserr.Error to get the Code and
  3361. // Message from an error.
  3362. fmt.Println(err.Error())
  3363. }
  3364. return
  3365. }
  3366. fmt.Println(result)
  3367. }
  3368. // To detach an Internet gateway from a VPC
  3369. //
  3370. // This example detaches the specified Internet gateway from the specified VPC.
  3371. func ExampleEC2_DetachInternetGateway_shared00() {
  3372. svc := ec2.New(session.New())
  3373. input := &ec2.DetachInternetGatewayInput{
  3374. InternetGatewayId: aws.String("igw-c0a643a9"),
  3375. VpcId: aws.String("vpc-a01106c2"),
  3376. }
  3377. result, err := svc.DetachInternetGateway(input)
  3378. if err != nil {
  3379. if aerr, ok := err.(awserr.Error); ok {
  3380. switch aerr.Code() {
  3381. default:
  3382. fmt.Println(aerr.Error())
  3383. }
  3384. } else {
  3385. // Print the error, cast err to awserr.Error to get the Code and
  3386. // Message from an error.
  3387. fmt.Println(err.Error())
  3388. }
  3389. return
  3390. }
  3391. fmt.Println(result)
  3392. }
  3393. // To detach a network interface from an instance
  3394. //
  3395. // This example detaches the specified network interface from its attached instance.
  3396. func ExampleEC2_DetachNetworkInterface_shared00() {
  3397. svc := ec2.New(session.New())
  3398. input := &ec2.DetachNetworkInterfaceInput{
  3399. AttachmentId: aws.String("eni-attach-66c4350a"),
  3400. }
  3401. result, err := svc.DetachNetworkInterface(input)
  3402. if err != nil {
  3403. if aerr, ok := err.(awserr.Error); ok {
  3404. switch aerr.Code() {
  3405. default:
  3406. fmt.Println(aerr.Error())
  3407. }
  3408. } else {
  3409. // Print the error, cast err to awserr.Error to get the Code and
  3410. // Message from an error.
  3411. fmt.Println(err.Error())
  3412. }
  3413. return
  3414. }
  3415. fmt.Println(result)
  3416. }
  3417. // To detach a volume from an instance
  3418. //
  3419. // This example detaches the volume (``vol-049df61146c4d7901``) from the instance it
  3420. // is attached to.
  3421. func ExampleEC2_DetachVolume_shared00() {
  3422. svc := ec2.New(session.New())
  3423. input := &ec2.DetachVolumeInput{
  3424. VolumeId: aws.String("vol-1234567890abcdef0"),
  3425. }
  3426. result, err := svc.DetachVolume(input)
  3427. if err != nil {
  3428. if aerr, ok := err.(awserr.Error); ok {
  3429. switch aerr.Code() {
  3430. default:
  3431. fmt.Println(aerr.Error())
  3432. }
  3433. } else {
  3434. // Print the error, cast err to awserr.Error to get the Code and
  3435. // Message from an error.
  3436. fmt.Println(err.Error())
  3437. }
  3438. return
  3439. }
  3440. fmt.Println(result)
  3441. }
  3442. // To disable route propagation
  3443. //
  3444. // This example disables the specified virtual private gateway from propagating static
  3445. // routes to the specified route table.
  3446. func ExampleEC2_DisableVgwRoutePropagation_shared00() {
  3447. svc := ec2.New(session.New())
  3448. input := &ec2.DisableVgwRoutePropagationInput{
  3449. GatewayId: aws.String("vgw-9a4cacf3"),
  3450. RouteTableId: aws.String("rtb-22574640"),
  3451. }
  3452. result, err := svc.DisableVgwRoutePropagation(input)
  3453. if err != nil {
  3454. if aerr, ok := err.(awserr.Error); ok {
  3455. switch aerr.Code() {
  3456. default:
  3457. fmt.Println(aerr.Error())
  3458. }
  3459. } else {
  3460. // Print the error, cast err to awserr.Error to get the Code and
  3461. // Message from an error.
  3462. fmt.Println(err.Error())
  3463. }
  3464. return
  3465. }
  3466. fmt.Println(result)
  3467. }
  3468. // To disassociate an Elastic IP address in EC2-VPC
  3469. //
  3470. // This example disassociates an Elastic IP address from an instance in a VPC.
  3471. func ExampleEC2_DisassociateAddress_shared00() {
  3472. svc := ec2.New(session.New())
  3473. input := &ec2.DisassociateAddressInput{
  3474. AssociationId: aws.String("eipassoc-2bebb745"),
  3475. }
  3476. result, err := svc.DisassociateAddress(input)
  3477. if err != nil {
  3478. if aerr, ok := err.(awserr.Error); ok {
  3479. switch aerr.Code() {
  3480. default:
  3481. fmt.Println(aerr.Error())
  3482. }
  3483. } else {
  3484. // Print the error, cast err to awserr.Error to get the Code and
  3485. // Message from an error.
  3486. fmt.Println(err.Error())
  3487. }
  3488. return
  3489. }
  3490. fmt.Println(result)
  3491. }
  3492. // To disassociate an Elastic IP addresses in EC2-Classic
  3493. //
  3494. // This example disassociates an Elastic IP address from an instance in EC2-Classic.
  3495. func ExampleEC2_DisassociateAddress_shared01() {
  3496. svc := ec2.New(session.New())
  3497. input := &ec2.DisassociateAddressInput{
  3498. PublicIp: aws.String("198.51.100.0"),
  3499. }
  3500. result, err := svc.DisassociateAddress(input)
  3501. if err != nil {
  3502. if aerr, ok := err.(awserr.Error); ok {
  3503. switch aerr.Code() {
  3504. default:
  3505. fmt.Println(aerr.Error())
  3506. }
  3507. } else {
  3508. // Print the error, cast err to awserr.Error to get the Code and
  3509. // Message from an error.
  3510. fmt.Println(err.Error())
  3511. }
  3512. return
  3513. }
  3514. fmt.Println(result)
  3515. }
  3516. // To disassociate an IAM instance profile
  3517. //
  3518. // This example disassociates the specified IAM instance profile from an instance.
  3519. func ExampleEC2_DisassociateIamInstanceProfile_shared00() {
  3520. svc := ec2.New(session.New())
  3521. input := &ec2.DisassociateIamInstanceProfileInput{
  3522. AssociationId: aws.String("iip-assoc-05020b59952902f5f"),
  3523. }
  3524. result, err := svc.DisassociateIamInstanceProfile(input)
  3525. if err != nil {
  3526. if aerr, ok := err.(awserr.Error); ok {
  3527. switch aerr.Code() {
  3528. default:
  3529. fmt.Println(aerr.Error())
  3530. }
  3531. } else {
  3532. // Print the error, cast err to awserr.Error to get the Code and
  3533. // Message from an error.
  3534. fmt.Println(err.Error())
  3535. }
  3536. return
  3537. }
  3538. fmt.Println(result)
  3539. }
  3540. // To disassociate a route table
  3541. //
  3542. // This example disassociates the specified route table from its associated subnet.
  3543. func ExampleEC2_DisassociateRouteTable_shared00() {
  3544. svc := ec2.New(session.New())
  3545. input := &ec2.DisassociateRouteTableInput{
  3546. AssociationId: aws.String("rtbassoc-781d0d1a"),
  3547. }
  3548. result, err := svc.DisassociateRouteTable(input)
  3549. if err != nil {
  3550. if aerr, ok := err.(awserr.Error); ok {
  3551. switch aerr.Code() {
  3552. default:
  3553. fmt.Println(aerr.Error())
  3554. }
  3555. } else {
  3556. // Print the error, cast err to awserr.Error to get the Code and
  3557. // Message from an error.
  3558. fmt.Println(err.Error())
  3559. }
  3560. return
  3561. }
  3562. fmt.Println(result)
  3563. }
  3564. // To enable route propagation
  3565. //
  3566. // This example enables the specified virtual private gateway to propagate static routes
  3567. // to the specified route table.
  3568. func ExampleEC2_EnableVgwRoutePropagation_shared00() {
  3569. svc := ec2.New(session.New())
  3570. input := &ec2.EnableVgwRoutePropagationInput{
  3571. GatewayId: aws.String("vgw-9a4cacf3"),
  3572. RouteTableId: aws.String("rtb-22574640"),
  3573. }
  3574. result, err := svc.EnableVgwRoutePropagation(input)
  3575. if err != nil {
  3576. if aerr, ok := err.(awserr.Error); ok {
  3577. switch aerr.Code() {
  3578. default:
  3579. fmt.Println(aerr.Error())
  3580. }
  3581. } else {
  3582. // Print the error, cast err to awserr.Error to get the Code and
  3583. // Message from an error.
  3584. fmt.Println(err.Error())
  3585. }
  3586. return
  3587. }
  3588. fmt.Println(result)
  3589. }
  3590. // To enable I/O for a volume
  3591. //
  3592. // This example enables I/O on volume ``vol-1234567890abcdef0``.
  3593. func ExampleEC2_EnableVolumeIO_shared00() {
  3594. svc := ec2.New(session.New())
  3595. input := &ec2.EnableVolumeIOInput{
  3596. VolumeId: aws.String("vol-1234567890abcdef0"),
  3597. }
  3598. result, err := svc.EnableVolumeIO(input)
  3599. if err != nil {
  3600. if aerr, ok := err.(awserr.Error); ok {
  3601. switch aerr.Code() {
  3602. default:
  3603. fmt.Println(aerr.Error())
  3604. }
  3605. } else {
  3606. // Print the error, cast err to awserr.Error to get the Code and
  3607. // Message from an error.
  3608. fmt.Println(err.Error())
  3609. }
  3610. return
  3611. }
  3612. fmt.Println(result)
  3613. }
  3614. // To get the console output
  3615. //
  3616. // This example gets the console output for the specified instance.
  3617. func ExampleEC2_GetConsoleOutput_shared00() {
  3618. svc := ec2.New(session.New())
  3619. input := &ec2.GetConsoleOutputInput{
  3620. InstanceId: aws.String("i-1234567890abcdef0"),
  3621. }
  3622. result, err := svc.GetConsoleOutput(input)
  3623. if err != nil {
  3624. if aerr, ok := err.(awserr.Error); ok {
  3625. switch aerr.Code() {
  3626. default:
  3627. fmt.Println(aerr.Error())
  3628. }
  3629. } else {
  3630. // Print the error, cast err to awserr.Error to get the Code and
  3631. // Message from an error.
  3632. fmt.Println(err.Error())
  3633. }
  3634. return
  3635. }
  3636. fmt.Println(result)
  3637. }
  3638. // To get the launch template data for an instance
  3639. //
  3640. // This example gets the launch template data for the specified instance.
  3641. func ExampleEC2_GetLaunchTemplateData_shared00() {
  3642. svc := ec2.New(session.New())
  3643. input := &ec2.GetLaunchTemplateDataInput{
  3644. InstanceId: aws.String("0123d646e8048babc"),
  3645. }
  3646. result, err := svc.GetLaunchTemplateData(input)
  3647. if err != nil {
  3648. if aerr, ok := err.(awserr.Error); ok {
  3649. switch aerr.Code() {
  3650. default:
  3651. fmt.Println(aerr.Error())
  3652. }
  3653. } else {
  3654. // Print the error, cast err to awserr.Error to get the Code and
  3655. // Message from an error.
  3656. fmt.Println(err.Error())
  3657. }
  3658. return
  3659. }
  3660. fmt.Println(result)
  3661. }
  3662. // To make an AMI public
  3663. //
  3664. // This example makes the specified AMI public.
  3665. func ExampleEC2_ModifyImageAttribute_shared00() {
  3666. svc := ec2.New(session.New())
  3667. input := &ec2.ModifyImageAttributeInput{
  3668. ImageId: aws.String("ami-5731123e"),
  3669. LaunchPermission: &ec2.LaunchPermissionModifications{
  3670. Add: []*ec2.LaunchPermission{
  3671. {
  3672. Group: aws.String("all"),
  3673. },
  3674. },
  3675. },
  3676. }
  3677. result, err := svc.ModifyImageAttribute(input)
  3678. if err != nil {
  3679. if aerr, ok := err.(awserr.Error); ok {
  3680. switch aerr.Code() {
  3681. default:
  3682. fmt.Println(aerr.Error())
  3683. }
  3684. } else {
  3685. // Print the error, cast err to awserr.Error to get the Code and
  3686. // Message from an error.
  3687. fmt.Println(err.Error())
  3688. }
  3689. return
  3690. }
  3691. fmt.Println(result)
  3692. }
  3693. // To grant launch permissions
  3694. //
  3695. // This example grants launch permissions for the specified AMI to the specified AWS
  3696. // account.
  3697. func ExampleEC2_ModifyImageAttribute_shared01() {
  3698. svc := ec2.New(session.New())
  3699. input := &ec2.ModifyImageAttributeInput{
  3700. ImageId: aws.String("ami-5731123e"),
  3701. LaunchPermission: &ec2.LaunchPermissionModifications{
  3702. Add: []*ec2.LaunchPermission{
  3703. {
  3704. UserId: aws.String("123456789012"),
  3705. },
  3706. },
  3707. },
  3708. }
  3709. result, err := svc.ModifyImageAttribute(input)
  3710. if err != nil {
  3711. if aerr, ok := err.(awserr.Error); ok {
  3712. switch aerr.Code() {
  3713. default:
  3714. fmt.Println(aerr.Error())
  3715. }
  3716. } else {
  3717. // Print the error, cast err to awserr.Error to get the Code and
  3718. // Message from an error.
  3719. fmt.Println(err.Error())
  3720. }
  3721. return
  3722. }
  3723. fmt.Println(result)
  3724. }
  3725. // To modify the instance type
  3726. //
  3727. // This example modifies the instance type of the specified stopped instance.
  3728. func ExampleEC2_ModifyInstanceAttribute_shared00() {
  3729. svc := ec2.New(session.New())
  3730. input := &ec2.ModifyInstanceAttributeInput{
  3731. InstanceId: aws.String("i-1234567890abcdef0"),
  3732. InstanceType: &ec2.AttributeValue{
  3733. Value: aws.String("m5.large"),
  3734. },
  3735. }
  3736. result, err := svc.ModifyInstanceAttribute(input)
  3737. if err != nil {
  3738. if aerr, ok := err.(awserr.Error); ok {
  3739. switch aerr.Code() {
  3740. default:
  3741. fmt.Println(aerr.Error())
  3742. }
  3743. } else {
  3744. // Print the error, cast err to awserr.Error to get the Code and
  3745. // Message from an error.
  3746. fmt.Println(err.Error())
  3747. }
  3748. return
  3749. }
  3750. fmt.Println(result)
  3751. }
  3752. // To enable enhanced networking
  3753. //
  3754. // This example enables enhanced networking for the specified stopped instance.
  3755. func ExampleEC2_ModifyInstanceAttribute_shared01() {
  3756. svc := ec2.New(session.New())
  3757. input := &ec2.ModifyInstanceAttributeInput{
  3758. EnaSupport: &ec2.AttributeBooleanValue{
  3759. Value: aws.Bool(true),
  3760. },
  3761. InstanceId: aws.String("i-1234567890abcdef0"),
  3762. }
  3763. result, err := svc.ModifyInstanceAttribute(input)
  3764. if err != nil {
  3765. if aerr, ok := err.(awserr.Error); ok {
  3766. switch aerr.Code() {
  3767. default:
  3768. fmt.Println(aerr.Error())
  3769. }
  3770. } else {
  3771. // Print the error, cast err to awserr.Error to get the Code and
  3772. // Message from an error.
  3773. fmt.Println(err.Error())
  3774. }
  3775. return
  3776. }
  3777. fmt.Println(result)
  3778. }
  3779. // To change the default version of a launch template
  3780. //
  3781. // This example specifies version 2 as the default version of the specified launch template.
  3782. func ExampleEC2_ModifyLaunchTemplate_shared00() {
  3783. svc := ec2.New(session.New())
  3784. input := &ec2.ModifyLaunchTemplateInput{
  3785. DefaultVersion: aws.String("2"),
  3786. LaunchTemplateId: aws.String("lt-0abcd290751193123"),
  3787. }
  3788. result, err := svc.ModifyLaunchTemplate(input)
  3789. if err != nil {
  3790. if aerr, ok := err.(awserr.Error); ok {
  3791. switch aerr.Code() {
  3792. default:
  3793. fmt.Println(aerr.Error())
  3794. }
  3795. } else {
  3796. // Print the error, cast err to awserr.Error to get the Code and
  3797. // Message from an error.
  3798. fmt.Println(err.Error())
  3799. }
  3800. return
  3801. }
  3802. fmt.Println(result)
  3803. }
  3804. // To modify the attachment attribute of a network interface
  3805. //
  3806. // This example modifies the attachment attribute of the specified network interface.
  3807. func ExampleEC2_ModifyNetworkInterfaceAttribute_shared00() {
  3808. svc := ec2.New(session.New())
  3809. input := &ec2.ModifyNetworkInterfaceAttributeInput{
  3810. Attachment: &ec2.NetworkInterfaceAttachmentChanges{
  3811. AttachmentId: aws.String("eni-attach-43348162"),
  3812. DeleteOnTermination: aws.Bool(false),
  3813. },
  3814. NetworkInterfaceId: aws.String("eni-686ea200"),
  3815. }
  3816. result, err := svc.ModifyNetworkInterfaceAttribute(input)
  3817. if err != nil {
  3818. if aerr, ok := err.(awserr.Error); ok {
  3819. switch aerr.Code() {
  3820. default:
  3821. fmt.Println(aerr.Error())
  3822. }
  3823. } else {
  3824. // Print the error, cast err to awserr.Error to get the Code and
  3825. // Message from an error.
  3826. fmt.Println(err.Error())
  3827. }
  3828. return
  3829. }
  3830. fmt.Println(result)
  3831. }
  3832. // To modify the description attribute of a network interface
  3833. //
  3834. // This example modifies the description attribute of the specified network interface.
  3835. func ExampleEC2_ModifyNetworkInterfaceAttribute_shared01() {
  3836. svc := ec2.New(session.New())
  3837. input := &ec2.ModifyNetworkInterfaceAttributeInput{
  3838. Description: &ec2.AttributeValue{
  3839. Value: aws.String("My description"),
  3840. },
  3841. NetworkInterfaceId: aws.String("eni-686ea200"),
  3842. }
  3843. result, err := svc.ModifyNetworkInterfaceAttribute(input)
  3844. if err != nil {
  3845. if aerr, ok := err.(awserr.Error); ok {
  3846. switch aerr.Code() {
  3847. default:
  3848. fmt.Println(aerr.Error())
  3849. }
  3850. } else {
  3851. // Print the error, cast err to awserr.Error to get the Code and
  3852. // Message from an error.
  3853. fmt.Println(err.Error())
  3854. }
  3855. return
  3856. }
  3857. fmt.Println(result)
  3858. }
  3859. // To modify the groupSet attribute of a network interface
  3860. //
  3861. // This example command modifies the groupSet attribute of the specified network interface.
  3862. func ExampleEC2_ModifyNetworkInterfaceAttribute_shared02() {
  3863. svc := ec2.New(session.New())
  3864. input := &ec2.ModifyNetworkInterfaceAttributeInput{
  3865. Groups: []*string{
  3866. aws.String("sg-903004f8"),
  3867. aws.String("sg-1a2b3c4d"),
  3868. },
  3869. NetworkInterfaceId: aws.String("eni-686ea200"),
  3870. }
  3871. result, err := svc.ModifyNetworkInterfaceAttribute(input)
  3872. if err != nil {
  3873. if aerr, ok := err.(awserr.Error); ok {
  3874. switch aerr.Code() {
  3875. default:
  3876. fmt.Println(aerr.Error())
  3877. }
  3878. } else {
  3879. // Print the error, cast err to awserr.Error to get the Code and
  3880. // Message from an error.
  3881. fmt.Println(err.Error())
  3882. }
  3883. return
  3884. }
  3885. fmt.Println(result)
  3886. }
  3887. // To modify the sourceDestCheck attribute of a network interface
  3888. //
  3889. // This example command modifies the sourceDestCheck attribute of the specified network
  3890. // interface.
  3891. func ExampleEC2_ModifyNetworkInterfaceAttribute_shared03() {
  3892. svc := ec2.New(session.New())
  3893. input := &ec2.ModifyNetworkInterfaceAttributeInput{
  3894. NetworkInterfaceId: aws.String("eni-686ea200"),
  3895. SourceDestCheck: &ec2.AttributeBooleanValue{
  3896. Value: aws.Bool(false),
  3897. },
  3898. }
  3899. result, err := svc.ModifyNetworkInterfaceAttribute(input)
  3900. if err != nil {
  3901. if aerr, ok := err.(awserr.Error); ok {
  3902. switch aerr.Code() {
  3903. default:
  3904. fmt.Println(aerr.Error())
  3905. }
  3906. } else {
  3907. // Print the error, cast err to awserr.Error to get the Code and
  3908. // Message from an error.
  3909. fmt.Println(err.Error())
  3910. }
  3911. return
  3912. }
  3913. fmt.Println(result)
  3914. }
  3915. // To modify a snapshot attribute
  3916. //
  3917. // This example modifies snapshot ``snap-1234567890abcdef0`` to remove the create volume
  3918. // permission for a user with the account ID ``123456789012``. If the command succeeds,
  3919. // no output is returned.
  3920. func ExampleEC2_ModifySnapshotAttribute_shared00() {
  3921. svc := ec2.New(session.New())
  3922. input := &ec2.ModifySnapshotAttributeInput{
  3923. Attribute: aws.String("createVolumePermission"),
  3924. OperationType: aws.String("remove"),
  3925. SnapshotId: aws.String("snap-1234567890abcdef0"),
  3926. UserIds: []*string{
  3927. aws.String("123456789012"),
  3928. },
  3929. }
  3930. result, err := svc.ModifySnapshotAttribute(input)
  3931. if err != nil {
  3932. if aerr, ok := err.(awserr.Error); ok {
  3933. switch aerr.Code() {
  3934. default:
  3935. fmt.Println(aerr.Error())
  3936. }
  3937. } else {
  3938. // Print the error, cast err to awserr.Error to get the Code and
  3939. // Message from an error.
  3940. fmt.Println(err.Error())
  3941. }
  3942. return
  3943. }
  3944. fmt.Println(result)
  3945. }
  3946. // To make a snapshot public
  3947. //
  3948. // This example makes the snapshot ``snap-1234567890abcdef0`` public.
  3949. func ExampleEC2_ModifySnapshotAttribute_shared01() {
  3950. svc := ec2.New(session.New())
  3951. input := &ec2.ModifySnapshotAttributeInput{
  3952. Attribute: aws.String("createVolumePermission"),
  3953. GroupNames: []*string{
  3954. aws.String("all"),
  3955. },
  3956. OperationType: aws.String("add"),
  3957. SnapshotId: aws.String("snap-1234567890abcdef0"),
  3958. }
  3959. result, err := svc.ModifySnapshotAttribute(input)
  3960. if err != nil {
  3961. if aerr, ok := err.(awserr.Error); ok {
  3962. switch aerr.Code() {
  3963. default:
  3964. fmt.Println(aerr.Error())
  3965. }
  3966. } else {
  3967. // Print the error, cast err to awserr.Error to get the Code and
  3968. // Message from an error.
  3969. fmt.Println(err.Error())
  3970. }
  3971. return
  3972. }
  3973. fmt.Println(result)
  3974. }
  3975. // To increase the target capacity of a Spot fleet request
  3976. //
  3977. // This example increases the target capacity of the specified Spot fleet request.
  3978. func ExampleEC2_ModifySpotFleetRequest_shared00() {
  3979. svc := ec2.New(session.New())
  3980. input := &ec2.ModifySpotFleetRequestInput{
  3981. SpotFleetRequestId: aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  3982. TargetCapacity: aws.Int64(20),
  3983. }
  3984. result, err := svc.ModifySpotFleetRequest(input)
  3985. if err != nil {
  3986. if aerr, ok := err.(awserr.Error); ok {
  3987. switch aerr.Code() {
  3988. default:
  3989. fmt.Println(aerr.Error())
  3990. }
  3991. } else {
  3992. // Print the error, cast err to awserr.Error to get the Code and
  3993. // Message from an error.
  3994. fmt.Println(err.Error())
  3995. }
  3996. return
  3997. }
  3998. fmt.Println(result)
  3999. }
  4000. // To decrease the target capacity of a Spot fleet request
  4001. //
  4002. // This example decreases the target capacity of the specified Spot fleet request without
  4003. // terminating any Spot Instances as a result.
  4004. func ExampleEC2_ModifySpotFleetRequest_shared01() {
  4005. svc := ec2.New(session.New())
  4006. input := &ec2.ModifySpotFleetRequestInput{
  4007. ExcessCapacityTerminationPolicy: aws.String("NoTermination "),
  4008. SpotFleetRequestId: aws.String("sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE"),
  4009. TargetCapacity: aws.Int64(10),
  4010. }
  4011. result, err := svc.ModifySpotFleetRequest(input)
  4012. if err != nil {
  4013. if aerr, ok := err.(awserr.Error); ok {
  4014. switch aerr.Code() {
  4015. default:
  4016. fmt.Println(aerr.Error())
  4017. }
  4018. } else {
  4019. // Print the error, cast err to awserr.Error to get the Code and
  4020. // Message from an error.
  4021. fmt.Println(err.Error())
  4022. }
  4023. return
  4024. }
  4025. fmt.Println(result)
  4026. }
  4027. // To change a subnet's public IP addressing behavior
  4028. //
  4029. // This example modifies the specified subnet so that all instances launched into this
  4030. // subnet are assigned a public IP address.
  4031. func ExampleEC2_ModifySubnetAttribute_shared00() {
  4032. svc := ec2.New(session.New())
  4033. input := &ec2.ModifySubnetAttributeInput{
  4034. MapPublicIpOnLaunch: &ec2.AttributeBooleanValue{
  4035. Value: aws.Bool(true),
  4036. },
  4037. SubnetId: aws.String("subnet-1a2b3c4d"),
  4038. }
  4039. result, err := svc.ModifySubnetAttribute(input)
  4040. if err != nil {
  4041. if aerr, ok := err.(awserr.Error); ok {
  4042. switch aerr.Code() {
  4043. default:
  4044. fmt.Println(aerr.Error())
  4045. }
  4046. } else {
  4047. // Print the error, cast err to awserr.Error to get the Code and
  4048. // Message from an error.
  4049. fmt.Println(err.Error())
  4050. }
  4051. return
  4052. }
  4053. fmt.Println(result)
  4054. }
  4055. // To modify a volume attribute
  4056. //
  4057. // This example sets the ``autoEnableIo`` attribute of the volume with the ID ``vol-1234567890abcdef0``
  4058. // to ``true``. If the command succeeds, no output is returned.
  4059. func ExampleEC2_ModifyVolumeAttribute_shared00() {
  4060. svc := ec2.New(session.New())
  4061. input := &ec2.ModifyVolumeAttributeInput{
  4062. AutoEnableIO: &ec2.AttributeBooleanValue{
  4063. Value: aws.Bool(true),
  4064. },
  4065. DryRun: aws.Bool(true),
  4066. VolumeId: aws.String("vol-1234567890abcdef0"),
  4067. }
  4068. result, err := svc.ModifyVolumeAttribute(input)
  4069. if err != nil {
  4070. if aerr, ok := err.(awserr.Error); ok {
  4071. switch aerr.Code() {
  4072. default:
  4073. fmt.Println(aerr.Error())
  4074. }
  4075. } else {
  4076. // Print the error, cast err to awserr.Error to get the Code and
  4077. // Message from an error.
  4078. fmt.Println(err.Error())
  4079. }
  4080. return
  4081. }
  4082. fmt.Println(result)
  4083. }
  4084. // To modify the enableDnsSupport attribute
  4085. //
  4086. // This example modifies the enableDnsSupport attribute. This attribute indicates whether
  4087. // DNS resolution is enabled for the VPC. If this attribute is true, the Amazon DNS
  4088. // server resolves DNS hostnames for instances in the VPC to their corresponding IP
  4089. // addresses; otherwise, it does not.
  4090. func ExampleEC2_ModifyVpcAttribute_shared00() {
  4091. svc := ec2.New(session.New())
  4092. input := &ec2.ModifyVpcAttributeInput{
  4093. EnableDnsSupport: &ec2.AttributeBooleanValue{
  4094. Value: aws.Bool(false),
  4095. },
  4096. VpcId: aws.String("vpc-a01106c2"),
  4097. }
  4098. result, err := svc.ModifyVpcAttribute(input)
  4099. if err != nil {
  4100. if aerr, ok := err.(awserr.Error); ok {
  4101. switch aerr.Code() {
  4102. default:
  4103. fmt.Println(aerr.Error())
  4104. }
  4105. } else {
  4106. // Print the error, cast err to awserr.Error to get the Code and
  4107. // Message from an error.
  4108. fmt.Println(err.Error())
  4109. }
  4110. return
  4111. }
  4112. fmt.Println(result)
  4113. }
  4114. // To modify the enableDnsHostnames attribute
  4115. //
  4116. // This example modifies the enableDnsHostnames attribute. This attribute indicates
  4117. // whether instances launched in the VPC get DNS hostnames. If this attribute is true,
  4118. // instances in the VPC get DNS hostnames; otherwise, they do not.
  4119. func ExampleEC2_ModifyVpcAttribute_shared01() {
  4120. svc := ec2.New(session.New())
  4121. input := &ec2.ModifyVpcAttributeInput{
  4122. EnableDnsHostnames: &ec2.AttributeBooleanValue{
  4123. Value: aws.Bool(false),
  4124. },
  4125. VpcId: aws.String("vpc-a01106c2"),
  4126. }
  4127. result, err := svc.ModifyVpcAttribute(input)
  4128. if err != nil {
  4129. if aerr, ok := err.(awserr.Error); ok {
  4130. switch aerr.Code() {
  4131. default:
  4132. fmt.Println(aerr.Error())
  4133. }
  4134. } else {
  4135. // Print the error, cast err to awserr.Error to get the Code and
  4136. // Message from an error.
  4137. fmt.Println(err.Error())
  4138. }
  4139. return
  4140. }
  4141. fmt.Println(result)
  4142. }
  4143. // To move an address to EC2-VPC
  4144. //
  4145. // This example moves the specified Elastic IP address to the EC2-VPC platform.
  4146. func ExampleEC2_MoveAddressToVpc_shared00() {
  4147. svc := ec2.New(session.New())
  4148. input := &ec2.MoveAddressToVpcInput{
  4149. PublicIp: aws.String("54.123.4.56"),
  4150. }
  4151. result, err := svc.MoveAddressToVpc(input)
  4152. if err != nil {
  4153. if aerr, ok := err.(awserr.Error); ok {
  4154. switch aerr.Code() {
  4155. default:
  4156. fmt.Println(aerr.Error())
  4157. }
  4158. } else {
  4159. // Print the error, cast err to awserr.Error to get the Code and
  4160. // Message from an error.
  4161. fmt.Println(err.Error())
  4162. }
  4163. return
  4164. }
  4165. fmt.Println(result)
  4166. }
  4167. // To purchase a Scheduled Instance
  4168. //
  4169. // This example purchases a Scheduled Instance.
  4170. func ExampleEC2_PurchaseScheduledInstances_shared00() {
  4171. svc := ec2.New(session.New())
  4172. input := &ec2.PurchaseScheduledInstancesInput{
  4173. PurchaseRequests: []*ec2.PurchaseRequest{
  4174. {
  4175. InstanceCount: aws.Int64(1),
  4176. PurchaseToken: aws.String("eyJ2IjoiMSIsInMiOjEsImMiOi..."),
  4177. },
  4178. },
  4179. }
  4180. result, err := svc.PurchaseScheduledInstances(input)
  4181. if err != nil {
  4182. if aerr, ok := err.(awserr.Error); ok {
  4183. switch aerr.Code() {
  4184. default:
  4185. fmt.Println(aerr.Error())
  4186. }
  4187. } else {
  4188. // Print the error, cast err to awserr.Error to get the Code and
  4189. // Message from an error.
  4190. fmt.Println(err.Error())
  4191. }
  4192. return
  4193. }
  4194. fmt.Println(result)
  4195. }
  4196. // To reboot an EC2 instance
  4197. //
  4198. // This example reboots the specified EC2 instance.
  4199. func ExampleEC2_RebootInstances_shared00() {
  4200. svc := ec2.New(session.New())
  4201. input := &ec2.RebootInstancesInput{
  4202. InstanceIds: []*string{
  4203. aws.String("i-1234567890abcdef5"),
  4204. },
  4205. }
  4206. result, err := svc.RebootInstances(input)
  4207. if err != nil {
  4208. if aerr, ok := err.(awserr.Error); ok {
  4209. switch aerr.Code() {
  4210. default:
  4211. fmt.Println(aerr.Error())
  4212. }
  4213. } else {
  4214. // Print the error, cast err to awserr.Error to get the Code and
  4215. // Message from an error.
  4216. fmt.Println(err.Error())
  4217. }
  4218. return
  4219. }
  4220. fmt.Println(result)
  4221. }
  4222. // To release an Elastic IP address for EC2-VPC
  4223. //
  4224. // This example releases an Elastic IP address for use with instances in a VPC.
  4225. func ExampleEC2_ReleaseAddress_shared00() {
  4226. svc := ec2.New(session.New())
  4227. input := &ec2.ReleaseAddressInput{
  4228. AllocationId: aws.String("eipalloc-64d5890a"),
  4229. }
  4230. result, err := svc.ReleaseAddress(input)
  4231. if err != nil {
  4232. if aerr, ok := err.(awserr.Error); ok {
  4233. switch aerr.Code() {
  4234. default:
  4235. fmt.Println(aerr.Error())
  4236. }
  4237. } else {
  4238. // Print the error, cast err to awserr.Error to get the Code and
  4239. // Message from an error.
  4240. fmt.Println(err.Error())
  4241. }
  4242. return
  4243. }
  4244. fmt.Println(result)
  4245. }
  4246. // To release an Elastic IP addresses for EC2-Classic
  4247. //
  4248. // This example releases an Elastic IP address for use with instances in EC2-Classic.
  4249. func ExampleEC2_ReleaseAddress_shared01() {
  4250. svc := ec2.New(session.New())
  4251. input := &ec2.ReleaseAddressInput{
  4252. PublicIp: aws.String("198.51.100.0"),
  4253. }
  4254. result, err := svc.ReleaseAddress(input)
  4255. if err != nil {
  4256. if aerr, ok := err.(awserr.Error); ok {
  4257. switch aerr.Code() {
  4258. default:
  4259. fmt.Println(aerr.Error())
  4260. }
  4261. } else {
  4262. // Print the error, cast err to awserr.Error to get the Code and
  4263. // Message from an error.
  4264. fmt.Println(err.Error())
  4265. }
  4266. return
  4267. }
  4268. fmt.Println(result)
  4269. }
  4270. // To replace the network ACL associated with a subnet
  4271. //
  4272. // This example associates the specified network ACL with the subnet for the specified
  4273. // network ACL association.
  4274. func ExampleEC2_ReplaceNetworkAclAssociation_shared00() {
  4275. svc := ec2.New(session.New())
  4276. input := &ec2.ReplaceNetworkAclAssociationInput{
  4277. AssociationId: aws.String("aclassoc-e5b95c8c"),
  4278. NetworkAclId: aws.String("acl-5fb85d36"),
  4279. }
  4280. result, err := svc.ReplaceNetworkAclAssociation(input)
  4281. if err != nil {
  4282. if aerr, ok := err.(awserr.Error); ok {
  4283. switch aerr.Code() {
  4284. default:
  4285. fmt.Println(aerr.Error())
  4286. }
  4287. } else {
  4288. // Print the error, cast err to awserr.Error to get the Code and
  4289. // Message from an error.
  4290. fmt.Println(err.Error())
  4291. }
  4292. return
  4293. }
  4294. fmt.Println(result)
  4295. }
  4296. // To replace a network ACL entry
  4297. //
  4298. // This example replaces an entry for the specified network ACL. The new rule 100 allows
  4299. // ingress traffic from 203.0.113.12/24 on UDP port 53 (DNS) into any associated subnet.
  4300. func ExampleEC2_ReplaceNetworkAclEntry_shared00() {
  4301. svc := ec2.New(session.New())
  4302. input := &ec2.ReplaceNetworkAclEntryInput{
  4303. CidrBlock: aws.String("203.0.113.12/24"),
  4304. Egress: aws.Bool(false),
  4305. NetworkAclId: aws.String("acl-5fb85d36"),
  4306. PortRange: &ec2.PortRange{
  4307. From: aws.Int64(53),
  4308. To: aws.Int64(53),
  4309. },
  4310. Protocol: aws.String("17"),
  4311. RuleAction: aws.String("allow"),
  4312. RuleNumber: aws.Int64(100),
  4313. }
  4314. result, err := svc.ReplaceNetworkAclEntry(input)
  4315. if err != nil {
  4316. if aerr, ok := err.(awserr.Error); ok {
  4317. switch aerr.Code() {
  4318. default:
  4319. fmt.Println(aerr.Error())
  4320. }
  4321. } else {
  4322. // Print the error, cast err to awserr.Error to get the Code and
  4323. // Message from an error.
  4324. fmt.Println(err.Error())
  4325. }
  4326. return
  4327. }
  4328. fmt.Println(result)
  4329. }
  4330. // To replace a route
  4331. //
  4332. // This example replaces the specified route in the specified table table. The new route
  4333. // matches the specified CIDR and sends the traffic to the specified virtual private
  4334. // gateway.
  4335. func ExampleEC2_ReplaceRoute_shared00() {
  4336. svc := ec2.New(session.New())
  4337. input := &ec2.ReplaceRouteInput{
  4338. DestinationCidrBlock: aws.String("10.0.0.0/16"),
  4339. GatewayId: aws.String("vgw-9a4cacf3"),
  4340. RouteTableId: aws.String("rtb-22574640"),
  4341. }
  4342. result, err := svc.ReplaceRoute(input)
  4343. if err != nil {
  4344. if aerr, ok := err.(awserr.Error); ok {
  4345. switch aerr.Code() {
  4346. default:
  4347. fmt.Println(aerr.Error())
  4348. }
  4349. } else {
  4350. // Print the error, cast err to awserr.Error to get the Code and
  4351. // Message from an error.
  4352. fmt.Println(err.Error())
  4353. }
  4354. return
  4355. }
  4356. fmt.Println(result)
  4357. }
  4358. // To replace the route table associated with a subnet
  4359. //
  4360. // This example associates the specified route table with the subnet for the specified
  4361. // route table association.
  4362. func ExampleEC2_ReplaceRouteTableAssociation_shared00() {
  4363. svc := ec2.New(session.New())
  4364. input := &ec2.ReplaceRouteTableAssociationInput{
  4365. AssociationId: aws.String("rtbassoc-781d0d1a"),
  4366. RouteTableId: aws.String("rtb-22574640"),
  4367. }
  4368. result, err := svc.ReplaceRouteTableAssociation(input)
  4369. if err != nil {
  4370. if aerr, ok := err.(awserr.Error); ok {
  4371. switch aerr.Code() {
  4372. default:
  4373. fmt.Println(aerr.Error())
  4374. }
  4375. } else {
  4376. // Print the error, cast err to awserr.Error to get the Code and
  4377. // Message from an error.
  4378. fmt.Println(err.Error())
  4379. }
  4380. return
  4381. }
  4382. fmt.Println(result)
  4383. }
  4384. // To request a Spot fleet in the subnet with the lowest price
  4385. //
  4386. // This example creates a Spot fleet request with two launch specifications that differ
  4387. // only by subnet. The Spot fleet launches the instances in the specified subnet with
  4388. // the lowest price. If the instances are launched in a default VPC, they receive a
  4389. // public IP address by default. If the instances are launched in a nondefault VPC,
  4390. // they do not receive a public IP address by default. Note that you can't specify different
  4391. // subnets from the same Availability Zone in a Spot fleet request.
  4392. func ExampleEC2_RequestSpotFleet_shared00() {
  4393. svc := ec2.New(session.New())
  4394. input := &ec2.RequestSpotFleetInput{
  4395. SpotFleetRequestConfig: &ec2.SpotFleetRequestConfigData{
  4396. IamFleetRole: aws.String("arn:aws:iam::123456789012:role/my-spot-fleet-role"),
  4397. LaunchSpecifications: []*ec2.SpotFleetLaunchSpecification{
  4398. {
  4399. IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
  4400. Arn: aws.String("arn:aws:iam::123456789012:instance-profile/my-iam-role"),
  4401. },
  4402. ImageId: aws.String("ami-1a2b3c4d"),
  4403. InstanceType: aws.String("m3.medium"),
  4404. KeyName: aws.String("my-key-pair"),
  4405. SecurityGroups: []*ec2.GroupIdentifier{
  4406. {
  4407. GroupId: aws.String("sg-1a2b3c4d"),
  4408. },
  4409. },
  4410. SubnetId: aws.String("subnet-1a2b3c4d, subnet-3c4d5e6f"),
  4411. },
  4412. },
  4413. SpotPrice: aws.String("0.04"),
  4414. TargetCapacity: aws.Int64(2),
  4415. },
  4416. }
  4417. result, err := svc.RequestSpotFleet(input)
  4418. if err != nil {
  4419. if aerr, ok := err.(awserr.Error); ok {
  4420. switch aerr.Code() {
  4421. default:
  4422. fmt.Println(aerr.Error())
  4423. }
  4424. } else {
  4425. // Print the error, cast err to awserr.Error to get the Code and
  4426. // Message from an error.
  4427. fmt.Println(err.Error())
  4428. }
  4429. return
  4430. }
  4431. fmt.Println(result)
  4432. }
  4433. // To request a Spot fleet in the Availability Zone with the lowest price
  4434. //
  4435. // This example creates a Spot fleet request with two launch specifications that differ
  4436. // only by Availability Zone. The Spot fleet launches the instances in the specified
  4437. // Availability Zone with the lowest price. If your account supports EC2-VPC only, Amazon
  4438. // EC2 launches the Spot instances in the default subnet of the Availability Zone. If
  4439. // your account supports EC2-Classic, Amazon EC2 launches the instances in EC2-Classic
  4440. // in the Availability Zone.
  4441. func ExampleEC2_RequestSpotFleet_shared01() {
  4442. svc := ec2.New(session.New())
  4443. input := &ec2.RequestSpotFleetInput{
  4444. SpotFleetRequestConfig: &ec2.SpotFleetRequestConfigData{
  4445. IamFleetRole: aws.String("arn:aws:iam::123456789012:role/my-spot-fleet-role"),
  4446. LaunchSpecifications: []*ec2.SpotFleetLaunchSpecification{
  4447. {
  4448. IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
  4449. Arn: aws.String("arn:aws:iam::123456789012:instance-profile/my-iam-role"),
  4450. },
  4451. ImageId: aws.String("ami-1a2b3c4d"),
  4452. InstanceType: aws.String("m3.medium"),
  4453. KeyName: aws.String("my-key-pair"),
  4454. Placement: &ec2.SpotPlacement{
  4455. AvailabilityZone: aws.String("us-west-2a, us-west-2b"),
  4456. },
  4457. SecurityGroups: []*ec2.GroupIdentifier{
  4458. {
  4459. GroupId: aws.String("sg-1a2b3c4d"),
  4460. },
  4461. },
  4462. },
  4463. },
  4464. SpotPrice: aws.String("0.04"),
  4465. TargetCapacity: aws.Int64(2),
  4466. },
  4467. }
  4468. result, err := svc.RequestSpotFleet(input)
  4469. if err != nil {
  4470. if aerr, ok := err.(awserr.Error); ok {
  4471. switch aerr.Code() {
  4472. default:
  4473. fmt.Println(aerr.Error())
  4474. }
  4475. } else {
  4476. // Print the error, cast err to awserr.Error to get the Code and
  4477. // Message from an error.
  4478. fmt.Println(err.Error())
  4479. }
  4480. return
  4481. }
  4482. fmt.Println(result)
  4483. }
  4484. // To launch Spot instances in a subnet and assign them public IP addresses
  4485. //
  4486. // This example assigns public addresses to instances launched in a nondefault VPC.
  4487. // Note that when you specify a network interface, you must include the subnet ID and
  4488. // security group ID using the network interface.
  4489. func ExampleEC2_RequestSpotFleet_shared02() {
  4490. svc := ec2.New(session.New())
  4491. input := &ec2.RequestSpotFleetInput{
  4492. SpotFleetRequestConfig: &ec2.SpotFleetRequestConfigData{
  4493. IamFleetRole: aws.String("arn:aws:iam::123456789012:role/my-spot-fleet-role"),
  4494. LaunchSpecifications: []*ec2.SpotFleetLaunchSpecification{
  4495. {
  4496. IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
  4497. Arn: aws.String("arn:aws:iam::880185128111:instance-profile/my-iam-role"),
  4498. },
  4499. ImageId: aws.String("ami-1a2b3c4d"),
  4500. InstanceType: aws.String("m3.medium"),
  4501. KeyName: aws.String("my-key-pair"),
  4502. NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
  4503. {
  4504. AssociatePublicIpAddress: aws.Bool(true),
  4505. DeviceIndex: aws.Int64(0),
  4506. Groups: []*string{
  4507. aws.String("sg-1a2b3c4d"),
  4508. },
  4509. SubnetId: aws.String("subnet-1a2b3c4d"),
  4510. },
  4511. },
  4512. },
  4513. },
  4514. SpotPrice: aws.String("0.04"),
  4515. TargetCapacity: aws.Int64(2),
  4516. },
  4517. }
  4518. result, err := svc.RequestSpotFleet(input)
  4519. if err != nil {
  4520. if aerr, ok := err.(awserr.Error); ok {
  4521. switch aerr.Code() {
  4522. default:
  4523. fmt.Println(aerr.Error())
  4524. }
  4525. } else {
  4526. // Print the error, cast err to awserr.Error to get the Code and
  4527. // Message from an error.
  4528. fmt.Println(err.Error())
  4529. }
  4530. return
  4531. }
  4532. fmt.Println(result)
  4533. }
  4534. // To request a Spot fleet using the diversified allocation strategy
  4535. //
  4536. // This example creates a Spot fleet request that launches 30 instances using the diversified
  4537. // allocation strategy. The launch specifications differ by instance type. The Spot
  4538. // fleet distributes the instances across the launch specifications such that there
  4539. // are 10 instances of each type.
  4540. func ExampleEC2_RequestSpotFleet_shared03() {
  4541. svc := ec2.New(session.New())
  4542. input := &ec2.RequestSpotFleetInput{
  4543. SpotFleetRequestConfig: &ec2.SpotFleetRequestConfigData{
  4544. AllocationStrategy: aws.String("diversified"),
  4545. IamFleetRole: aws.String("arn:aws:iam::123456789012:role/my-spot-fleet-role"),
  4546. LaunchSpecifications: []*ec2.SpotFleetLaunchSpecification{
  4547. {
  4548. ImageId: aws.String("ami-1a2b3c4d"),
  4549. InstanceType: aws.String("c4.2xlarge"),
  4550. SubnetId: aws.String("subnet-1a2b3c4d"),
  4551. },
  4552. {
  4553. ImageId: aws.String("ami-1a2b3c4d"),
  4554. InstanceType: aws.String("m3.2xlarge"),
  4555. SubnetId: aws.String("subnet-1a2b3c4d"),
  4556. },
  4557. {
  4558. ImageId: aws.String("ami-1a2b3c4d"),
  4559. InstanceType: aws.String("r3.2xlarge"),
  4560. SubnetId: aws.String("subnet-1a2b3c4d"),
  4561. },
  4562. },
  4563. SpotPrice: aws.String("0.70"),
  4564. TargetCapacity: aws.Int64(30),
  4565. },
  4566. }
  4567. result, err := svc.RequestSpotFleet(input)
  4568. if err != nil {
  4569. if aerr, ok := err.(awserr.Error); ok {
  4570. switch aerr.Code() {
  4571. default:
  4572. fmt.Println(aerr.Error())
  4573. }
  4574. } else {
  4575. // Print the error, cast err to awserr.Error to get the Code and
  4576. // Message from an error.
  4577. fmt.Println(err.Error())
  4578. }
  4579. return
  4580. }
  4581. fmt.Println(result)
  4582. }
  4583. // To create a one-time Spot Instance request
  4584. //
  4585. // This example creates a one-time Spot Instance request for five instances in the specified
  4586. // Availability Zone. If your account supports EC2-VPC only, Amazon EC2 launches the
  4587. // instances in the default subnet of the specified Availability Zone. If your account
  4588. // supports EC2-Classic, Amazon EC2 launches the instances in EC2-Classic in the specified
  4589. // Availability Zone.
  4590. func ExampleEC2_RequestSpotInstances_shared00() {
  4591. svc := ec2.New(session.New())
  4592. input := &ec2.RequestSpotInstancesInput{
  4593. InstanceCount: aws.Int64(5),
  4594. LaunchSpecification: &ec2.RequestSpotLaunchSpecification{
  4595. IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
  4596. Arn: aws.String("arn:aws:iam::123456789012:instance-profile/my-iam-role"),
  4597. },
  4598. ImageId: aws.String("ami-1a2b3c4d"),
  4599. InstanceType: aws.String("m3.medium"),
  4600. KeyName: aws.String("my-key-pair"),
  4601. Placement: &ec2.SpotPlacement{
  4602. AvailabilityZone: aws.String("us-west-2a"),
  4603. },
  4604. SecurityGroupIds: []*string{
  4605. aws.String("sg-1a2b3c4d"),
  4606. },
  4607. },
  4608. SpotPrice: aws.String("0.03"),
  4609. Type: aws.String("one-time"),
  4610. }
  4611. result, err := svc.RequestSpotInstances(input)
  4612. if err != nil {
  4613. if aerr, ok := err.(awserr.Error); ok {
  4614. switch aerr.Code() {
  4615. default:
  4616. fmt.Println(aerr.Error())
  4617. }
  4618. } else {
  4619. // Print the error, cast err to awserr.Error to get the Code and
  4620. // Message from an error.
  4621. fmt.Println(err.Error())
  4622. }
  4623. return
  4624. }
  4625. fmt.Println(result)
  4626. }
  4627. // To create a one-time Spot Instance request
  4628. //
  4629. // This example command creates a one-time Spot Instance request for five instances
  4630. // in the specified subnet. Amazon EC2 launches the instances in the specified subnet.
  4631. // If the VPC is a nondefault VPC, the instances do not receive a public IP address
  4632. // by default.
  4633. func ExampleEC2_RequestSpotInstances_shared01() {
  4634. svc := ec2.New(session.New())
  4635. input := &ec2.RequestSpotInstancesInput{
  4636. InstanceCount: aws.Int64(5),
  4637. LaunchSpecification: &ec2.RequestSpotLaunchSpecification{
  4638. IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
  4639. Arn: aws.String("arn:aws:iam::123456789012:instance-profile/my-iam-role"),
  4640. },
  4641. ImageId: aws.String("ami-1a2b3c4d"),
  4642. InstanceType: aws.String("m3.medium"),
  4643. SecurityGroupIds: []*string{
  4644. aws.String("sg-1a2b3c4d"),
  4645. },
  4646. SubnetId: aws.String("subnet-1a2b3c4d"),
  4647. },
  4648. SpotPrice: aws.String("0.050"),
  4649. Type: aws.String("one-time"),
  4650. }
  4651. result, err := svc.RequestSpotInstances(input)
  4652. if err != nil {
  4653. if aerr, ok := err.(awserr.Error); ok {
  4654. switch aerr.Code() {
  4655. default:
  4656. fmt.Println(aerr.Error())
  4657. }
  4658. } else {
  4659. // Print the error, cast err to awserr.Error to get the Code and
  4660. // Message from an error.
  4661. fmt.Println(err.Error())
  4662. }
  4663. return
  4664. }
  4665. fmt.Println(result)
  4666. }
  4667. // To reset the launchPermission attribute
  4668. //
  4669. // This example resets the launchPermission attribute for the specified AMI. By default,
  4670. // AMIs are private.
  4671. func ExampleEC2_ResetImageAttribute_shared00() {
  4672. svc := ec2.New(session.New())
  4673. input := &ec2.ResetImageAttributeInput{
  4674. Attribute: aws.String("launchPermission"),
  4675. ImageId: aws.String("ami-5731123e"),
  4676. }
  4677. result, err := svc.ResetImageAttribute(input)
  4678. if err != nil {
  4679. if aerr, ok := err.(awserr.Error); ok {
  4680. switch aerr.Code() {
  4681. default:
  4682. fmt.Println(aerr.Error())
  4683. }
  4684. } else {
  4685. // Print the error, cast err to awserr.Error to get the Code and
  4686. // Message from an error.
  4687. fmt.Println(err.Error())
  4688. }
  4689. return
  4690. }
  4691. fmt.Println(result)
  4692. }
  4693. // To reset the sourceDestCheck attribute
  4694. //
  4695. // This example resets the sourceDestCheck attribute for the specified instance.
  4696. func ExampleEC2_ResetInstanceAttribute_shared00() {
  4697. svc := ec2.New(session.New())
  4698. input := &ec2.ResetInstanceAttributeInput{
  4699. Attribute: aws.String("sourceDestCheck"),
  4700. InstanceId: aws.String("i-1234567890abcdef0"),
  4701. }
  4702. result, err := svc.ResetInstanceAttribute(input)
  4703. if err != nil {
  4704. if aerr, ok := err.(awserr.Error); ok {
  4705. switch aerr.Code() {
  4706. default:
  4707. fmt.Println(aerr.Error())
  4708. }
  4709. } else {
  4710. // Print the error, cast err to awserr.Error to get the Code and
  4711. // Message from an error.
  4712. fmt.Println(err.Error())
  4713. }
  4714. return
  4715. }
  4716. fmt.Println(result)
  4717. }
  4718. // To reset a snapshot attribute
  4719. //
  4720. // This example resets the create volume permissions for snapshot ``snap-1234567890abcdef0``.
  4721. // If the command succeeds, no output is returned.
  4722. func ExampleEC2_ResetSnapshotAttribute_shared00() {
  4723. svc := ec2.New(session.New())
  4724. input := &ec2.ResetSnapshotAttributeInput{
  4725. Attribute: aws.String("createVolumePermission"),
  4726. SnapshotId: aws.String("snap-1234567890abcdef0"),
  4727. }
  4728. result, err := svc.ResetSnapshotAttribute(input)
  4729. if err != nil {
  4730. if aerr, ok := err.(awserr.Error); ok {
  4731. switch aerr.Code() {
  4732. default:
  4733. fmt.Println(aerr.Error())
  4734. }
  4735. } else {
  4736. // Print the error, cast err to awserr.Error to get the Code and
  4737. // Message from an error.
  4738. fmt.Println(err.Error())
  4739. }
  4740. return
  4741. }
  4742. fmt.Println(result)
  4743. }
  4744. // To restore an address to EC2-Classic
  4745. //
  4746. // This example restores the specified Elastic IP address to the EC2-Classic platform.
  4747. func ExampleEC2_RestoreAddressToClassic_shared00() {
  4748. svc := ec2.New(session.New())
  4749. input := &ec2.RestoreAddressToClassicInput{
  4750. PublicIp: aws.String("198.51.100.0"),
  4751. }
  4752. result, err := svc.RestoreAddressToClassic(input)
  4753. if err != nil {
  4754. if aerr, ok := err.(awserr.Error); ok {
  4755. switch aerr.Code() {
  4756. default:
  4757. fmt.Println(aerr.Error())
  4758. }
  4759. } else {
  4760. // Print the error, cast err to awserr.Error to get the Code and
  4761. // Message from an error.
  4762. fmt.Println(err.Error())
  4763. }
  4764. return
  4765. }
  4766. fmt.Println(result)
  4767. }
  4768. // To launch an instance
  4769. //
  4770. // This example launches an instance using the specified AMI, instance type, security
  4771. // group, subnet, block device mapping, and tags.
  4772. func ExampleEC2_RunInstances_shared00() {
  4773. svc := ec2.New(session.New())
  4774. input := &ec2.RunInstancesInput{
  4775. BlockDeviceMappings: []*ec2.BlockDeviceMapping{
  4776. {
  4777. DeviceName: aws.String("/dev/sdh"),
  4778. Ebs: &ec2.EbsBlockDevice{
  4779. VolumeSize: aws.Int64(100),
  4780. },
  4781. },
  4782. },
  4783. ImageId: aws.String("ami-abc12345"),
  4784. InstanceType: aws.String("t2.micro"),
  4785. KeyName: aws.String("my-key-pair"),
  4786. MaxCount: aws.Int64(1),
  4787. MinCount: aws.Int64(1),
  4788. SecurityGroupIds: []*string{
  4789. aws.String("sg-1a2b3c4d"),
  4790. },
  4791. SubnetId: aws.String("subnet-6e7f829e"),
  4792. TagSpecifications: []*ec2.TagSpecification{
  4793. {
  4794. ResourceType: aws.String("instance"),
  4795. Tags: []*ec2.Tag{
  4796. {
  4797. Key: aws.String("Purpose"),
  4798. Value: aws.String("test"),
  4799. },
  4800. },
  4801. },
  4802. },
  4803. }
  4804. result, err := svc.RunInstances(input)
  4805. if err != nil {
  4806. if aerr, ok := err.(awserr.Error); ok {
  4807. switch aerr.Code() {
  4808. default:
  4809. fmt.Println(aerr.Error())
  4810. }
  4811. } else {
  4812. // Print the error, cast err to awserr.Error to get the Code and
  4813. // Message from an error.
  4814. fmt.Println(err.Error())
  4815. }
  4816. return
  4817. }
  4818. fmt.Println(result)
  4819. }
  4820. // To launch a Scheduled Instance in a VPC
  4821. //
  4822. // This example launches the specified Scheduled Instance in a VPC.
  4823. func ExampleEC2_RunScheduledInstances_shared00() {
  4824. svc := ec2.New(session.New())
  4825. input := &ec2.RunScheduledInstancesInput{
  4826. InstanceCount: aws.Int64(1),
  4827. LaunchSpecification: &ec2.ScheduledInstancesLaunchSpecification{
  4828. IamInstanceProfile: &ec2.ScheduledInstancesIamInstanceProfile{
  4829. Name: aws.String("my-iam-role"),
  4830. },
  4831. ImageId: aws.String("ami-12345678"),
  4832. InstanceType: aws.String("c4.large"),
  4833. KeyName: aws.String("my-key-pair"),
  4834. NetworkInterfaces: []*ec2.ScheduledInstancesNetworkInterface{
  4835. {
  4836. AssociatePublicIpAddress: aws.Bool(true),
  4837. DeviceIndex: aws.Int64(0),
  4838. Groups: []*string{
  4839. aws.String("sg-12345678"),
  4840. },
  4841. SubnetId: aws.String("subnet-12345678"),
  4842. },
  4843. },
  4844. },
  4845. ScheduledInstanceId: aws.String("sci-1234-1234-1234-1234-123456789012"),
  4846. }
  4847. result, err := svc.RunScheduledInstances(input)
  4848. if err != nil {
  4849. if aerr, ok := err.(awserr.Error); ok {
  4850. switch aerr.Code() {
  4851. default:
  4852. fmt.Println(aerr.Error())
  4853. }
  4854. } else {
  4855. // Print the error, cast err to awserr.Error to get the Code and
  4856. // Message from an error.
  4857. fmt.Println(err.Error())
  4858. }
  4859. return
  4860. }
  4861. fmt.Println(result)
  4862. }
  4863. // To launch a Scheduled Instance in EC2-Classic
  4864. //
  4865. // This example launches the specified Scheduled Instance in EC2-Classic.
  4866. func ExampleEC2_RunScheduledInstances_shared01() {
  4867. svc := ec2.New(session.New())
  4868. input := &ec2.RunScheduledInstancesInput{
  4869. InstanceCount: aws.Int64(1),
  4870. LaunchSpecification: &ec2.ScheduledInstancesLaunchSpecification{
  4871. IamInstanceProfile: &ec2.ScheduledInstancesIamInstanceProfile{
  4872. Name: aws.String("my-iam-role"),
  4873. },
  4874. ImageId: aws.String("ami-12345678"),
  4875. InstanceType: aws.String("c4.large"),
  4876. KeyName: aws.String("my-key-pair"),
  4877. Placement: &ec2.ScheduledInstancesPlacement{
  4878. AvailabilityZone: aws.String("us-west-2b"),
  4879. },
  4880. SecurityGroupIds: []*string{
  4881. aws.String("sg-12345678"),
  4882. },
  4883. },
  4884. ScheduledInstanceId: aws.String("sci-1234-1234-1234-1234-123456789012"),
  4885. }
  4886. result, err := svc.RunScheduledInstances(input)
  4887. if err != nil {
  4888. if aerr, ok := err.(awserr.Error); ok {
  4889. switch aerr.Code() {
  4890. default:
  4891. fmt.Println(aerr.Error())
  4892. }
  4893. } else {
  4894. // Print the error, cast err to awserr.Error to get the Code and
  4895. // Message from an error.
  4896. fmt.Println(err.Error())
  4897. }
  4898. return
  4899. }
  4900. fmt.Println(result)
  4901. }
  4902. // To start a stopped EC2 instance
  4903. //
  4904. // This example starts the specified EC2 instance.
  4905. func ExampleEC2_StartInstances_shared00() {
  4906. svc := ec2.New(session.New())
  4907. input := &ec2.StartInstancesInput{
  4908. InstanceIds: []*string{
  4909. aws.String("i-1234567890abcdef0"),
  4910. },
  4911. }
  4912. result, err := svc.StartInstances(input)
  4913. if err != nil {
  4914. if aerr, ok := err.(awserr.Error); ok {
  4915. switch aerr.Code() {
  4916. default:
  4917. fmt.Println(aerr.Error())
  4918. }
  4919. } else {
  4920. // Print the error, cast err to awserr.Error to get the Code and
  4921. // Message from an error.
  4922. fmt.Println(err.Error())
  4923. }
  4924. return
  4925. }
  4926. fmt.Println(result)
  4927. }
  4928. // To stop a running EC2 instance
  4929. //
  4930. // This example stops the specified EC2 instance.
  4931. func ExampleEC2_StopInstances_shared00() {
  4932. svc := ec2.New(session.New())
  4933. input := &ec2.StopInstancesInput{
  4934. InstanceIds: []*string{
  4935. aws.String("i-1234567890abcdef0"),
  4936. },
  4937. }
  4938. result, err := svc.StopInstances(input)
  4939. if err != nil {
  4940. if aerr, ok := err.(awserr.Error); ok {
  4941. switch aerr.Code() {
  4942. default:
  4943. fmt.Println(aerr.Error())
  4944. }
  4945. } else {
  4946. // Print the error, cast err to awserr.Error to get the Code and
  4947. // Message from an error.
  4948. fmt.Println(err.Error())
  4949. }
  4950. return
  4951. }
  4952. fmt.Println(result)
  4953. }
  4954. // To terminate an EC2 instance
  4955. //
  4956. // This example terminates the specified EC2 instance.
  4957. func ExampleEC2_TerminateInstances_shared00() {
  4958. svc := ec2.New(session.New())
  4959. input := &ec2.TerminateInstancesInput{
  4960. InstanceIds: []*string{
  4961. aws.String("i-1234567890abcdef0"),
  4962. },
  4963. }
  4964. result, err := svc.TerminateInstances(input)
  4965. if err != nil {
  4966. if aerr, ok := err.(awserr.Error); ok {
  4967. switch aerr.Code() {
  4968. default:
  4969. fmt.Println(aerr.Error())
  4970. }
  4971. } else {
  4972. // Print the error, cast err to awserr.Error to get the Code and
  4973. // Message from an error.
  4974. fmt.Println(err.Error())
  4975. }
  4976. return
  4977. }
  4978. fmt.Println(result)
  4979. }
  4980. // To unassign a secondary private IP address from a network interface
  4981. //
  4982. // This example unassigns the specified private IP address from the specified network
  4983. // interface.
  4984. func ExampleEC2_UnassignPrivateIpAddresses_shared00() {
  4985. svc := ec2.New(session.New())
  4986. input := &ec2.UnassignPrivateIpAddressesInput{
  4987. NetworkInterfaceId: aws.String("eni-e5aa89a3"),
  4988. PrivateIpAddresses: []*string{
  4989. aws.String("10.0.0.82"),
  4990. },
  4991. }
  4992. result, err := svc.UnassignPrivateIpAddresses(input)
  4993. if err != nil {
  4994. if aerr, ok := err.(awserr.Error); ok {
  4995. switch aerr.Code() {
  4996. default:
  4997. fmt.Println(aerr.Error())
  4998. }
  4999. } else {
  5000. // Print the error, cast err to awserr.Error to get the Code and
  5001. // Message from an error.
  5002. fmt.Println(err.Error())
  5003. }
  5004. return
  5005. }
  5006. fmt.Println(result)
  5007. }
  5008. // To update an outbound security group rule description
  5009. //
  5010. // This example updates the description for the specified security group rule.
  5011. func ExampleEC2_UpdateSecurityGroupRuleDescriptionsEgress_shared00() {
  5012. svc := ec2.New(session.New())
  5013. input := &ec2.UpdateSecurityGroupRuleDescriptionsEgressInput{
  5014. GroupId: aws.String("sg-123abc12"),
  5015. IpPermissions: []*ec2.IpPermission{
  5016. {
  5017. FromPort: aws.Int64(80),
  5018. IpProtocol: aws.String("tcp"),
  5019. IpRanges: []*ec2.IpRange{
  5020. {
  5021. CidrIp: aws.String("203.0.113.0/24"),
  5022. Description: aws.String("Outbound HTTP access to server 2"),
  5023. },
  5024. },
  5025. ToPort: aws.Int64(80),
  5026. },
  5027. },
  5028. }
  5029. result, err := svc.UpdateSecurityGroupRuleDescriptionsEgress(input)
  5030. if err != nil {
  5031. if aerr, ok := err.(awserr.Error); ok {
  5032. switch aerr.Code() {
  5033. default:
  5034. fmt.Println(aerr.Error())
  5035. }
  5036. } else {
  5037. // Print the error, cast err to awserr.Error to get the Code and
  5038. // Message from an error.
  5039. fmt.Println(err.Error())
  5040. }
  5041. return
  5042. }
  5043. fmt.Println(result)
  5044. }
  5045. // To update an inbound security group rule description
  5046. //
  5047. // This example updates the description for the specified security group rule.
  5048. func ExampleEC2_UpdateSecurityGroupRuleDescriptionsIngress_shared00() {
  5049. svc := ec2.New(session.New())
  5050. input := &ec2.UpdateSecurityGroupRuleDescriptionsIngressInput{
  5051. GroupId: aws.String("sg-123abc12"),
  5052. IpPermissions: []*ec2.IpPermission{
  5053. {
  5054. FromPort: aws.Int64(22),
  5055. IpProtocol: aws.String("tcp"),
  5056. IpRanges: []*ec2.IpRange{
  5057. {
  5058. CidrIp: aws.String("203.0.113.0/16"),
  5059. Description: aws.String("SSH access from the LA office"),
  5060. },
  5061. },
  5062. ToPort: aws.Int64(22),
  5063. },
  5064. },
  5065. }
  5066. result, err := svc.UpdateSecurityGroupRuleDescriptionsIngress(input)
  5067. if err != nil {
  5068. if aerr, ok := err.(awserr.Error); ok {
  5069. switch aerr.Code() {
  5070. default:
  5071. fmt.Println(aerr.Error())
  5072. }
  5073. } else {
  5074. // Print the error, cast err to awserr.Error to get the Code and
  5075. // Message from an error.
  5076. fmt.Println(err.Error())
  5077. }
  5078. return
  5079. }
  5080. fmt.Println(result)
  5081. }