forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
988 lines (695 loc) · 35.8 KB
/
Copy pathindex.html
File metadata and controls
988 lines (695 loc) · 35.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="AWS Lambda Powertools Python">
<link rel="shortcut icon" href="media/aws-logo-light.svg">
<meta name="generator" content="mkdocs-1.1.2, mkdocs-material-6.2.7">
<title>Homepage - AWS Lambda Powertools Python</title>
<link rel="stylesheet" href="assets/stylesheets/main.cb6bc1d0.min.css">
<link rel="stylesheet" href="assets/stylesheets/palette.39b8e14a.min.css">
<meta name="theme-color" content="#7e56c2">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
<style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono",SFMono-Regular,Consolas,Menlo,monospace}</style>
<link rel="stylesheet" href="stylesheets/extra.css">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="awscloud">
<meta name="twitter:title" content="AWS Lambda Powertools Python - Homepage">
<meta name="twitter:description" content="None">
<meta name="twitter:image" content="./assets/images/powertools_docs_thumbnail.png">
<meta name="twitter:image:alt" content="AWS Lambda Powertools Python">
<meta property="og:type" content="website">
<meta property="og:title" content="AWS Lambda Powertools Python - Homepage">
<meta property="og:site_name" content="AWS Lambda Powertools Python">
<meta property="og:description" content="None">
<meta property="og:url" content="https://am29d.github.io/aws-lambda-powertools-python/">
<meta property="og:image" content="./assets/images/powertools_docs_thumbnail.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
</head>
<body dir="ltr" data-md-color-scheme="" data-md-color-primary="deep-purple" data-md-color-accent="">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#install" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid" aria-label="Header">
<a href="." title="AWS Lambda Powertools Python" class="md-header-nav__button md-logo" aria-label="AWS Lambda Powertools Python">
<img src="media/aws-logo-light.svg" alt="logo">
</a>
<label class="md-header-nav__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
</label>
<div class="md-header-nav__title" data-md-component="header-title">
<div class="md-header-nav__ellipsis">
<div class="md-header-nav__topic">
<span class="md-ellipsis">
AWS Lambda Powertools Python
</span>
</div>
<div class="md-header-nav__topic">
<span class="md-ellipsis">
Homepage
</span>
</div>
</div>
</div>
<div class="md-header-nav__source">
<a href="https://github.com/awslabs/aws-lambda-powertools-python/" title="Go to repository" class="md-source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="." title="AWS Lambda Powertools Python" class="md-nav__button md-logo" aria-label="AWS Lambda Powertools Python">
<img src="media/aws-logo-light.svg" alt="logo">
</a>
AWS Lambda Powertools Python
</label>
<div class="md-nav__source">
<a href="https://github.com/awslabs/aws-lambda-powertools-python/" title="Go to repository" class="md-source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Homepage
<span class="md-nav__icon md-icon"></span>
</label>
<a href="." class="md-nav__link md-nav__link--active">
Homepage
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#install" class="md-nav__link">
Install
</a>
<nav class="md-nav" aria-label="Install">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#lambda-layer" class="md-nav__link">
Lambda Layer
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#features" class="md-nav__link">
Features
</a>
</li>
<li class="md-nav__item">
<a href="#environment-variables" class="md-nav__link">
Environment variables
</a>
</li>
<li class="md-nav__item">
<a href="#debug-mode" class="md-nav__link">
Debug mode
</a>
</li>
<li class="md-nav__item">
<a href="#tenets" class="md-nav__link">
Tenets
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="changelog/" class="md-nav__link">
Changelog
</a>
</li>
<li class="md-nav__item md-nav__item--section md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="nav-3" data-md-state="indeterminate" type="checkbox" id="nav-3" checked>
<label class="md-nav__link" for="nav-3">
Core utilities
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Core utilities" data-md-level="1">
<label class="md-nav__title" for="nav-3">
<span class="md-nav__icon md-icon"></span>
Core utilities
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="core/tracer/" class="md-nav__link">
Tracer
</a>
</li>
<li class="md-nav__item">
<a href="core/logger/" class="md-nav__link">
Logger
</a>
</li>
<li class="md-nav__item">
<a href="core/metrics/" class="md-nav__link">
Metrics
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--section md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="nav-4" data-md-state="indeterminate" type="checkbox" id="nav-4" checked>
<label class="md-nav__link" for="nav-4">
Utilities
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Utilities" data-md-level="1">
<label class="md-nav__title" for="nav-4">
<span class="md-nav__icon md-icon"></span>
Utilities
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="utilities/middleware_factory/" class="md-nav__link">
Middleware factory
</a>
</li>
<li class="md-nav__item">
<a href="utilities/parameters/" class="md-nav__link">
Parameters
</a>
</li>
<li class="md-nav__item">
<a href="utilities/batch/" class="md-nav__link">
SQS Batch Processing
</a>
</li>
<li class="md-nav__item">
<a href="utilities/typing/" class="md-nav__link">
Typing
</a>
</li>
<li class="md-nav__item">
<a href="utilities/validation/" class="md-nav__link">
Validation
</a>
</li>
<li class="md-nav__item">
<a href="utilities/data_classes/" class="md-nav__link">
Event Source Data Classes
</a>
</li>
<li class="md-nav__item">
<a href="utilities/parser/" class="md-nav__link">
Parser
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#install" class="md-nav__link">
Install
</a>
<nav class="md-nav" aria-label="Install">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#lambda-layer" class="md-nav__link">
Lambda Layer
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#features" class="md-nav__link">
Features
</a>
</li>
<li class="md-nav__item">
<a href="#environment-variables" class="md-nav__link">
Environment variables
</a>
</li>
<li class="md-nav__item">
<a href="#debug-mode" class="md-nav__link">
Debug mode
</a>
</li>
<li class="md-nav__item">
<a href="#tenets" class="md-nav__link">
Tenets
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<a href="https://github.com/awslabs/aws-lambda-powertools-python/edit/master/docs/index.md" title="Edit this page" class="md-content__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z"/></svg>
</a>
<h1>Homepage</h1>
<p>A suite of utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more.</p>
<div class="admonition info">
<p><strong>Looking for a quick run through of the core utilities?</strong></p>
<p>Check out <a href="https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-lambda-powertools/">this detailed blog post</a> with a practical example.</p>
</div>
<h2 id="install">Install<a class="headerlink" href="#install" title="Permanent link">¶</a></h2>
<p>Powertools is available in PyPi. You can use your favourite dependency management tool to install it</p>
<ul>
<li><a href="https://python-poetry.org/">poetry</a>: <code>poetry add aws-lambda-powertools</code></li>
<li><a href="https://pip.pypa.io/en/latest/index.html">pip</a>: <code>pip install aws-lambda-powertools</code></li>
</ul>
<p><strong>Quick hello world example using SAM CLI</strong></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code>sam init --location https://github.com/aws-samples/cookiecutter-aws-sam-python
</code></pre></div>
</td></tr></table>
<h3 id="lambda-layer">Lambda Layer<a class="headerlink" href="#lambda-layer" title="Permanent link">¶</a></h3>
<p>Powertools is also available as a Lambda Layer, and it is distributed via the <a href="https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html">AWS Serverless Application Repository (SAR)</a> to support semantic versioning.</p>
<table>
<thead>
<tr>
<th>App</th>
<th>ARN</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://serverlessrepo.aws.amazon.com/applications/eu-west-1/057560766410/aws-lambda-powertools-python-layer">aws-lambda-powertools-python-layer</a></td>
<td>arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer</td>
<td>Core dependencies only; sufficient for nearly all utilities.</td>
</tr>
<tr>
<td><a href="https://serverlessrepo.aws.amazon.com/applications/eu-west-1/057560766410/aws-lambda-powertools-python-layer-extras">aws-lambda-powertools-python-layer-extras</a></td>
<td>arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer-extras</td>
<td>Core plus extra dependencies such as <code>pydantic</code> that is required by <code>parser</code> utility.</td>
</tr>
</tbody>
</table>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><strong>Layer-extras</strong> does not support Python 3.6 runtime. This layer also includes all extra dependencies: <code>22.4MB zipped</code>, <code>~155MB unzipped</code>.</p>
</div>
<p>If using SAM, you can include this SAR App as part of your shared Layers stack, and lock to a specific semantic version. Once deployed, it'll be available across the account this is deployed to.</p>
<div class="tabbed-set" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><label for="__tabbed_1_1">template.yml</label><div class="tabbed-content"></div>
</div>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span> 1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nt">AwsLambdaPowertoolsPythonLayer</span><span class="p">:</span>
<span class="nt">Type</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">AWS::Serverless::Application</span>
<span class="nt">Properties</span><span class="p">:</span>
<span class="nt">Location</span><span class="p">:</span>
<span class="hll"> <span class="nt">ApplicationId</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer</span>
</span><span class="hll"> <span class="nt">SemanticVersion</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">1.10.2</span> <span class="c1"># change to latest semantic version available in SAR</span>
</span>
<span class="nt">MyLambdaFunction</span><span class="p">:</span>
<span class="nt">Type</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">AWS::Serverless::Function</span>
<span class="nt">Properties</span><span class="p">:</span>
<span class="nt">Location</span><span class="p">:</span>
<span class="hll"> <span class="nt">Layers</span><span class="p">:</span>
</span><span class="hll"> <span class="c1"># fetch Layer ARN from SAR App stack output</span>
</span><span class="hll"> <span class="p p-Indicator">-</span> <span class="kt">!GetAtt</span> <span class="l l-Scalar l-Scalar-Plain">AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn</span>
</span></code></pre></div>
</td></tr></table>
<details class="multiple optional-class"><summary>Example IAM permissions to deploy layer</summary><blockquote>
<p>Credits to <a href="https://github.com/mwarkentin">mwarkentin</a> for providing the scoped down IAM permissions.</p>
</blockquote>
<p>The region and the account id for <code>CloudFormationTransform</code> and <code>GetCfnTemplate</code> are fixed.</p>
<div class="tabbed-set" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><label for="__tabbed_2_1">template.yml</label><div class="tabbed-content">
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nt">AWSTemplateFormatVersion</span><span class="p">:</span> <span class="s">"2010-09-09"</span>
<span class="nt">Resources</span><span class="p">:</span>
<span class="nt">PowertoolsLayerIamRole</span><span class="p">:</span>
<span class="nt">Type</span><span class="p">:</span> <span class="s">"AWS::IAM::Role"</span>
<span class="nt">Properties</span><span class="p">:</span>
<span class="nt">AssumeRolePolicyDocument</span><span class="p">:</span>
<span class="nt">Version</span><span class="p">:</span> <span class="s">"2012-10-17"</span>
<span class="nt">Statement</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="nt">Effect</span><span class="p">:</span> <span class="s">"Allow"</span>
<span class="nt">Principal</span><span class="p">:</span>
<span class="nt">Service</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="s">"cloudformation.amazonaws.com"</span>
<span class="nt">Action</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="s">"sts:AssumeRole"</span>
<span class="nt">Path</span><span class="p">:</span> <span class="s">"/"</span>
<span class="nt">PowertoolsLayerIamPolicy</span><span class="p">:</span>
<span class="nt">Type</span><span class="p">:</span> <span class="s">"AWS::IAM::Policy"</span>
<span class="nt">Properties</span><span class="p">:</span>
<span class="nt">PolicyName</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">PowertoolsLambdaLayerPolicy</span>
<span class="nt">PolicyDocument</span><span class="p">:</span>
<span class="nt">Version</span><span class="p">:</span> <span class="s">"2012-10-17"</span>
<span class="nt">Statement</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="nt">Sid</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">CloudFormationTransform</span>
<span class="nt">Effect</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">Allow</span>
<span class="nt">Action</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">cloudformation:CreateChangeSet</span>
<span class="nt">Resource</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">arn:aws:cloudformation:us-east-1:aws:transform/Serverless-2016-10-31</span>
<span class="p p-Indicator">-</span> <span class="nt">Sid</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">GetCfnTemplate</span>
<span class="nt">Effect</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">Allow</span>
<span class="nt">Action</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">serverlessrepo:CreateCloudFormationTemplate</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">serverlessrepo:GetCloudFormationTemplate</span>
<span class="nt">Resource</span><span class="p">:</span>
<span class="c1"># this is arn of the powertools SAR app</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer</span>
<span class="p p-Indicator">-</span> <span class="nt">Sid</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">S3AccessLayer</span>
<span class="nt">Effect</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">Allow</span>
<span class="nt">Action</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">s3:GetObject</span>
<span class="nt">Resource</span><span class="p">:</span>
<span class="c1"># AWS publishes to an external S3 bucket locked down to your account ID</span>
<span class="c1"># The below example is us publishing lambda powertools</span>
<span class="c1"># Bucket: awsserverlessrepo-changesets-plntc6bfnfj</span>
<span class="c1"># Key: *****/arn:aws:serverlessrepo:eu-west-1:057560766410:applications-aws-lambda-powertools-python-layer-versions-1.10.2/aeeccf50-****-****-****-*********</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">arn:aws:s3:::awsserverlessrepo-changesets-*/*</span>
<span class="p p-Indicator">-</span> <span class="nt">Sid</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">GetLayerVersion</span>
<span class="nt">Effect</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">Allow</span>
<span class="nt">Action</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">lambda:PublishLayerVersion</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">lambda:GetLayerVersion</span>
<span class="nt">Resource</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="kt">!Sub</span> <span class="l l-Scalar l-Scalar-Plain">arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:aws-lambda-powertools-python-layer*</span>
<span class="nt">Roles</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="nt">Ref</span><span class="p">:</span> <span class="s">"PowertoolsLayerIamRole"</span>
</code></pre></div>
</td></tr></table>
</div>
</div>
</details>
<p>You can fetch available versions via SAR API with:</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span>1
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code>aws serverlessrepo list-application-versions <span class="se">\</span>
--application-id arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
</code></pre></div>
</td></tr></table>
<h2 id="features">Features<a class="headerlink" href="#features" title="Permanent link">¶</a></h2>
<table>
<thead>
<tr>
<th>Utility</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="./core/tracer">Tracing</a></td>
<td>Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions</td>
</tr>
<tr>
<td><a href="./core/logger">Logging</a></td>
<td>Structured logging made easier, and decorator to enrich structured logging with key Lambda context details</td>
</tr>
<tr>
<td><a href="./core/metrics">Metrics</a></td>
<td>Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)</td>
</tr>
<tr>
<td><a href=".//utilities/middleware_factory">Bring your own middleware</a></td>
<td>Decorator factory to create your own middleware to run logic before, and after each Lambda invocation</td>
</tr>
<tr>
<td><a href="./utilities/parameters">Parameters</a></td>
<td>Retrieve parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, or Amazon DynamoDB, and cache them for a specific amount of time</td>
</tr>
<tr>
<td><a href="./utilities/typing">Typing</a></td>
<td>Static typing classes to speedup development in your IDE</td>
</tr>
<tr>
<td><a href="./utilities/batch">Batch</a></td>
<td>Handle partial failures for AWS SQS batch processing</td>
</tr>
<tr>
<td><a href="./utilities/validation">Validation</a></td>
<td>JSON Schema validator for inbound events and responses</td>
</tr>
<tr>
<td><a href="./utilities/data_classes">Event source data classes</a></td>
<td>Data classes describing the schema of common Lambda event triggers</td>
</tr>
</tbody>
</table>
<h2 id="environment-variables">Environment variables<a class="headerlink" href="#environment-variables" title="Permanent link">¶</a></h2>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p><strong>Explicit parameters take precedence over environment variables.</strong></p>
</div>
<table>
<thead>
<tr>
<th>Environment variable</th>
<th>Description</th>
<th>Utility</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>POWERTOOLS_SERVICE_NAME</strong></td>
<td>Sets service name used for tracing namespace, metrics dimension and structured logging</td>
<td>All</td>
<td><code>"service_undefined"</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_METRICS_NAMESPACE</strong></td>
<td>Sets namespace used for metrics</td>
<td><a href="./core/metrics">Metrics</a></td>
<td><code>None</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_TRACE_DISABLED</strong></td>
<td>Disables tracing</td>
<td><a href="./core/tracer">Tracing</a></td>
<td><code>false</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_TRACER_CAPTURE_RESPONSE</strong></td>
<td>Captures Lambda or method return as metadata.</td>
<td><a href="./core/tracer">Tracing</a></td>
<td><code>true</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_TRACER_CAPTURE_ERROR</strong></td>
<td>Captures Lambda or method exception as metadata.</td>
<td><a href="./core/tracer">Tracing</a></td>
<td><code>true</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_TRACE_MIDDLEWARES</strong></td>
<td>Creates sub-segment for each custom middleware</td>
<td><a href="./utilities/middleware_factory">Middleware factory</a></td>
<td><code>false</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_LOGGER_LOG_EVENT</strong></td>
<td>Logs incoming event</td>
<td><a href="./core/logger">Logging</a></td>
<td><code>false</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_LOGGER_SAMPLE_RATE</strong></td>
<td>Debug log sampling</td>
<td><a href="./core/logger">Logging</a></td>
<td><code>0</code></td>
</tr>
<tr>
<td><strong>POWERTOOLS_LOG_DEDUPLICATION_DISABLED</strong></td>
<td>Disables log deduplication filter protection to use Pytest Live Log feature</td>
<td><a href="./core/logger">Logging</a></td>
<td><code>false</code></td>
</tr>
<tr>
<td><strong>LOG_LEVEL</strong></td>
<td>Sets logging level</td>
<td><a href="./core/logger">Logging</a></td>
<td><code>INFO</code></td>
</tr>
</tbody>
</table>
<h2 id="debug-mode">Debug mode<a class="headerlink" href="#debug-mode" title="Permanent link">¶</a></h2>
<p>As a best practice, AWS Lambda Powertools logging statements are suppressed. If necessary, you can enable debugging using <code>set_package_logger</code>:</p>
<div class="tabbed-set" data-tabs="3:1"><input checked="checked" id="__tabbed_3_1" name="__tabbed_3" type="radio" /><label for="__tabbed_3_1">app.py</label><div class="tabbed-content">
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">aws_lambda_powertools.logging.logger</span> <span class="kn">import</span> <span class="n">set_package_logger</span>
<span class="n">set_package_logger</span><span class="p">()</span>
</code></pre></div>
</td></tr></table>
</div>
</div>
<h2 id="tenets">Tenets<a class="headerlink" href="#tenets" title="Permanent link">¶</a></h2>
<ul>
<li><strong>AWS Lambda only</strong>. We optimise for AWS Lambda function environments and supported runtimes only. Utilities might work with web frameworks and non-Lambda environments, though they are not officially supported.</li>
<li><strong>Eases the adoption of best practices</strong>. The main priority of the utilities is to facilitate best practices adoption, as defined in the AWS Well-Architected Serverless Lens; all other functionality is optional.</li>
<li><strong>Keep it lean</strong>. Additional dependencies are carefully considered for security and ease of maintenance, and prevent negatively impacting startup time.</li>
<li><strong>We strive for backwards compatibility</strong>. New features and changes should keep backwards compatibility. If a breaking change cannot be avoided, the deprecation and migration process should be clearly defined.</li>
<li><strong>We work backwards from the community</strong>. We aim to strike a balance of what would work best for 80% of customers. Emerging practices are considered and discussed via Requests for Comment (RFCs)</li>
<li><strong>Idiomatic</strong>. Utilities follow programming language idioms and language-specific best practices.</li>
</ul>
<p><em><code>*</code> Core utilities are Tracer, Logger and Metrics. Optional utilities may vary across languages.</em></p>
<hr>
<div class="md-source-date">
<small>
Last update: 2021-02-05
</small>
</div>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid" aria-label="Footer">
<a href="changelog/" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-footer-nav__title">
<div class="md-ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
Changelog
</div>
</div>
<div class="md-footer-nav__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
<div class="md-footer-copyright__highlight">
Copyright © 2020 - Present by Amazon Web Services
</div>
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<script src="assets/javascripts/vendor.53cc9318.min.js"></script>
<script src="assets/javascripts/bundle.e9c9f54f.min.js"></script><script id="__lang" type="application/json">{"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing"}</script>
<script>
app = initialize({
base: ".",
features: ['navigation.sections', 'navigation.expand'],
search: Object.assign({
worker: "assets/javascripts/worker/search.9c0e82ba.min.js"
}, typeof search !== "undefined" && search)
})
</script>
</body>
</html>