Skip to content

Commit d29d917

Browse files
committed
add AWS hellopy-read-random raw-code
1 parent 639a1f4 commit d29d917

File tree

1 file changed

+50
-0
lines changed
  • src/setup/deployment/raw-code/serverless/aws/hellopy-read-random

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import json
2+
import os
3+
import time
4+
import random
5+
6+
7+
def lambda_handler(request, context):
8+
incr_limit = 0
9+
10+
if 'queryStringParameters' in request and 'IncrementLimit' in request['queryStringParameters']:
11+
incr_limit = int(request['queryStringParameters'].get('IncrementLimit', 0))
12+
elif 'body' in request and json.loads(request['body'])['IncrementLimit']:
13+
incr_limit = int(json.loads(request['body'])['IncrementLimit'])
14+
15+
simulate_work(incr_limit)
16+
read_filler_file('./filler.file')
17+
18+
json_region = os.environ.get('AWS_REGION', 'Unknown')
19+
20+
response = {
21+
"statusCode": 200,
22+
"headers": {
23+
"Content-Type": "application/json"
24+
},
25+
"body": json.dumps({
26+
"Region ": json_region,
27+
"RequestID": context.aws_request_id,
28+
"TimestampChain": [str(time.time_ns())]
29+
}, indent=4)
30+
}
31+
32+
return response
33+
34+
35+
def simulate_work(increment):
36+
# MAXNUM = 6103705
37+
num = 0
38+
while num < increment:
39+
num += 1
40+
41+
42+
def read_filler_file(path: str) -> None:
43+
file_size = os.stat(path).st_size
44+
number_of_pages = file_size // 4096
45+
with open(path, 'rb') as f:
46+
for _ in range(100):
47+
page_number = random.randrange(0, number_of_pages)
48+
page_offset = page_number * 4096
49+
f.seek(page_offset)
50+
f.read(1)

0 commit comments

Comments
 (0)