examples_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package lambda_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/lambda"
  10. )
  11. var _ time.Duration
  12. var _ bytes.Buffer
  13. func ExampleLambda_AddPermission() {
  14. sess, err := session.NewSession()
  15. if err != nil {
  16. fmt.Println("failed to create session,", err)
  17. return
  18. }
  19. svc := lambda.New(sess)
  20. params := &lambda.AddPermissionInput{
  21. Action: aws.String("Action"), // Required
  22. FunctionName: aws.String("FunctionName"), // Required
  23. Principal: aws.String("Principal"), // Required
  24. StatementId: aws.String("StatementId"), // Required
  25. EventSourceToken: aws.String("EventSourceToken"),
  26. Qualifier: aws.String("Qualifier"),
  27. SourceAccount: aws.String("SourceOwner"),
  28. SourceArn: aws.String("Arn"),
  29. }
  30. resp, err := svc.AddPermission(params)
  31. if err != nil {
  32. // Print the error, cast err to awserr.Error to get the Code and
  33. // Message from an error.
  34. fmt.Println(err.Error())
  35. return
  36. }
  37. // Pretty-print the response data.
  38. fmt.Println(resp)
  39. }
  40. func ExampleLambda_CreateAlias() {
  41. sess, err := session.NewSession()
  42. if err != nil {
  43. fmt.Println("failed to create session,", err)
  44. return
  45. }
  46. svc := lambda.New(sess)
  47. params := &lambda.CreateAliasInput{
  48. FunctionName: aws.String("FunctionName"), // Required
  49. FunctionVersion: aws.String("Version"), // Required
  50. Name: aws.String("Alias"), // Required
  51. Description: aws.String("Description"),
  52. }
  53. resp, err := svc.CreateAlias(params)
  54. if err != nil {
  55. // Print the error, cast err to awserr.Error to get the Code and
  56. // Message from an error.
  57. fmt.Println(err.Error())
  58. return
  59. }
  60. // Pretty-print the response data.
  61. fmt.Println(resp)
  62. }
  63. func ExampleLambda_CreateEventSourceMapping() {
  64. sess, err := session.NewSession()
  65. if err != nil {
  66. fmt.Println("failed to create session,", err)
  67. return
  68. }
  69. svc := lambda.New(sess)
  70. params := &lambda.CreateEventSourceMappingInput{
  71. EventSourceArn: aws.String("Arn"), // Required
  72. FunctionName: aws.String("FunctionName"), // Required
  73. StartingPosition: aws.String("EventSourcePosition"), // Required
  74. BatchSize: aws.Int64(1),
  75. Enabled: aws.Bool(true),
  76. }
  77. resp, err := svc.CreateEventSourceMapping(params)
  78. if err != nil {
  79. // Print the error, cast err to awserr.Error to get the Code and
  80. // Message from an error.
  81. fmt.Println(err.Error())
  82. return
  83. }
  84. // Pretty-print the response data.
  85. fmt.Println(resp)
  86. }
  87. func ExampleLambda_CreateFunction() {
  88. sess, err := session.NewSession()
  89. if err != nil {
  90. fmt.Println("failed to create session,", err)
  91. return
  92. }
  93. svc := lambda.New(sess)
  94. params := &lambda.CreateFunctionInput{
  95. Code: &lambda.FunctionCode{ // Required
  96. S3Bucket: aws.String("S3Bucket"),
  97. S3Key: aws.String("S3Key"),
  98. S3ObjectVersion: aws.String("S3ObjectVersion"),
  99. ZipFile: []byte("PAYLOAD"),
  100. },
  101. FunctionName: aws.String("FunctionName"), // Required
  102. Handler: aws.String("Handler"), // Required
  103. Role: aws.String("RoleArn"), // Required
  104. Runtime: aws.String("Runtime"), // Required
  105. Description: aws.String("Description"),
  106. MemorySize: aws.Int64(1),
  107. Publish: aws.Bool(true),
  108. Timeout: aws.Int64(1),
  109. VpcConfig: &lambda.VpcConfig{
  110. SecurityGroupIds: []*string{
  111. aws.String("SecurityGroupId"), // Required
  112. // More values...
  113. },
  114. SubnetIds: []*string{
  115. aws.String("SubnetId"), // Required
  116. // More values...
  117. },
  118. },
  119. }
  120. resp, err := svc.CreateFunction(params)
  121. if err != nil {
  122. // Print the error, cast err to awserr.Error to get the Code and
  123. // Message from an error.
  124. fmt.Println(err.Error())
  125. return
  126. }
  127. // Pretty-print the response data.
  128. fmt.Println(resp)
  129. }
  130. func ExampleLambda_DeleteAlias() {
  131. sess, err := session.NewSession()
  132. if err != nil {
  133. fmt.Println("failed to create session,", err)
  134. return
  135. }
  136. svc := lambda.New(sess)
  137. params := &lambda.DeleteAliasInput{
  138. FunctionName: aws.String("FunctionName"), // Required
  139. Name: aws.String("Alias"), // Required
  140. }
  141. resp, err := svc.DeleteAlias(params)
  142. if err != nil {
  143. // Print the error, cast err to awserr.Error to get the Code and
  144. // Message from an error.
  145. fmt.Println(err.Error())
  146. return
  147. }
  148. // Pretty-print the response data.
  149. fmt.Println(resp)
  150. }
  151. func ExampleLambda_DeleteEventSourceMapping() {
  152. sess, err := session.NewSession()
  153. if err != nil {
  154. fmt.Println("failed to create session,", err)
  155. return
  156. }
  157. svc := lambda.New(sess)
  158. params := &lambda.DeleteEventSourceMappingInput{
  159. UUID: aws.String("String"), // Required
  160. }
  161. resp, err := svc.DeleteEventSourceMapping(params)
  162. if err != nil {
  163. // Print the error, cast err to awserr.Error to get the Code and
  164. // Message from an error.
  165. fmt.Println(err.Error())
  166. return
  167. }
  168. // Pretty-print the response data.
  169. fmt.Println(resp)
  170. }
  171. func ExampleLambda_DeleteFunction() {
  172. sess, err := session.NewSession()
  173. if err != nil {
  174. fmt.Println("failed to create session,", err)
  175. return
  176. }
  177. svc := lambda.New(sess)
  178. params := &lambda.DeleteFunctionInput{
  179. FunctionName: aws.String("FunctionName"), // Required
  180. Qualifier: aws.String("Qualifier"),
  181. }
  182. resp, err := svc.DeleteFunction(params)
  183. if err != nil {
  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. return
  188. }
  189. // Pretty-print the response data.
  190. fmt.Println(resp)
  191. }
  192. func ExampleLambda_GetAlias() {
  193. sess, err := session.NewSession()
  194. if err != nil {
  195. fmt.Println("failed to create session,", err)
  196. return
  197. }
  198. svc := lambda.New(sess)
  199. params := &lambda.GetAliasInput{
  200. FunctionName: aws.String("FunctionName"), // Required
  201. Name: aws.String("Alias"), // Required
  202. }
  203. resp, err := svc.GetAlias(params)
  204. if err != nil {
  205. // Print the error, cast err to awserr.Error to get the Code and
  206. // Message from an error.
  207. fmt.Println(err.Error())
  208. return
  209. }
  210. // Pretty-print the response data.
  211. fmt.Println(resp)
  212. }
  213. func ExampleLambda_GetEventSourceMapping() {
  214. sess, err := session.NewSession()
  215. if err != nil {
  216. fmt.Println("failed to create session,", err)
  217. return
  218. }
  219. svc := lambda.New(sess)
  220. params := &lambda.GetEventSourceMappingInput{
  221. UUID: aws.String("String"), // Required
  222. }
  223. resp, err := svc.GetEventSourceMapping(params)
  224. if err != nil {
  225. // Print the error, cast err to awserr.Error to get the Code and
  226. // Message from an error.
  227. fmt.Println(err.Error())
  228. return
  229. }
  230. // Pretty-print the response data.
  231. fmt.Println(resp)
  232. }
  233. func ExampleLambda_GetFunction() {
  234. sess, err := session.NewSession()
  235. if err != nil {
  236. fmt.Println("failed to create session,", err)
  237. return
  238. }
  239. svc := lambda.New(sess)
  240. params := &lambda.GetFunctionInput{
  241. FunctionName: aws.String("FunctionName"), // Required
  242. Qualifier: aws.String("Qualifier"),
  243. }
  244. resp, err := svc.GetFunction(params)
  245. if err != nil {
  246. // Print the error, cast err to awserr.Error to get the Code and
  247. // Message from an error.
  248. fmt.Println(err.Error())
  249. return
  250. }
  251. // Pretty-print the response data.
  252. fmt.Println(resp)
  253. }
  254. func ExampleLambda_GetFunctionConfiguration() {
  255. sess, err := session.NewSession()
  256. if err != nil {
  257. fmt.Println("failed to create session,", err)
  258. return
  259. }
  260. svc := lambda.New(sess)
  261. params := &lambda.GetFunctionConfigurationInput{
  262. FunctionName: aws.String("FunctionName"), // Required
  263. Qualifier: aws.String("Qualifier"),
  264. }
  265. resp, err := svc.GetFunctionConfiguration(params)
  266. if err != nil {
  267. // Print the error, cast err to awserr.Error to get the Code and
  268. // Message from an error.
  269. fmt.Println(err.Error())
  270. return
  271. }
  272. // Pretty-print the response data.
  273. fmt.Println(resp)
  274. }
  275. func ExampleLambda_GetPolicy() {
  276. sess, err := session.NewSession()
  277. if err != nil {
  278. fmt.Println("failed to create session,", err)
  279. return
  280. }
  281. svc := lambda.New(sess)
  282. params := &lambda.GetPolicyInput{
  283. FunctionName: aws.String("FunctionName"), // Required
  284. Qualifier: aws.String("Qualifier"),
  285. }
  286. resp, err := svc.GetPolicy(params)
  287. if err != nil {
  288. // Print the error, cast err to awserr.Error to get the Code and
  289. // Message from an error.
  290. fmt.Println(err.Error())
  291. return
  292. }
  293. // Pretty-print the response data.
  294. fmt.Println(resp)
  295. }
  296. func ExampleLambda_Invoke() {
  297. sess, err := session.NewSession()
  298. if err != nil {
  299. fmt.Println("failed to create session,", err)
  300. return
  301. }
  302. svc := lambda.New(sess)
  303. params := &lambda.InvokeInput{
  304. FunctionName: aws.String("FunctionName"), // Required
  305. ClientContext: aws.String("String"),
  306. InvocationType: aws.String("InvocationType"),
  307. LogType: aws.String("LogType"),
  308. Payload: []byte("PAYLOAD"),
  309. Qualifier: aws.String("Qualifier"),
  310. }
  311. resp, err := svc.Invoke(params)
  312. if err != nil {
  313. // Print the error, cast err to awserr.Error to get the Code and
  314. // Message from an error.
  315. fmt.Println(err.Error())
  316. return
  317. }
  318. // Pretty-print the response data.
  319. fmt.Println(resp)
  320. }
  321. func ExampleLambda_InvokeAsync() {
  322. sess, err := session.NewSession()
  323. if err != nil {
  324. fmt.Println("failed to create session,", err)
  325. return
  326. }
  327. svc := lambda.New(sess)
  328. params := &lambda.InvokeAsyncInput{
  329. FunctionName: aws.String("FunctionName"), // Required
  330. InvokeArgs: bytes.NewReader([]byte("PAYLOAD")), // Required
  331. }
  332. resp, err := svc.InvokeAsync(params)
  333. if err != nil {
  334. // Print the error, cast err to awserr.Error to get the Code and
  335. // Message from an error.
  336. fmt.Println(err.Error())
  337. return
  338. }
  339. // Pretty-print the response data.
  340. fmt.Println(resp)
  341. }
  342. func ExampleLambda_ListAliases() {
  343. sess, err := session.NewSession()
  344. if err != nil {
  345. fmt.Println("failed to create session,", err)
  346. return
  347. }
  348. svc := lambda.New(sess)
  349. params := &lambda.ListAliasesInput{
  350. FunctionName: aws.String("FunctionName"), // Required
  351. FunctionVersion: aws.String("Version"),
  352. Marker: aws.String("String"),
  353. MaxItems: aws.Int64(1),
  354. }
  355. resp, err := svc.ListAliases(params)
  356. if err != nil {
  357. // Print the error, cast err to awserr.Error to get the Code and
  358. // Message from an error.
  359. fmt.Println(err.Error())
  360. return
  361. }
  362. // Pretty-print the response data.
  363. fmt.Println(resp)
  364. }
  365. func ExampleLambda_ListEventSourceMappings() {
  366. sess, err := session.NewSession()
  367. if err != nil {
  368. fmt.Println("failed to create session,", err)
  369. return
  370. }
  371. svc := lambda.New(sess)
  372. params := &lambda.ListEventSourceMappingsInput{
  373. EventSourceArn: aws.String("Arn"),
  374. FunctionName: aws.String("FunctionName"),
  375. Marker: aws.String("String"),
  376. MaxItems: aws.Int64(1),
  377. }
  378. resp, err := svc.ListEventSourceMappings(params)
  379. if err != nil {
  380. // Print the error, cast err to awserr.Error to get the Code and
  381. // Message from an error.
  382. fmt.Println(err.Error())
  383. return
  384. }
  385. // Pretty-print the response data.
  386. fmt.Println(resp)
  387. }
  388. func ExampleLambda_ListFunctions() {
  389. sess, err := session.NewSession()
  390. if err != nil {
  391. fmt.Println("failed to create session,", err)
  392. return
  393. }
  394. svc := lambda.New(sess)
  395. params := &lambda.ListFunctionsInput{
  396. Marker: aws.String("String"),
  397. MaxItems: aws.Int64(1),
  398. }
  399. resp, err := svc.ListFunctions(params)
  400. if err != nil {
  401. // Print the error, cast err to awserr.Error to get the Code and
  402. // Message from an error.
  403. fmt.Println(err.Error())
  404. return
  405. }
  406. // Pretty-print the response data.
  407. fmt.Println(resp)
  408. }
  409. func ExampleLambda_ListVersionsByFunction() {
  410. sess, err := session.NewSession()
  411. if err != nil {
  412. fmt.Println("failed to create session,", err)
  413. return
  414. }
  415. svc := lambda.New(sess)
  416. params := &lambda.ListVersionsByFunctionInput{
  417. FunctionName: aws.String("FunctionName"), // Required
  418. Marker: aws.String("String"),
  419. MaxItems: aws.Int64(1),
  420. }
  421. resp, err := svc.ListVersionsByFunction(params)
  422. if err != nil {
  423. // Print the error, cast err to awserr.Error to get the Code and
  424. // Message from an error.
  425. fmt.Println(err.Error())
  426. return
  427. }
  428. // Pretty-print the response data.
  429. fmt.Println(resp)
  430. }
  431. func ExampleLambda_PublishVersion() {
  432. sess, err := session.NewSession()
  433. if err != nil {
  434. fmt.Println("failed to create session,", err)
  435. return
  436. }
  437. svc := lambda.New(sess)
  438. params := &lambda.PublishVersionInput{
  439. FunctionName: aws.String("FunctionName"), // Required
  440. CodeSha256: aws.String("String"),
  441. Description: aws.String("Description"),
  442. }
  443. resp, err := svc.PublishVersion(params)
  444. if err != nil {
  445. // Print the error, cast err to awserr.Error to get the Code and
  446. // Message from an error.
  447. fmt.Println(err.Error())
  448. return
  449. }
  450. // Pretty-print the response data.
  451. fmt.Println(resp)
  452. }
  453. func ExampleLambda_RemovePermission() {
  454. sess, err := session.NewSession()
  455. if err != nil {
  456. fmt.Println("failed to create session,", err)
  457. return
  458. }
  459. svc := lambda.New(sess)
  460. params := &lambda.RemovePermissionInput{
  461. FunctionName: aws.String("FunctionName"), // Required
  462. StatementId: aws.String("StatementId"), // Required
  463. Qualifier: aws.String("Qualifier"),
  464. }
  465. resp, err := svc.RemovePermission(params)
  466. if err != nil {
  467. // Print the error, cast err to awserr.Error to get the Code and
  468. // Message from an error.
  469. fmt.Println(err.Error())
  470. return
  471. }
  472. // Pretty-print the response data.
  473. fmt.Println(resp)
  474. }
  475. func ExampleLambda_UpdateAlias() {
  476. sess, err := session.NewSession()
  477. if err != nil {
  478. fmt.Println("failed to create session,", err)
  479. return
  480. }
  481. svc := lambda.New(sess)
  482. params := &lambda.UpdateAliasInput{
  483. FunctionName: aws.String("FunctionName"), // Required
  484. Name: aws.String("Alias"), // Required
  485. Description: aws.String("Description"),
  486. FunctionVersion: aws.String("Version"),
  487. }
  488. resp, err := svc.UpdateAlias(params)
  489. if err != nil {
  490. // Print the error, cast err to awserr.Error to get the Code and
  491. // Message from an error.
  492. fmt.Println(err.Error())
  493. return
  494. }
  495. // Pretty-print the response data.
  496. fmt.Println(resp)
  497. }
  498. func ExampleLambda_UpdateEventSourceMapping() {
  499. sess, err := session.NewSession()
  500. if err != nil {
  501. fmt.Println("failed to create session,", err)
  502. return
  503. }
  504. svc := lambda.New(sess)
  505. params := &lambda.UpdateEventSourceMappingInput{
  506. UUID: aws.String("String"), // Required
  507. BatchSize: aws.Int64(1),
  508. Enabled: aws.Bool(true),
  509. FunctionName: aws.String("FunctionName"),
  510. }
  511. resp, err := svc.UpdateEventSourceMapping(params)
  512. if err != nil {
  513. // Print the error, cast err to awserr.Error to get the Code and
  514. // Message from an error.
  515. fmt.Println(err.Error())
  516. return
  517. }
  518. // Pretty-print the response data.
  519. fmt.Println(resp)
  520. }
  521. func ExampleLambda_UpdateFunctionCode() {
  522. sess, err := session.NewSession()
  523. if err != nil {
  524. fmt.Println("failed to create session,", err)
  525. return
  526. }
  527. svc := lambda.New(sess)
  528. params := &lambda.UpdateFunctionCodeInput{
  529. FunctionName: aws.String("FunctionName"), // Required
  530. Publish: aws.Bool(true),
  531. S3Bucket: aws.String("S3Bucket"),
  532. S3Key: aws.String("S3Key"),
  533. S3ObjectVersion: aws.String("S3ObjectVersion"),
  534. ZipFile: []byte("PAYLOAD"),
  535. }
  536. resp, err := svc.UpdateFunctionCode(params)
  537. if err != nil {
  538. // Print the error, cast err to awserr.Error to get the Code and
  539. // Message from an error.
  540. fmt.Println(err.Error())
  541. return
  542. }
  543. // Pretty-print the response data.
  544. fmt.Println(resp)
  545. }
  546. func ExampleLambda_UpdateFunctionConfiguration() {
  547. sess, err := session.NewSession()
  548. if err != nil {
  549. fmt.Println("failed to create session,", err)
  550. return
  551. }
  552. svc := lambda.New(sess)
  553. params := &lambda.UpdateFunctionConfigurationInput{
  554. FunctionName: aws.String("FunctionName"), // Required
  555. Description: aws.String("Description"),
  556. Handler: aws.String("Handler"),
  557. MemorySize: aws.Int64(1),
  558. Role: aws.String("RoleArn"),
  559. Runtime: aws.String("Runtime"),
  560. Timeout: aws.Int64(1),
  561. VpcConfig: &lambda.VpcConfig{
  562. SecurityGroupIds: []*string{
  563. aws.String("SecurityGroupId"), // Required
  564. // More values...
  565. },
  566. SubnetIds: []*string{
  567. aws.String("SubnetId"), // Required
  568. // More values...
  569. },
  570. },
  571. }
  572. resp, err := svc.UpdateFunctionConfiguration(params)
  573. if err != nil {
  574. // Print the error, cast err to awserr.Error to get the Code and
  575. // Message from an error.
  576. fmt.Println(err.Error())
  577. return
  578. }
  579. // Pretty-print the response data.
  580. fmt.Println(resp)
  581. }