-
Notifications
You must be signed in to change notification settings - Fork 0
/
lamdafunction.py
42 lines (33 loc) · 1.21 KB
/
lamdafunction.py
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
import base64
import logging
import json
import boto3
#import numpy
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
print('Loading Lambda function')
runtime=boto3.Session().client('sagemaker-runtime')
endpoint_name='dog-pytorch-endpoint-multi-instance'
def lambda_handler(event, context):
#x=event['content']
#aa=x.encode('ascii')
#bs=base64.b64decode(aa)
print('Context:::',context)
print('EventType::',type(event))
bs=event
runtime=boto3.Session().client('sagemaker-runtime')
response=runtime.invoke_endpoint(EndpointName=endpoint_name,
ContentType="application/json",
Accept='application/json',
#Body=bytearray(x)
Body=json.dumps(bs))
result=response['Body'].read().decode('utf-8')
sss=json.loads(result)
return {
'statusCode': 200,
'headers' : { 'Content-Type' : 'text/plain', 'Access-Control-Allow-Origin' : '*' },
'type-result':str(type(result)),
'COntent-Type-In':str(context),
'body' : json.dumps(sss)
#'updated_result':str(updated_result)
}