examples_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package cloudwatchlogs_test
  3. import (
  4. "bytes"
  5. "fmt"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/aws/session"
  9. "github.com/aws/aws-sdk-go/service/cloudwatchlogs"
  10. )
  11. var _ time.Duration
  12. var _ bytes.Buffer
  13. func ExampleCloudWatchLogs_CancelExportTask() {
  14. sess, err := session.NewSession()
  15. if err != nil {
  16. fmt.Println("failed to create session,", err)
  17. return
  18. }
  19. svc := cloudwatchlogs.New(sess)
  20. params := &cloudwatchlogs.CancelExportTaskInput{
  21. TaskId: aws.String("ExportTaskId"), // Required
  22. }
  23. resp, err := svc.CancelExportTask(params)
  24. if err != nil {
  25. // Print the error, cast err to awserr.Error to get the Code and
  26. // Message from an error.
  27. fmt.Println(err.Error())
  28. return
  29. }
  30. // Pretty-print the response data.
  31. fmt.Println(resp)
  32. }
  33. func ExampleCloudWatchLogs_CreateExportTask() {
  34. sess, err := session.NewSession()
  35. if err != nil {
  36. fmt.Println("failed to create session,", err)
  37. return
  38. }
  39. svc := cloudwatchlogs.New(sess)
  40. params := &cloudwatchlogs.CreateExportTaskInput{
  41. Destination: aws.String("ExportDestinationBucket"), // Required
  42. From: aws.Int64(1), // Required
  43. LogGroupName: aws.String("LogGroupName"), // Required
  44. To: aws.Int64(1), // Required
  45. DestinationPrefix: aws.String("ExportDestinationPrefix"),
  46. LogStreamNamePrefix: aws.String("LogStreamName"),
  47. TaskName: aws.String("ExportTaskName"),
  48. }
  49. resp, err := svc.CreateExportTask(params)
  50. if err != nil {
  51. // Print the error, cast err to awserr.Error to get the Code and
  52. // Message from an error.
  53. fmt.Println(err.Error())
  54. return
  55. }
  56. // Pretty-print the response data.
  57. fmt.Println(resp)
  58. }
  59. func ExampleCloudWatchLogs_CreateLogGroup() {
  60. sess, err := session.NewSession()
  61. if err != nil {
  62. fmt.Println("failed to create session,", err)
  63. return
  64. }
  65. svc := cloudwatchlogs.New(sess)
  66. params := &cloudwatchlogs.CreateLogGroupInput{
  67. LogGroupName: aws.String("LogGroupName"), // Required
  68. }
  69. resp, err := svc.CreateLogGroup(params)
  70. if err != nil {
  71. // Print the error, cast err to awserr.Error to get the Code and
  72. // Message from an error.
  73. fmt.Println(err.Error())
  74. return
  75. }
  76. // Pretty-print the response data.
  77. fmt.Println(resp)
  78. }
  79. func ExampleCloudWatchLogs_CreateLogStream() {
  80. sess, err := session.NewSession()
  81. if err != nil {
  82. fmt.Println("failed to create session,", err)
  83. return
  84. }
  85. svc := cloudwatchlogs.New(sess)
  86. params := &cloudwatchlogs.CreateLogStreamInput{
  87. LogGroupName: aws.String("LogGroupName"), // Required
  88. LogStreamName: aws.String("LogStreamName"), // Required
  89. }
  90. resp, err := svc.CreateLogStream(params)
  91. if err != nil {
  92. // Print the error, cast err to awserr.Error to get the Code and
  93. // Message from an error.
  94. fmt.Println(err.Error())
  95. return
  96. }
  97. // Pretty-print the response data.
  98. fmt.Println(resp)
  99. }
  100. func ExampleCloudWatchLogs_DeleteDestination() {
  101. sess, err := session.NewSession()
  102. if err != nil {
  103. fmt.Println("failed to create session,", err)
  104. return
  105. }
  106. svc := cloudwatchlogs.New(sess)
  107. params := &cloudwatchlogs.DeleteDestinationInput{
  108. DestinationName: aws.String("DestinationName"), // Required
  109. }
  110. resp, err := svc.DeleteDestination(params)
  111. if err != nil {
  112. // Print the error, cast err to awserr.Error to get the Code and
  113. // Message from an error.
  114. fmt.Println(err.Error())
  115. return
  116. }
  117. // Pretty-print the response data.
  118. fmt.Println(resp)
  119. }
  120. func ExampleCloudWatchLogs_DeleteLogGroup() {
  121. sess, err := session.NewSession()
  122. if err != nil {
  123. fmt.Println("failed to create session,", err)
  124. return
  125. }
  126. svc := cloudwatchlogs.New(sess)
  127. params := &cloudwatchlogs.DeleteLogGroupInput{
  128. LogGroupName: aws.String("LogGroupName"), // Required
  129. }
  130. resp, err := svc.DeleteLogGroup(params)
  131. if err != nil {
  132. // Print the error, cast err to awserr.Error to get the Code and
  133. // Message from an error.
  134. fmt.Println(err.Error())
  135. return
  136. }
  137. // Pretty-print the response data.
  138. fmt.Println(resp)
  139. }
  140. func ExampleCloudWatchLogs_DeleteLogStream() {
  141. sess, err := session.NewSession()
  142. if err != nil {
  143. fmt.Println("failed to create session,", err)
  144. return
  145. }
  146. svc := cloudwatchlogs.New(sess)
  147. params := &cloudwatchlogs.DeleteLogStreamInput{
  148. LogGroupName: aws.String("LogGroupName"), // Required
  149. LogStreamName: aws.String("LogStreamName"), // Required
  150. }
  151. resp, err := svc.DeleteLogStream(params)
  152. if err != nil {
  153. // Print the error, cast err to awserr.Error to get the Code and
  154. // Message from an error.
  155. fmt.Println(err.Error())
  156. return
  157. }
  158. // Pretty-print the response data.
  159. fmt.Println(resp)
  160. }
  161. func ExampleCloudWatchLogs_DeleteMetricFilter() {
  162. sess, err := session.NewSession()
  163. if err != nil {
  164. fmt.Println("failed to create session,", err)
  165. return
  166. }
  167. svc := cloudwatchlogs.New(sess)
  168. params := &cloudwatchlogs.DeleteMetricFilterInput{
  169. FilterName: aws.String("FilterName"), // Required
  170. LogGroupName: aws.String("LogGroupName"), // Required
  171. }
  172. resp, err := svc.DeleteMetricFilter(params)
  173. if err != nil {
  174. // Print the error, cast err to awserr.Error to get the Code and
  175. // Message from an error.
  176. fmt.Println(err.Error())
  177. return
  178. }
  179. // Pretty-print the response data.
  180. fmt.Println(resp)
  181. }
  182. func ExampleCloudWatchLogs_DeleteRetentionPolicy() {
  183. sess, err := session.NewSession()
  184. if err != nil {
  185. fmt.Println("failed to create session,", err)
  186. return
  187. }
  188. svc := cloudwatchlogs.New(sess)
  189. params := &cloudwatchlogs.DeleteRetentionPolicyInput{
  190. LogGroupName: aws.String("LogGroupName"), // Required
  191. }
  192. resp, err := svc.DeleteRetentionPolicy(params)
  193. if err != nil {
  194. // Print the error, cast err to awserr.Error to get the Code and
  195. // Message from an error.
  196. fmt.Println(err.Error())
  197. return
  198. }
  199. // Pretty-print the response data.
  200. fmt.Println(resp)
  201. }
  202. func ExampleCloudWatchLogs_DeleteSubscriptionFilter() {
  203. sess, err := session.NewSession()
  204. if err != nil {
  205. fmt.Println("failed to create session,", err)
  206. return
  207. }
  208. svc := cloudwatchlogs.New(sess)
  209. params := &cloudwatchlogs.DeleteSubscriptionFilterInput{
  210. FilterName: aws.String("FilterName"), // Required
  211. LogGroupName: aws.String("LogGroupName"), // Required
  212. }
  213. resp, err := svc.DeleteSubscriptionFilter(params)
  214. if err != nil {
  215. // Print the error, cast err to awserr.Error to get the Code and
  216. // Message from an error.
  217. fmt.Println(err.Error())
  218. return
  219. }
  220. // Pretty-print the response data.
  221. fmt.Println(resp)
  222. }
  223. func ExampleCloudWatchLogs_DescribeDestinations() {
  224. sess, err := session.NewSession()
  225. if err != nil {
  226. fmt.Println("failed to create session,", err)
  227. return
  228. }
  229. svc := cloudwatchlogs.New(sess)
  230. params := &cloudwatchlogs.DescribeDestinationsInput{
  231. DestinationNamePrefix: aws.String("DestinationName"),
  232. Limit: aws.Int64(1),
  233. NextToken: aws.String("NextToken"),
  234. }
  235. resp, err := svc.DescribeDestinations(params)
  236. if err != nil {
  237. // Print the error, cast err to awserr.Error to get the Code and
  238. // Message from an error.
  239. fmt.Println(err.Error())
  240. return
  241. }
  242. // Pretty-print the response data.
  243. fmt.Println(resp)
  244. }
  245. func ExampleCloudWatchLogs_DescribeExportTasks() {
  246. sess, err := session.NewSession()
  247. if err != nil {
  248. fmt.Println("failed to create session,", err)
  249. return
  250. }
  251. svc := cloudwatchlogs.New(sess)
  252. params := &cloudwatchlogs.DescribeExportTasksInput{
  253. Limit: aws.Int64(1),
  254. NextToken: aws.String("NextToken"),
  255. StatusCode: aws.String("ExportTaskStatusCode"),
  256. TaskId: aws.String("ExportTaskId"),
  257. }
  258. resp, err := svc.DescribeExportTasks(params)
  259. if err != nil {
  260. // Print the error, cast err to awserr.Error to get the Code and
  261. // Message from an error.
  262. fmt.Println(err.Error())
  263. return
  264. }
  265. // Pretty-print the response data.
  266. fmt.Println(resp)
  267. }
  268. func ExampleCloudWatchLogs_DescribeLogGroups() {
  269. sess, err := session.NewSession()
  270. if err != nil {
  271. fmt.Println("failed to create session,", err)
  272. return
  273. }
  274. svc := cloudwatchlogs.New(sess)
  275. params := &cloudwatchlogs.DescribeLogGroupsInput{
  276. Limit: aws.Int64(1),
  277. LogGroupNamePrefix: aws.String("LogGroupName"),
  278. NextToken: aws.String("NextToken"),
  279. }
  280. resp, err := svc.DescribeLogGroups(params)
  281. if err != nil {
  282. // Print the error, cast err to awserr.Error to get the Code and
  283. // Message from an error.
  284. fmt.Println(err.Error())
  285. return
  286. }
  287. // Pretty-print the response data.
  288. fmt.Println(resp)
  289. }
  290. func ExampleCloudWatchLogs_DescribeLogStreams() {
  291. sess, err := session.NewSession()
  292. if err != nil {
  293. fmt.Println("failed to create session,", err)
  294. return
  295. }
  296. svc := cloudwatchlogs.New(sess)
  297. params := &cloudwatchlogs.DescribeLogStreamsInput{
  298. LogGroupName: aws.String("LogGroupName"), // Required
  299. Descending: aws.Bool(true),
  300. Limit: aws.Int64(1),
  301. LogStreamNamePrefix: aws.String("LogStreamName"),
  302. NextToken: aws.String("NextToken"),
  303. OrderBy: aws.String("OrderBy"),
  304. }
  305. resp, err := svc.DescribeLogStreams(params)
  306. if err != nil {
  307. // Print the error, cast err to awserr.Error to get the Code and
  308. // Message from an error.
  309. fmt.Println(err.Error())
  310. return
  311. }
  312. // Pretty-print the response data.
  313. fmt.Println(resp)
  314. }
  315. func ExampleCloudWatchLogs_DescribeMetricFilters() {
  316. sess, err := session.NewSession()
  317. if err != nil {
  318. fmt.Println("failed to create session,", err)
  319. return
  320. }
  321. svc := cloudwatchlogs.New(sess)
  322. params := &cloudwatchlogs.DescribeMetricFiltersInput{
  323. LogGroupName: aws.String("LogGroupName"), // Required
  324. FilterNamePrefix: aws.String("FilterName"),
  325. Limit: aws.Int64(1),
  326. NextToken: aws.String("NextToken"),
  327. }
  328. resp, err := svc.DescribeMetricFilters(params)
  329. if err != nil {
  330. // Print the error, cast err to awserr.Error to get the Code and
  331. // Message from an error.
  332. fmt.Println(err.Error())
  333. return
  334. }
  335. // Pretty-print the response data.
  336. fmt.Println(resp)
  337. }
  338. func ExampleCloudWatchLogs_DescribeSubscriptionFilters() {
  339. sess, err := session.NewSession()
  340. if err != nil {
  341. fmt.Println("failed to create session,", err)
  342. return
  343. }
  344. svc := cloudwatchlogs.New(sess)
  345. params := &cloudwatchlogs.DescribeSubscriptionFiltersInput{
  346. LogGroupName: aws.String("LogGroupName"), // Required
  347. FilterNamePrefix: aws.String("FilterName"),
  348. Limit: aws.Int64(1),
  349. NextToken: aws.String("NextToken"),
  350. }
  351. resp, err := svc.DescribeSubscriptionFilters(params)
  352. if err != nil {
  353. // Print the error, cast err to awserr.Error to get the Code and
  354. // Message from an error.
  355. fmt.Println(err.Error())
  356. return
  357. }
  358. // Pretty-print the response data.
  359. fmt.Println(resp)
  360. }
  361. func ExampleCloudWatchLogs_FilterLogEvents() {
  362. sess, err := session.NewSession()
  363. if err != nil {
  364. fmt.Println("failed to create session,", err)
  365. return
  366. }
  367. svc := cloudwatchlogs.New(sess)
  368. params := &cloudwatchlogs.FilterLogEventsInput{
  369. LogGroupName: aws.String("LogGroupName"), // Required
  370. EndTime: aws.Int64(1),
  371. FilterPattern: aws.String("FilterPattern"),
  372. Interleaved: aws.Bool(true),
  373. Limit: aws.Int64(1),
  374. LogStreamNames: []*string{
  375. aws.String("LogStreamName"), // Required
  376. // More values...
  377. },
  378. NextToken: aws.String("NextToken"),
  379. StartTime: aws.Int64(1),
  380. }
  381. resp, err := svc.FilterLogEvents(params)
  382. if err != nil {
  383. // Print the error, cast err to awserr.Error to get the Code and
  384. // Message from an error.
  385. fmt.Println(err.Error())
  386. return
  387. }
  388. // Pretty-print the response data.
  389. fmt.Println(resp)
  390. }
  391. func ExampleCloudWatchLogs_GetLogEvents() {
  392. sess, err := session.NewSession()
  393. if err != nil {
  394. fmt.Println("failed to create session,", err)
  395. return
  396. }
  397. svc := cloudwatchlogs.New(sess)
  398. params := &cloudwatchlogs.GetLogEventsInput{
  399. LogGroupName: aws.String("LogGroupName"), // Required
  400. LogStreamName: aws.String("LogStreamName"), // Required
  401. EndTime: aws.Int64(1),
  402. Limit: aws.Int64(1),
  403. NextToken: aws.String("NextToken"),
  404. StartFromHead: aws.Bool(true),
  405. StartTime: aws.Int64(1),
  406. }
  407. resp, err := svc.GetLogEvents(params)
  408. if err != nil {
  409. // Print the error, cast err to awserr.Error to get the Code and
  410. // Message from an error.
  411. fmt.Println(err.Error())
  412. return
  413. }
  414. // Pretty-print the response data.
  415. fmt.Println(resp)
  416. }
  417. func ExampleCloudWatchLogs_PutDestination() {
  418. sess, err := session.NewSession()
  419. if err != nil {
  420. fmt.Println("failed to create session,", err)
  421. return
  422. }
  423. svc := cloudwatchlogs.New(sess)
  424. params := &cloudwatchlogs.PutDestinationInput{
  425. DestinationName: aws.String("DestinationName"), // Required
  426. RoleArn: aws.String("RoleArn"), // Required
  427. TargetArn: aws.String("TargetArn"), // Required
  428. }
  429. resp, err := svc.PutDestination(params)
  430. if err != nil {
  431. // Print the error, cast err to awserr.Error to get the Code and
  432. // Message from an error.
  433. fmt.Println(err.Error())
  434. return
  435. }
  436. // Pretty-print the response data.
  437. fmt.Println(resp)
  438. }
  439. func ExampleCloudWatchLogs_PutDestinationPolicy() {
  440. sess, err := session.NewSession()
  441. if err != nil {
  442. fmt.Println("failed to create session,", err)
  443. return
  444. }
  445. svc := cloudwatchlogs.New(sess)
  446. params := &cloudwatchlogs.PutDestinationPolicyInput{
  447. AccessPolicy: aws.String("AccessPolicy"), // Required
  448. DestinationName: aws.String("DestinationName"), // Required
  449. }
  450. resp, err := svc.PutDestinationPolicy(params)
  451. if err != nil {
  452. // Print the error, cast err to awserr.Error to get the Code and
  453. // Message from an error.
  454. fmt.Println(err.Error())
  455. return
  456. }
  457. // Pretty-print the response data.
  458. fmt.Println(resp)
  459. }
  460. func ExampleCloudWatchLogs_PutLogEvents() {
  461. sess, err := session.NewSession()
  462. if err != nil {
  463. fmt.Println("failed to create session,", err)
  464. return
  465. }
  466. svc := cloudwatchlogs.New(sess)
  467. params := &cloudwatchlogs.PutLogEventsInput{
  468. LogEvents: []*cloudwatchlogs.InputLogEvent{ // Required
  469. { // Required
  470. Message: aws.String("EventMessage"), // Required
  471. Timestamp: aws.Int64(1), // Required
  472. },
  473. // More values...
  474. },
  475. LogGroupName: aws.String("LogGroupName"), // Required
  476. LogStreamName: aws.String("LogStreamName"), // Required
  477. SequenceToken: aws.String("SequenceToken"),
  478. }
  479. resp, err := svc.PutLogEvents(params)
  480. if err != nil {
  481. // Print the error, cast err to awserr.Error to get the Code and
  482. // Message from an error.
  483. fmt.Println(err.Error())
  484. return
  485. }
  486. // Pretty-print the response data.
  487. fmt.Println(resp)
  488. }
  489. func ExampleCloudWatchLogs_PutMetricFilter() {
  490. sess, err := session.NewSession()
  491. if err != nil {
  492. fmt.Println("failed to create session,", err)
  493. return
  494. }
  495. svc := cloudwatchlogs.New(sess)
  496. params := &cloudwatchlogs.PutMetricFilterInput{
  497. FilterName: aws.String("FilterName"), // Required
  498. FilterPattern: aws.String("FilterPattern"), // Required
  499. LogGroupName: aws.String("LogGroupName"), // Required
  500. MetricTransformations: []*cloudwatchlogs.MetricTransformation{ // Required
  501. { // Required
  502. MetricName: aws.String("MetricName"), // Required
  503. MetricNamespace: aws.String("MetricNamespace"), // Required
  504. MetricValue: aws.String("MetricValue"), // Required
  505. DefaultValue: aws.Float64(1.0),
  506. },
  507. // More values...
  508. },
  509. }
  510. resp, err := svc.PutMetricFilter(params)
  511. if err != nil {
  512. // Print the error, cast err to awserr.Error to get the Code and
  513. // Message from an error.
  514. fmt.Println(err.Error())
  515. return
  516. }
  517. // Pretty-print the response data.
  518. fmt.Println(resp)
  519. }
  520. func ExampleCloudWatchLogs_PutRetentionPolicy() {
  521. sess, err := session.NewSession()
  522. if err != nil {
  523. fmt.Println("failed to create session,", err)
  524. return
  525. }
  526. svc := cloudwatchlogs.New(sess)
  527. params := &cloudwatchlogs.PutRetentionPolicyInput{
  528. LogGroupName: aws.String("LogGroupName"), // Required
  529. RetentionInDays: aws.Int64(1), // Required
  530. }
  531. resp, err := svc.PutRetentionPolicy(params)
  532. if err != nil {
  533. // Print the error, cast err to awserr.Error to get the Code and
  534. // Message from an error.
  535. fmt.Println(err.Error())
  536. return
  537. }
  538. // Pretty-print the response data.
  539. fmt.Println(resp)
  540. }
  541. func ExampleCloudWatchLogs_PutSubscriptionFilter() {
  542. sess, err := session.NewSession()
  543. if err != nil {
  544. fmt.Println("failed to create session,", err)
  545. return
  546. }
  547. svc := cloudwatchlogs.New(sess)
  548. params := &cloudwatchlogs.PutSubscriptionFilterInput{
  549. DestinationArn: aws.String("DestinationArn"), // Required
  550. FilterName: aws.String("FilterName"), // Required
  551. FilterPattern: aws.String("FilterPattern"), // Required
  552. LogGroupName: aws.String("LogGroupName"), // Required
  553. RoleArn: aws.String("RoleArn"),
  554. }
  555. resp, err := svc.PutSubscriptionFilter(params)
  556. if err != nil {
  557. // Print the error, cast err to awserr.Error to get the Code and
  558. // Message from an error.
  559. fmt.Println(err.Error())
  560. return
  561. }
  562. // Pretty-print the response data.
  563. fmt.Println(resp)
  564. }
  565. func ExampleCloudWatchLogs_TestMetricFilter() {
  566. sess, err := session.NewSession()
  567. if err != nil {
  568. fmt.Println("failed to create session,", err)
  569. return
  570. }
  571. svc := cloudwatchlogs.New(sess)
  572. params := &cloudwatchlogs.TestMetricFilterInput{
  573. FilterPattern: aws.String("FilterPattern"), // Required
  574. LogEventMessages: []*string{ // Required
  575. aws.String("EventMessage"), // Required
  576. // More values...
  577. },
  578. }
  579. resp, err := svc.TestMetricFilter(params)
  580. if err != nil {
  581. // Print the error, cast err to awserr.Error to get the Code and
  582. // Message from an error.
  583. fmt.Println(err.Error())
  584. return
  585. }
  586. // Pretty-print the response data.
  587. fmt.Println(resp)
  588. }