FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-lambda/aws_lambda/helpers.py at master · nficano/python-lambda · GitHub
This repository was archived by the owner on Mar 15, 2026. It is now read-only.
nficano
/
python-lambda
Public archive
Notifications
You must be signed in to change notification settings
Fork
227
Star
1.5k
Code
Issues
42
Pull requests
25
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-lambda
/
aws_lambda
/
helpers.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (54 loc) · 1.85 KB
Breadcrumbs
python-lambda
/
aws_lambda
/
helpers.py
Copy path
File metadata and controls
69 lines (54 loc) · 1.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# -*- coding: utf-8 -*-
import
datetime
as
dt
import
os
import
re
import
time
import
zipfile
def
mkdir
(
path
):
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
def
read
(
path
,
loader
=
None
,
binary_file
=
False
):
open_mode
=
"rb"
if
binary_file
else
"r"
with
open
(
path
,
mode
=
open_mode
)
as
fh
:
if
not
loader
:
return
fh
.
read
()
return
loader
(
fh
.
read
())
def
archive
(
src
,
dest
,
filename
):
output
=
os
.
path
.
join
(
dest
,
filename
)
zfh
=
zipfile
.
ZipFile
(
output
,
"w"
,
zipfile
.
ZIP_DEFLATED
)
for
root
,
_
,
files
in
os
.
walk
(
src
):
for
file
in
files
:
zfh
.
write
(
os
.
path
.
join
(
root
,
file
))
zfh
.
close
()
return
os
.
path
.
join
(
dest
,
filename
)
def
timestamp
(
fmt
=
"%Y-%m-%d-%H%M%S"
):
now
=
dt
.
datetime
.
utcnow
()
return
now
.
strftime
(
fmt
)
def
get_environment_variable_value
(
val
):
env_val
=
val
if
val
is
not
None
and
isinstance
(
val
,
str
):
match
=
re
.
search
(
r"^\${(?P<environment_key_name>\w+)*}$"
,
val
)
if
match
is
not
None
:
env_val
=
os
.
environ
.
get
(
match
.
group
(
"environment_key_name"
))
return
env_val
class
LambdaContext
:
def
current_milli_time
(
x
):
return
int
(
round
(
time
.
time
()
*
1000
))
def
get_remaining_time_in_millis
(
self
):
return
max
(
0
,
self
.
timeout_millis
-
(
self
.
current_milli_time
()
-
self
.
start_time_millis
),
)
def
__init__
(
self
,
function_name
,
timeoutSeconds
=
3
):
self
.
function_name
=
function_name
self
.
function_version
=
None
self
.
invoked_function_arn
=
None
self
.
memory_limit_in_mb
=
None
self
.
aws_request_id
=
None
self
.
log_group_name
=
None
self
.
log_stream_name
=
None
self
.
identity
=
None
self
.
client_context
=
None
self
.
timeout_millis
=
timeoutSeconds
*
1000
self
.
start_time_millis
=
self
.
current_milli_time
()
Back
|
FazBrowse Home
|
New Git URL