examples_test.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package route53_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/route53"
  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 associate a VPC with a hosted zone
  23. //
  24. // The following example associates the VPC with ID vpc-1a2b3c4d with the hosted zone
  25. // with ID Z3M3LMPEXAMPLE.
  26. func ExampleRoute53_AssociateVPCWithHostedZone_shared00() {
  27. svc := route53.New(session.New())
  28. input := &route53.AssociateVPCWithHostedZoneInput{
  29. Comment: aws.String(""),
  30. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  31. VPC: &route53.VPC{
  32. VPCId: aws.String("vpc-1a2b3c4d"),
  33. VPCRegion: aws.String("us-east-2"),
  34. },
  35. }
  36. result, err := svc.AssociateVPCWithHostedZone(input)
  37. if err != nil {
  38. if aerr, ok := err.(awserr.Error); ok {
  39. switch aerr.Code() {
  40. case route53.ErrCodeNoSuchHostedZone:
  41. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  42. case route53.ErrCodeNotAuthorizedException:
  43. fmt.Println(route53.ErrCodeNotAuthorizedException, aerr.Error())
  44. case route53.ErrCodeInvalidVPCId:
  45. fmt.Println(route53.ErrCodeInvalidVPCId, aerr.Error())
  46. case route53.ErrCodeInvalidInput:
  47. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  48. case route53.ErrCodePublicZoneVPCAssociation:
  49. fmt.Println(route53.ErrCodePublicZoneVPCAssociation, aerr.Error())
  50. case route53.ErrCodeConflictingDomainExists:
  51. fmt.Println(route53.ErrCodeConflictingDomainExists, aerr.Error())
  52. case route53.ErrCodeLimitsExceeded:
  53. fmt.Println(route53.ErrCodeLimitsExceeded, aerr.Error())
  54. default:
  55. fmt.Println(aerr.Error())
  56. }
  57. } else {
  58. // Print the error, cast err to awserr.Error to get the Code and
  59. // Message from an error.
  60. fmt.Println(err.Error())
  61. }
  62. return
  63. }
  64. fmt.Println(result)
  65. }
  66. // To create a basic resource record set
  67. //
  68. // The following example creates a resource record set that routes Internet traffic
  69. // to a resource with an IP address of 192.0.2.44.
  70. func ExampleRoute53_ChangeResourceRecordSets_shared00() {
  71. svc := route53.New(session.New())
  72. input := &route53.ChangeResourceRecordSetsInput{
  73. ChangeBatch: &route53.ChangeBatch{
  74. Changes: []*route53.Change{
  75. {
  76. Action: aws.String("CREATE"),
  77. ResourceRecordSet: &route53.ResourceRecordSet{
  78. Name: aws.String("example.com"),
  79. ResourceRecords: []*route53.ResourceRecord{
  80. {
  81. Value: aws.String("192.0.2.44"),
  82. },
  83. },
  84. TTL: aws.Int64(60),
  85. Type: aws.String("A"),
  86. },
  87. },
  88. },
  89. Comment: aws.String("Web server for example.com"),
  90. },
  91. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  92. }
  93. result, err := svc.ChangeResourceRecordSets(input)
  94. if err != nil {
  95. if aerr, ok := err.(awserr.Error); ok {
  96. switch aerr.Code() {
  97. case route53.ErrCodeNoSuchHostedZone:
  98. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  99. case route53.ErrCodeNoSuchHealthCheck:
  100. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  101. case route53.ErrCodeInvalidChangeBatch:
  102. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  103. case route53.ErrCodeInvalidInput:
  104. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  105. case route53.ErrCodePriorRequestNotComplete:
  106. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  107. default:
  108. fmt.Println(aerr.Error())
  109. }
  110. } else {
  111. // Print the error, cast err to awserr.Error to get the Code and
  112. // Message from an error.
  113. fmt.Println(err.Error())
  114. }
  115. return
  116. }
  117. fmt.Println(result)
  118. }
  119. // To create weighted resource record sets
  120. //
  121. // The following example creates two weighted resource record sets. The resource with
  122. // a Weight of 100 will get 1/3rd of traffic (100/100+200), and the other resource will
  123. // get the rest of the traffic for example.com.
  124. func ExampleRoute53_ChangeResourceRecordSets_shared01() {
  125. svc := route53.New(session.New())
  126. input := &route53.ChangeResourceRecordSetsInput{
  127. ChangeBatch: &route53.ChangeBatch{
  128. Changes: []*route53.Change{
  129. {
  130. Action: aws.String("CREATE"),
  131. ResourceRecordSet: &route53.ResourceRecordSet{
  132. HealthCheckId: aws.String("abcdef11-2222-3333-4444-555555fedcba"),
  133. Name: aws.String("example.com"),
  134. ResourceRecords: []*route53.ResourceRecord{
  135. {
  136. Value: aws.String("192.0.2.44"),
  137. },
  138. },
  139. SetIdentifier: aws.String("Seattle data center"),
  140. TTL: aws.Int64(60),
  141. Type: aws.String("A"),
  142. Weight: aws.Int64(100),
  143. },
  144. },
  145. {
  146. Action: aws.String("CREATE"),
  147. ResourceRecordSet: &route53.ResourceRecordSet{
  148. HealthCheckId: aws.String("abcdef66-7777-8888-9999-000000fedcba"),
  149. Name: aws.String("example.com"),
  150. ResourceRecords: []*route53.ResourceRecord{
  151. {
  152. Value: aws.String("192.0.2.45"),
  153. },
  154. },
  155. SetIdentifier: aws.String("Portland data center"),
  156. TTL: aws.Int64(60),
  157. Type: aws.String("A"),
  158. Weight: aws.Int64(200),
  159. },
  160. },
  161. },
  162. Comment: aws.String("Web servers for example.com"),
  163. },
  164. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  165. }
  166. result, err := svc.ChangeResourceRecordSets(input)
  167. if err != nil {
  168. if aerr, ok := err.(awserr.Error); ok {
  169. switch aerr.Code() {
  170. case route53.ErrCodeNoSuchHostedZone:
  171. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  172. case route53.ErrCodeNoSuchHealthCheck:
  173. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  174. case route53.ErrCodeInvalidChangeBatch:
  175. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  176. case route53.ErrCodeInvalidInput:
  177. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  178. case route53.ErrCodePriorRequestNotComplete:
  179. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  180. default:
  181. fmt.Println(aerr.Error())
  182. }
  183. } else {
  184. // Print the error, cast err to awserr.Error to get the Code and
  185. // Message from an error.
  186. fmt.Println(err.Error())
  187. }
  188. return
  189. }
  190. fmt.Println(result)
  191. }
  192. // To create an alias resource record set
  193. //
  194. // The following example creates an alias resource record set that routes traffic to
  195. // a CloudFront distribution.
  196. func ExampleRoute53_ChangeResourceRecordSets_shared02() {
  197. svc := route53.New(session.New())
  198. input := &route53.ChangeResourceRecordSetsInput{
  199. ChangeBatch: &route53.ChangeBatch{
  200. Changes: []*route53.Change{
  201. {
  202. Action: aws.String("CREATE"),
  203. ResourceRecordSet: &route53.ResourceRecordSet{
  204. AliasTarget: &route53.AliasTarget{
  205. DNSName: aws.String("d123rk29d0stfj.cloudfront.net"),
  206. EvaluateTargetHealth: aws.Bool(false),
  207. HostedZoneId: aws.String("Z2FDTNDATAQYW2"),
  208. },
  209. Name: aws.String("example.com"),
  210. Type: aws.String("A"),
  211. },
  212. },
  213. },
  214. Comment: aws.String("CloudFront distribution for example.com"),
  215. },
  216. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  217. }
  218. result, err := svc.ChangeResourceRecordSets(input)
  219. if err != nil {
  220. if aerr, ok := err.(awserr.Error); ok {
  221. switch aerr.Code() {
  222. case route53.ErrCodeNoSuchHostedZone:
  223. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  224. case route53.ErrCodeNoSuchHealthCheck:
  225. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  226. case route53.ErrCodeInvalidChangeBatch:
  227. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  228. case route53.ErrCodeInvalidInput:
  229. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  230. case route53.ErrCodePriorRequestNotComplete:
  231. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  232. default:
  233. fmt.Println(aerr.Error())
  234. }
  235. } else {
  236. // Print the error, cast err to awserr.Error to get the Code and
  237. // Message from an error.
  238. fmt.Println(err.Error())
  239. }
  240. return
  241. }
  242. fmt.Println(result)
  243. }
  244. // To create weighted alias resource record sets
  245. //
  246. // The following example creates two weighted alias resource record sets that route
  247. // traffic to ELB load balancers. The resource with a Weight of 100 will get 1/3rd of
  248. // traffic (100/100+200), and the other resource will get the rest of the traffic for
  249. // example.com.
  250. func ExampleRoute53_ChangeResourceRecordSets_shared03() {
  251. svc := route53.New(session.New())
  252. input := &route53.ChangeResourceRecordSetsInput{
  253. ChangeBatch: &route53.ChangeBatch{
  254. Changes: []*route53.Change{
  255. {
  256. Action: aws.String("CREATE"),
  257. ResourceRecordSet: &route53.ResourceRecordSet{
  258. AliasTarget: &route53.AliasTarget{
  259. DNSName: aws.String("example-com-123456789.us-east-2.elb.amazonaws.com "),
  260. EvaluateTargetHealth: aws.Bool(true),
  261. HostedZoneId: aws.String("Z3AADJGX6KTTL2"),
  262. },
  263. Name: aws.String("example.com"),
  264. SetIdentifier: aws.String("Ohio region"),
  265. Type: aws.String("A"),
  266. Weight: aws.Int64(100),
  267. },
  268. },
  269. {
  270. Action: aws.String("CREATE"),
  271. ResourceRecordSet: &route53.ResourceRecordSet{
  272. AliasTarget: &route53.AliasTarget{
  273. DNSName: aws.String("example-com-987654321.us-west-2.elb.amazonaws.com "),
  274. EvaluateTargetHealth: aws.Bool(true),
  275. HostedZoneId: aws.String("Z1H1FL5HABSF5"),
  276. },
  277. Name: aws.String("example.com"),
  278. SetIdentifier: aws.String("Oregon region"),
  279. Type: aws.String("A"),
  280. Weight: aws.Int64(200),
  281. },
  282. },
  283. },
  284. Comment: aws.String("ELB load balancers for example.com"),
  285. },
  286. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  287. }
  288. result, err := svc.ChangeResourceRecordSets(input)
  289. if err != nil {
  290. if aerr, ok := err.(awserr.Error); ok {
  291. switch aerr.Code() {
  292. case route53.ErrCodeNoSuchHostedZone:
  293. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  294. case route53.ErrCodeNoSuchHealthCheck:
  295. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  296. case route53.ErrCodeInvalidChangeBatch:
  297. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  298. case route53.ErrCodeInvalidInput:
  299. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  300. case route53.ErrCodePriorRequestNotComplete:
  301. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  302. default:
  303. fmt.Println(aerr.Error())
  304. }
  305. } else {
  306. // Print the error, cast err to awserr.Error to get the Code and
  307. // Message from an error.
  308. fmt.Println(err.Error())
  309. }
  310. return
  311. }
  312. fmt.Println(result)
  313. }
  314. // To create latency resource record sets
  315. //
  316. // The following example creates two latency resource record sets that route traffic
  317. // to EC2 instances. Traffic for example.com is routed either to the Ohio region or
  318. // the Oregon region, depending on the latency between the user and those regions.
  319. func ExampleRoute53_ChangeResourceRecordSets_shared04() {
  320. svc := route53.New(session.New())
  321. input := &route53.ChangeResourceRecordSetsInput{
  322. ChangeBatch: &route53.ChangeBatch{
  323. Changes: []*route53.Change{
  324. {
  325. Action: aws.String("CREATE"),
  326. ResourceRecordSet: &route53.ResourceRecordSet{
  327. HealthCheckId: aws.String("abcdef11-2222-3333-4444-555555fedcba"),
  328. Name: aws.String("example.com"),
  329. Region: aws.String("us-east-2"),
  330. ResourceRecords: []*route53.ResourceRecord{
  331. {
  332. Value: aws.String("192.0.2.44"),
  333. },
  334. },
  335. SetIdentifier: aws.String("Ohio region"),
  336. TTL: aws.Int64(60),
  337. Type: aws.String("A"),
  338. },
  339. },
  340. {
  341. Action: aws.String("CREATE"),
  342. ResourceRecordSet: &route53.ResourceRecordSet{
  343. HealthCheckId: aws.String("abcdef66-7777-8888-9999-000000fedcba"),
  344. Name: aws.String("example.com"),
  345. Region: aws.String("us-west-2"),
  346. ResourceRecords: []*route53.ResourceRecord{
  347. {
  348. Value: aws.String("192.0.2.45"),
  349. },
  350. },
  351. SetIdentifier: aws.String("Oregon region"),
  352. TTL: aws.Int64(60),
  353. Type: aws.String("A"),
  354. },
  355. },
  356. },
  357. Comment: aws.String("EC2 instances for example.com"),
  358. },
  359. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  360. }
  361. result, err := svc.ChangeResourceRecordSets(input)
  362. if err != nil {
  363. if aerr, ok := err.(awserr.Error); ok {
  364. switch aerr.Code() {
  365. case route53.ErrCodeNoSuchHostedZone:
  366. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  367. case route53.ErrCodeNoSuchHealthCheck:
  368. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  369. case route53.ErrCodeInvalidChangeBatch:
  370. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  371. case route53.ErrCodeInvalidInput:
  372. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  373. case route53.ErrCodePriorRequestNotComplete:
  374. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  375. default:
  376. fmt.Println(aerr.Error())
  377. }
  378. } else {
  379. // Print the error, cast err to awserr.Error to get the Code and
  380. // Message from an error.
  381. fmt.Println(err.Error())
  382. }
  383. return
  384. }
  385. fmt.Println(result)
  386. }
  387. // To create latency alias resource record sets
  388. //
  389. // The following example creates two latency alias resource record sets that route traffic
  390. // for example.com to ELB load balancers. Requests are routed either to the Ohio region
  391. // or the Oregon region, depending on the latency between the user and those regions.
  392. func ExampleRoute53_ChangeResourceRecordSets_shared05() {
  393. svc := route53.New(session.New())
  394. input := &route53.ChangeResourceRecordSetsInput{
  395. ChangeBatch: &route53.ChangeBatch{
  396. Changes: []*route53.Change{
  397. {
  398. Action: aws.String("CREATE"),
  399. ResourceRecordSet: &route53.ResourceRecordSet{
  400. AliasTarget: &route53.AliasTarget{
  401. DNSName: aws.String("example-com-123456789.us-east-2.elb.amazonaws.com "),
  402. EvaluateTargetHealth: aws.Bool(true),
  403. HostedZoneId: aws.String("Z3AADJGX6KTTL2"),
  404. },
  405. Name: aws.String("example.com"),
  406. Region: aws.String("us-east-2"),
  407. SetIdentifier: aws.String("Ohio region"),
  408. Type: aws.String("A"),
  409. },
  410. },
  411. {
  412. Action: aws.String("CREATE"),
  413. ResourceRecordSet: &route53.ResourceRecordSet{
  414. AliasTarget: &route53.AliasTarget{
  415. DNSName: aws.String("example-com-987654321.us-west-2.elb.amazonaws.com "),
  416. EvaluateTargetHealth: aws.Bool(true),
  417. HostedZoneId: aws.String("Z1H1FL5HABSF5"),
  418. },
  419. Name: aws.String("example.com"),
  420. Region: aws.String("us-west-2"),
  421. SetIdentifier: aws.String("Oregon region"),
  422. Type: aws.String("A"),
  423. },
  424. },
  425. },
  426. Comment: aws.String("ELB load balancers for example.com"),
  427. },
  428. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  429. }
  430. result, err := svc.ChangeResourceRecordSets(input)
  431. if err != nil {
  432. if aerr, ok := err.(awserr.Error); ok {
  433. switch aerr.Code() {
  434. case route53.ErrCodeNoSuchHostedZone:
  435. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  436. case route53.ErrCodeNoSuchHealthCheck:
  437. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  438. case route53.ErrCodeInvalidChangeBatch:
  439. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  440. case route53.ErrCodeInvalidInput:
  441. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  442. case route53.ErrCodePriorRequestNotComplete:
  443. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  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 create failover resource record sets
  457. //
  458. // The following example creates primary and secondary failover resource record sets
  459. // that route traffic to EC2 instances. Traffic is generally routed to the primary resource,
  460. // in the Ohio region. If that resource is unavailable, traffic is routed to the secondary
  461. // resource, in the Oregon region.
  462. func ExampleRoute53_ChangeResourceRecordSets_shared06() {
  463. svc := route53.New(session.New())
  464. input := &route53.ChangeResourceRecordSetsInput{
  465. ChangeBatch: &route53.ChangeBatch{
  466. Changes: []*route53.Change{
  467. {
  468. Action: aws.String("CREATE"),
  469. ResourceRecordSet: &route53.ResourceRecordSet{
  470. Failover: aws.String("PRIMARY"),
  471. HealthCheckId: aws.String("abcdef11-2222-3333-4444-555555fedcba"),
  472. Name: aws.String("example.com"),
  473. ResourceRecords: []*route53.ResourceRecord{
  474. {
  475. Value: aws.String("192.0.2.44"),
  476. },
  477. },
  478. SetIdentifier: aws.String("Ohio region"),
  479. TTL: aws.Int64(60),
  480. Type: aws.String("A"),
  481. },
  482. },
  483. {
  484. Action: aws.String("CREATE"),
  485. ResourceRecordSet: &route53.ResourceRecordSet{
  486. Failover: aws.String("SECONDARY"),
  487. HealthCheckId: aws.String("abcdef66-7777-8888-9999-000000fedcba"),
  488. Name: aws.String("example.com"),
  489. ResourceRecords: []*route53.ResourceRecord{
  490. {
  491. Value: aws.String("192.0.2.45"),
  492. },
  493. },
  494. SetIdentifier: aws.String("Oregon region"),
  495. TTL: aws.Int64(60),
  496. Type: aws.String("A"),
  497. },
  498. },
  499. },
  500. Comment: aws.String("Failover configuration for example.com"),
  501. },
  502. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  503. }
  504. result, err := svc.ChangeResourceRecordSets(input)
  505. if err != nil {
  506. if aerr, ok := err.(awserr.Error); ok {
  507. switch aerr.Code() {
  508. case route53.ErrCodeNoSuchHostedZone:
  509. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  510. case route53.ErrCodeNoSuchHealthCheck:
  511. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  512. case route53.ErrCodeInvalidChangeBatch:
  513. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  514. case route53.ErrCodeInvalidInput:
  515. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  516. case route53.ErrCodePriorRequestNotComplete:
  517. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  518. default:
  519. fmt.Println(aerr.Error())
  520. }
  521. } else {
  522. // Print the error, cast err to awserr.Error to get the Code and
  523. // Message from an error.
  524. fmt.Println(err.Error())
  525. }
  526. return
  527. }
  528. fmt.Println(result)
  529. }
  530. // To create failover alias resource record sets
  531. //
  532. // The following example creates primary and secondary failover alias resource record
  533. // sets that route traffic to ELB load balancers. Traffic is generally routed to the
  534. // primary resource, in the Ohio region. If that resource is unavailable, traffic is
  535. // routed to the secondary resource, in the Oregon region.
  536. func ExampleRoute53_ChangeResourceRecordSets_shared07() {
  537. svc := route53.New(session.New())
  538. input := &route53.ChangeResourceRecordSetsInput{
  539. ChangeBatch: &route53.ChangeBatch{
  540. Changes: []*route53.Change{
  541. {
  542. Action: aws.String("CREATE"),
  543. ResourceRecordSet: &route53.ResourceRecordSet{
  544. AliasTarget: &route53.AliasTarget{
  545. DNSName: aws.String("example-com-123456789.us-east-2.elb.amazonaws.com "),
  546. EvaluateTargetHealth: aws.Bool(true),
  547. HostedZoneId: aws.String("Z3AADJGX6KTTL2"),
  548. },
  549. Failover: aws.String("PRIMARY"),
  550. Name: aws.String("example.com"),
  551. SetIdentifier: aws.String("Ohio region"),
  552. Type: aws.String("A"),
  553. },
  554. },
  555. {
  556. Action: aws.String("CREATE"),
  557. ResourceRecordSet: &route53.ResourceRecordSet{
  558. AliasTarget: &route53.AliasTarget{
  559. DNSName: aws.String("example-com-987654321.us-west-2.elb.amazonaws.com "),
  560. EvaluateTargetHealth: aws.Bool(true),
  561. HostedZoneId: aws.String("Z1H1FL5HABSF5"),
  562. },
  563. Failover: aws.String("SECONDARY"),
  564. Name: aws.String("example.com"),
  565. SetIdentifier: aws.String("Oregon region"),
  566. Type: aws.String("A"),
  567. },
  568. },
  569. },
  570. Comment: aws.String("Failover alias configuration for example.com"),
  571. },
  572. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  573. }
  574. result, err := svc.ChangeResourceRecordSets(input)
  575. if err != nil {
  576. if aerr, ok := err.(awserr.Error); ok {
  577. switch aerr.Code() {
  578. case route53.ErrCodeNoSuchHostedZone:
  579. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  580. case route53.ErrCodeNoSuchHealthCheck:
  581. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  582. case route53.ErrCodeInvalidChangeBatch:
  583. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  584. case route53.ErrCodeInvalidInput:
  585. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  586. case route53.ErrCodePriorRequestNotComplete:
  587. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  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 create geolocation resource record sets
  601. //
  602. // The following example creates four geolocation resource record sets that use IPv4
  603. // addresses to route traffic to resources such as web servers running on EC2 instances.
  604. // Traffic is routed to one of four IP addresses, for North America (NA), for South
  605. // America (SA), for Europe (EU), and for all other locations (*).
  606. func ExampleRoute53_ChangeResourceRecordSets_shared08() {
  607. svc := route53.New(session.New())
  608. input := &route53.ChangeResourceRecordSetsInput{
  609. ChangeBatch: &route53.ChangeBatch{
  610. Changes: []*route53.Change{
  611. {
  612. Action: aws.String("CREATE"),
  613. ResourceRecordSet: &route53.ResourceRecordSet{
  614. GeoLocation: &route53.GeoLocation{
  615. ContinentCode: aws.String("NA"),
  616. },
  617. Name: aws.String("example.com"),
  618. ResourceRecords: []*route53.ResourceRecord{
  619. {
  620. Value: aws.String("192.0.2.44"),
  621. },
  622. },
  623. SetIdentifier: aws.String("North America"),
  624. TTL: aws.Int64(60),
  625. Type: aws.String("A"),
  626. },
  627. },
  628. {
  629. Action: aws.String("CREATE"),
  630. ResourceRecordSet: &route53.ResourceRecordSet{
  631. GeoLocation: &route53.GeoLocation{
  632. ContinentCode: aws.String("SA"),
  633. },
  634. Name: aws.String("example.com"),
  635. ResourceRecords: []*route53.ResourceRecord{
  636. {
  637. Value: aws.String("192.0.2.45"),
  638. },
  639. },
  640. SetIdentifier: aws.String("South America"),
  641. TTL: aws.Int64(60),
  642. Type: aws.String("A"),
  643. },
  644. },
  645. {
  646. Action: aws.String("CREATE"),
  647. ResourceRecordSet: &route53.ResourceRecordSet{
  648. GeoLocation: &route53.GeoLocation{
  649. ContinentCode: aws.String("EU"),
  650. },
  651. Name: aws.String("example.com"),
  652. ResourceRecords: []*route53.ResourceRecord{
  653. {
  654. Value: aws.String("192.0.2.46"),
  655. },
  656. },
  657. SetIdentifier: aws.String("Europe"),
  658. TTL: aws.Int64(60),
  659. Type: aws.String("A"),
  660. },
  661. },
  662. {
  663. Action: aws.String("CREATE"),
  664. ResourceRecordSet: &route53.ResourceRecordSet{
  665. GeoLocation: &route53.GeoLocation{
  666. CountryCode: aws.String("*"),
  667. },
  668. Name: aws.String("example.com"),
  669. ResourceRecords: []*route53.ResourceRecord{
  670. {
  671. Value: aws.String("192.0.2.47"),
  672. },
  673. },
  674. SetIdentifier: aws.String("Other locations"),
  675. TTL: aws.Int64(60),
  676. Type: aws.String("A"),
  677. },
  678. },
  679. },
  680. Comment: aws.String("Geolocation configuration for example.com"),
  681. },
  682. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  683. }
  684. result, err := svc.ChangeResourceRecordSets(input)
  685. if err != nil {
  686. if aerr, ok := err.(awserr.Error); ok {
  687. switch aerr.Code() {
  688. case route53.ErrCodeNoSuchHostedZone:
  689. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  690. case route53.ErrCodeNoSuchHealthCheck:
  691. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  692. case route53.ErrCodeInvalidChangeBatch:
  693. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  694. case route53.ErrCodeInvalidInput:
  695. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  696. case route53.ErrCodePriorRequestNotComplete:
  697. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  698. default:
  699. fmt.Println(aerr.Error())
  700. }
  701. } else {
  702. // Print the error, cast err to awserr.Error to get the Code and
  703. // Message from an error.
  704. fmt.Println(err.Error())
  705. }
  706. return
  707. }
  708. fmt.Println(result)
  709. }
  710. // To create geolocation alias resource record sets
  711. //
  712. // The following example creates four geolocation alias resource record sets that route
  713. // traffic to ELB load balancers. Traffic is routed to one of four IP addresses, for
  714. // North America (NA), for South America (SA), for Europe (EU), and for all other locations
  715. // (*).
  716. func ExampleRoute53_ChangeResourceRecordSets_shared09() {
  717. svc := route53.New(session.New())
  718. input := &route53.ChangeResourceRecordSetsInput{
  719. ChangeBatch: &route53.ChangeBatch{
  720. Changes: []*route53.Change{
  721. {
  722. Action: aws.String("CREATE"),
  723. ResourceRecordSet: &route53.ResourceRecordSet{
  724. AliasTarget: &route53.AliasTarget{
  725. DNSName: aws.String("example-com-123456789.us-east-2.elb.amazonaws.com "),
  726. EvaluateTargetHealth: aws.Bool(true),
  727. HostedZoneId: aws.String("Z3AADJGX6KTTL2"),
  728. },
  729. GeoLocation: &route53.GeoLocation{
  730. ContinentCode: aws.String("NA"),
  731. },
  732. Name: aws.String("example.com"),
  733. SetIdentifier: aws.String("North America"),
  734. Type: aws.String("A"),
  735. },
  736. },
  737. {
  738. Action: aws.String("CREATE"),
  739. ResourceRecordSet: &route53.ResourceRecordSet{
  740. AliasTarget: &route53.AliasTarget{
  741. DNSName: aws.String("example-com-234567890.sa-east-1.elb.amazonaws.com "),
  742. EvaluateTargetHealth: aws.Bool(true),
  743. HostedZoneId: aws.String("Z2P70J7HTTTPLU"),
  744. },
  745. GeoLocation: &route53.GeoLocation{
  746. ContinentCode: aws.String("SA"),
  747. },
  748. Name: aws.String("example.com"),
  749. SetIdentifier: aws.String("South America"),
  750. Type: aws.String("A"),
  751. },
  752. },
  753. {
  754. Action: aws.String("CREATE"),
  755. ResourceRecordSet: &route53.ResourceRecordSet{
  756. AliasTarget: &route53.AliasTarget{
  757. DNSName: aws.String("example-com-234567890.eu-central-1.elb.amazonaws.com "),
  758. EvaluateTargetHealth: aws.Bool(true),
  759. HostedZoneId: aws.String("Z215JYRZR1TBD5"),
  760. },
  761. GeoLocation: &route53.GeoLocation{
  762. ContinentCode: aws.String("EU"),
  763. },
  764. Name: aws.String("example.com"),
  765. SetIdentifier: aws.String("Europe"),
  766. Type: aws.String("A"),
  767. },
  768. },
  769. {
  770. Action: aws.String("CREATE"),
  771. ResourceRecordSet: &route53.ResourceRecordSet{
  772. AliasTarget: &route53.AliasTarget{
  773. DNSName: aws.String("example-com-234567890.ap-southeast-1.elb.amazonaws.com "),
  774. EvaluateTargetHealth: aws.Bool(true),
  775. HostedZoneId: aws.String("Z1LMS91P8CMLE5"),
  776. },
  777. GeoLocation: &route53.GeoLocation{
  778. CountryCode: aws.String("*"),
  779. },
  780. Name: aws.String("example.com"),
  781. SetIdentifier: aws.String("Other locations"),
  782. Type: aws.String("A"),
  783. },
  784. },
  785. },
  786. Comment: aws.String("Geolocation alias configuration for example.com"),
  787. },
  788. HostedZoneId: aws.String("Z3M3LMPEXAMPLE"),
  789. }
  790. result, err := svc.ChangeResourceRecordSets(input)
  791. if err != nil {
  792. if aerr, ok := err.(awserr.Error); ok {
  793. switch aerr.Code() {
  794. case route53.ErrCodeNoSuchHostedZone:
  795. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  796. case route53.ErrCodeNoSuchHealthCheck:
  797. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  798. case route53.ErrCodeInvalidChangeBatch:
  799. fmt.Println(route53.ErrCodeInvalidChangeBatch, aerr.Error())
  800. case route53.ErrCodeInvalidInput:
  801. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  802. case route53.ErrCodePriorRequestNotComplete:
  803. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  804. default:
  805. fmt.Println(aerr.Error())
  806. }
  807. } else {
  808. // Print the error, cast err to awserr.Error to get the Code and
  809. // Message from an error.
  810. fmt.Println(err.Error())
  811. }
  812. return
  813. }
  814. fmt.Println(result)
  815. }
  816. // To add or remove tags from a hosted zone or health check
  817. //
  818. // The following example adds two tags and removes one tag from the hosted zone with
  819. // ID Z3M3LMPEXAMPLE.
  820. func ExampleRoute53_ChangeTagsForResource_shared00() {
  821. svc := route53.New(session.New())
  822. input := &route53.ChangeTagsForResourceInput{
  823. AddTags: []*route53.Tag{
  824. {
  825. Key: aws.String("apex"),
  826. Value: aws.String("3874"),
  827. },
  828. {
  829. Key: aws.String("acme"),
  830. Value: aws.String("4938"),
  831. },
  832. },
  833. RemoveTagKeys: []*string{
  834. aws.String("Nadir"),
  835. },
  836. ResourceId: aws.String("Z3M3LMPEXAMPLE"),
  837. ResourceType: aws.String("hostedzone"),
  838. }
  839. result, err := svc.ChangeTagsForResource(input)
  840. if err != nil {
  841. if aerr, ok := err.(awserr.Error); ok {
  842. switch aerr.Code() {
  843. case route53.ErrCodeInvalidInput:
  844. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  845. case route53.ErrCodeNoSuchHealthCheck:
  846. fmt.Println(route53.ErrCodeNoSuchHealthCheck, aerr.Error())
  847. case route53.ErrCodeNoSuchHostedZone:
  848. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  849. case route53.ErrCodePriorRequestNotComplete:
  850. fmt.Println(route53.ErrCodePriorRequestNotComplete, aerr.Error())
  851. case route53.ErrCodeThrottlingException:
  852. fmt.Println(route53.ErrCodeThrottlingException, aerr.Error())
  853. default:
  854. fmt.Println(aerr.Error())
  855. }
  856. } else {
  857. // Print the error, cast err to awserr.Error to get the Code and
  858. // Message from an error.
  859. fmt.Println(err.Error())
  860. }
  861. return
  862. }
  863. fmt.Println(result)
  864. }
  865. // To get information about a hosted zone
  866. //
  867. // The following example gets information about the Z3M3LMPEXAMPLE hosted zone.
  868. func ExampleRoute53_GetHostedZone_shared00() {
  869. svc := route53.New(session.New())
  870. input := &route53.GetHostedZoneInput{
  871. Id: aws.String("Z3M3LMPEXAMPLE"),
  872. }
  873. result, err := svc.GetHostedZone(input)
  874. if err != nil {
  875. if aerr, ok := err.(awserr.Error); ok {
  876. switch aerr.Code() {
  877. case route53.ErrCodeNoSuchHostedZone:
  878. fmt.Println(route53.ErrCodeNoSuchHostedZone, aerr.Error())
  879. case route53.ErrCodeInvalidInput:
  880. fmt.Println(route53.ErrCodeInvalidInput, aerr.Error())
  881. default:
  882. fmt.Println(aerr.Error())
  883. }
  884. } else {
  885. // Print the error, cast err to awserr.Error to get the Code and
  886. // Message from an error.
  887. fmt.Println(err.Error())
  888. }
  889. return
  890. }
  891. fmt.Println(result)
  892. }