Spaces:
Configuration error

yonkasoft commited on
Commit
0c9beb9
1 Parent(s): 0d97454

Upload 6 files

Browse files
Files changed (6) hide show
  1. __init__.py +0 -0
  2. app.py +42 -0
  3. app1.py +0 -0
  4. event.json +62 -0
  5. requirements.txt +1 -8
  6. test_handler.py +72 -0
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ # import requests
4
+
5
+
6
+ def lambda_handler(event, context):
7
+ """Sample pure Lambda function
8
+
9
+ Parameters
10
+ ----------
11
+ event: dict, required
12
+ API Gateway Lambda Proxy Input Format
13
+
14
+ Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
15
+
16
+ context: object, required
17
+ Lambda Context runtime methods and attributes
18
+
19
+ Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
20
+
21
+ Returns
22
+ ------
23
+ API Gateway Lambda Proxy Output Format: dict
24
+
25
+ Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
26
+ """
27
+
28
+ # try:
29
+ # ip = requests.get("http://checkip.amazonaws.com/")
30
+ # except requests.RequestException as e:
31
+ # # Send some context about this error to Lambda Logs
32
+ # print(e)
33
+
34
+ # raise e
35
+
36
+ return {
37
+ "statusCode": 200,
38
+ "body": json.dumps({
39
+ "message": "hello world",
40
+ # "location": ip.text.replace("\n", "")
41
+ }),
42
+ }
app1.py ADDED
File without changes
event.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "body": "{\"message\": \"hello world\"}",
3
+ "resource": "/hello",
4
+ "path": "/hello",
5
+ "httpMethod": "GET",
6
+ "isBase64Encoded": false,
7
+ "queryStringParameters": {
8
+ "foo": "bar"
9
+ },
10
+ "pathParameters": {
11
+ "proxy": "/path/to/resource"
12
+ },
13
+ "stageVariables": {
14
+ "baz": "qux"
15
+ },
16
+ "headers": {
17
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
18
+ "Accept-Encoding": "gzip, deflate, sdch",
19
+ "Accept-Language": "en-US,en;q=0.8",
20
+ "Cache-Control": "max-age=0",
21
+ "CloudFront-Forwarded-Proto": "https",
22
+ "CloudFront-Is-Desktop-Viewer": "true",
23
+ "CloudFront-Is-Mobile-Viewer": "false",
24
+ "CloudFront-Is-SmartTV-Viewer": "false",
25
+ "CloudFront-Is-Tablet-Viewer": "false",
26
+ "CloudFront-Viewer-Country": "US",
27
+ "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
28
+ "Upgrade-Insecure-Requests": "1",
29
+ "User-Agent": "Custom User Agent String",
30
+ "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
31
+ "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
32
+ "X-Forwarded-For": "127.0.0.1, 127.0.0.2",
33
+ "X-Forwarded-Port": "443",
34
+ "X-Forwarded-Proto": "https"
35
+ },
36
+ "requestContext": {
37
+ "accountId": "123456789012",
38
+ "resourceId": "123456",
39
+ "stage": "prod",
40
+ "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
41
+ "requestTime": "09/Apr/2015:12:34:56 +0000",
42
+ "requestTimeEpoch": 1428582896000,
43
+ "identity": {
44
+ "cognitoIdentityPoolId": null,
45
+ "accountId": null,
46
+ "cognitoIdentityId": null,
47
+ "caller": null,
48
+ "accessKey": null,
49
+ "sourceIp": "127.0.0.1",
50
+ "cognitoAuthenticationType": null,
51
+ "cognitoAuthenticationProvider": null,
52
+ "userArn": null,
53
+ "userAgent": "Custom User Agent String",
54
+ "user": null
55
+ },
56
+ "path": "/prod/hello",
57
+ "resourcePath": "/hello",
58
+ "httpMethod": "POST",
59
+ "apiId": "1234567890",
60
+ "protocol": "HTTP/1.1"
61
+ }
62
+ }
requirements.txt CHANGED
@@ -1,8 +1 @@
1
-
2
- fastapi==0.74.*
3
- requests==2.27.*
4
- sentencepiece==0.1.*
5
- torch==1.11.*
6
- transformers==4.*
7
- uvicorn[standard]==0.17.*
8
-
 
1
+ requests
 
 
 
 
 
 
 
test_handler.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import pytest
4
+
5
+ from hello_world import app
6
+
7
+
8
+ @pytest.fixture()
9
+ def apigw_event():
10
+ """ Generates API GW Event"""
11
+
12
+ return {
13
+ "body": '{ "test": "body"}',
14
+ "resource": "/{proxy+}",
15
+ "requestContext": {
16
+ "resourceId": "123456",
17
+ "apiId": "1234567890",
18
+ "resourcePath": "/{proxy+}",
19
+ "httpMethod": "POST",
20
+ "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
21
+ "accountId": "123456789012",
22
+ "identity": {
23
+ "apiKey": "",
24
+ "userArn": "",
25
+ "cognitoAuthenticationType": "",
26
+ "caller": "",
27
+ "userAgent": "Custom User Agent String",
28
+ "user": "",
29
+ "cognitoIdentityPoolId": "",
30
+ "cognitoIdentityId": "",
31
+ "cognitoAuthenticationProvider": "",
32
+ "sourceIp": "127.0.0.1",
33
+ "accountId": "",
34
+ },
35
+ "stage": "prod",
36
+ },
37
+ "queryStringParameters": {"foo": "bar"},
38
+ "headers": {
39
+ "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
40
+ "Accept-Language": "en-US,en;q=0.8",
41
+ "CloudFront-Is-Desktop-Viewer": "true",
42
+ "CloudFront-Is-SmartTV-Viewer": "false",
43
+ "CloudFront-Is-Mobile-Viewer": "false",
44
+ "X-Forwarded-For": "127.0.0.1, 127.0.0.2",
45
+ "CloudFront-Viewer-Country": "US",
46
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
47
+ "Upgrade-Insecure-Requests": "1",
48
+ "X-Forwarded-Port": "443",
49
+ "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
50
+ "X-Forwarded-Proto": "https",
51
+ "X-Amz-Cf-Id": "aaaaaaaaaae3VYQb9jd-nvCd-de396Uhbp027Y2JvkCPNLmGJHqlaA==",
52
+ "CloudFront-Is-Tablet-Viewer": "false",
53
+ "Cache-Control": "max-age=0",
54
+ "User-Agent": "Custom User Agent String",
55
+ "CloudFront-Forwarded-Proto": "https",
56
+ "Accept-Encoding": "gzip, deflate, sdch",
57
+ },
58
+ "pathParameters": {"proxy": "/examplepath"},
59
+ "httpMethod": "POST",
60
+ "stageVariables": {"baz": "qux"},
61
+ "path": "/examplepath",
62
+ }
63
+
64
+
65
+ def test_lambda_handler(apigw_event):
66
+
67
+ ret = app.lambda_handler(apigw_event, "")
68
+ data = json.loads(ret["body"])
69
+
70
+ assert ret["statusCode"] == 200
71
+ assert "message" in ret["body"]
72
+ assert data["message"] == "hello world"